-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ad9959
commit b2c133e
Showing
5 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters