Permalink
Browse files

Allow the -t commandline argument to accept absolute paths for templa…

…te files
  • Loading branch information...
1 parent c421288 commit 0afb72495845c1532b0ab3edac07b45b42e25dc1 @jasonm jasonm committed Sep 2, 2009
Showing with 22 additions and 4 deletions.
  1. +12 −4 lib/slidedown.rb
  2. +10 −0 spec/commandline_spec.rb
View
16 lib/slidedown.rb
@@ -9,7 +9,7 @@
class SlideDown
USAGE = "The SlideDown command line interface takes a .md (Markdown) file as its only required argument. It will convert the file to HTML in standard out. Options:
- -t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags."
+ -t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags. This can also accept an absolute path for templates outside the /templates directory."
attr_accessor :stylesheets, :title
attr_reader :classes
@@ -63,9 +63,13 @@ def read(path)
end
def render(name)
- directory = File.join(File.dirname(__FILE__), "..", "templates")
- path = File.join(directory, "#{name}.erb")
- template = File.read(path)
+ if is_absolute_path?(name)
+ template = File.read("#{name}.erb")
+ else
+ directory = File.join(File.dirname(__FILE__), "..", "templates")
+ path = File.join(directory, "#{name}.erb")
+ template = File.read(path)
+ end
ERB.new(template).result(binding)
end
@@ -100,4 +104,8 @@ def extract_notes!
''
end
end
+
+ def is_absolute_path?(path)
+ path == File.expand_path(path)
+ end
end
View
10 spec/commandline_spec.rb
@@ -20,6 +20,16 @@
result_file_content.should == reference_file_content
end
+ it "accepts -t /full/path/to/template-filename" do
+ import_template_path = File.join(root_path, 'templates', 'import.erb')
+ other_template_path = Tempfile.new("slidedown-template").path
+ File.copy(import_template_path, "#{other_template_path}.erb")
+
+ run_slidedown("-t #{other_template_path}")
+
+ result_file_content.should == reference_file_content("slides-import")
+ end
+
def run_slidedown(opts = "")
`#{slidedown_path} #{source_path} #{opts} > #{result_file_path}`
end

0 comments on commit 0afb724

Please sign in to comment.