Skip to content

Commit

Permalink
Basic spec for options added
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdavey committed Oct 13, 2014
1 parent 1ad9959 commit b2c133e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'bundler/gem_tasks'

# Default directory to look in is `/specs`
# Run with `rake spec`
RSpec::Core::RakeTask.new(:spec) do |task|
task.rspec_opts = ['--color', '--format', 'documentation']
end

task :default => :spec

1 change: 1 addition & 0 deletions lib/vimwiki_markdown.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "vimwiki_markdown/version"
require "vimwiki_markdown/options"

module VimwikiMarkdown
# Your code goes here...
Expand Down
81 changes: 81 additions & 0 deletions lib/vimwiki_markdown/options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
require 'active_support/inflector'

module VimwikiMarkdown
class Options
DEFAULTS = ["1", #force - 1/0
"markdown",
"md",
"/home/patrick/vimwikimarkdown/site_html/",
"/home/patrick/vimwikimarkdown/index.md",
"/home/patrick/vimwikimarkdown/site_html/style.css",
"/home/patrick/vimwikimarkdown/templates/",
"default",
".tpl",
"-"]

FORCE = 0
SYNTAX = 1
EXTENSION = 2
OUTPUT_DIR = 3
INPUT_FILE = 4
CSS_FILE = 5
TEMPLATE_PATH = 6
TEMPLATE_DEFAULT = 7
TEMPLATE_EXT = 8
ROOT_PATH = 9

attr_reader :force, :syntax, :extension, :output_dir,
:input_file, :css_file, :template_path,
:template_default, :template_ext, :root_path

=begin force : [0/1] overwrite an existing file
syntax : the syntax chosen for this wiki
extension : the file extension for this wiki
output_dir : the full path of the output directory, i.e. 'path_html'
input_file : the full path of the wiki page
css_file : the full path of the css file for this wiki
template_path : the full path to the wiki's templates
template_default : the default template name
template_ext : the extension of template files
root_path : a count of ../ for pages buried in subdirs
if you have wikilink [[dir1/dir2/dir3/my page in a subdir]]
then e %root_path% is replaced by '../../../'.
=end

def initialize
@force = arguments[FORCE] == "1" ? true : false
@syntax = arguments[SYNTAX]
@extension = arguments[EXTENSION]
@output_dir = arguments[OUTPUT_DIR]
@input_file = arguments[INPUT_FILE]
@css_file = arguments[CSS_FILE]
@template_path = arguments[TEMPLATE_PATH]
@template_default = arguments[TEMPLATE_DEFAULT]
@template_ext = arguments[TEMPLATE_EXT]
@root_path = arguments[ROOT_PATH]
raise "Must be markdown" unless syntax == 'markdown'
end

def template_filename
"#{template_path}#{template_default}#{template_ext}"
end

def self.arguments
ARGV.empty? ? DEFAULTS : ARGV
end

def title
File.basename(input_file, ".md").capitalize
end

def output_fullpath
"#{output_dir}#{title.parameterize}.html"
end

private

def arguments
Options.arguments
end
end
end
19 changes: 19 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'
require 'vimwiki_markdown/options'

module VimwikiMarkdown
describe Options do
subject { Options.new }

context "no options passed" do
before do
allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
end

its(:force) { should be(true) }
its(:syntax) { should eq('markdown') }
its(:output_fullpath) { should eq("#{subject.output_dir}#{subject.title.parameterize}.html") }
its(:template_filename) { should eq('/home/patrick/vimwikimarkdown/templates/default.tpl') }
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'bundler/setup'
require 'pry'
require 'rspec/its'
require 'vimwiki_markdown'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
Expand Down

0 comments on commit b2c133e

Please sign in to comment.