lib/slidedown.rb in slidedown-0.1.1 vs lib/slidedown.rb in slidedown-0.2.0

- old
+ new

@@ -7,11 +7,11 @@ $SILENT = true 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 def self.run!(argv = ARGV) @@ -61,13 +61,17 @@ def read(path) File.read(File.join(File.dirname(__FILE__), '..', "templates", 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 private @@ -77,11 +81,11 @@ def local_stylesheets Dir[Dir.pwd + '/*.stylesheets'] end - def jabascripts + def javascripts Dir[Dir.pwd + '/*.javascripts'].map { |path| File.read(path) } end def extract_classes! @classes = [] @@ -97,7 +101,11 @@ '!SLIDE' end @raw.gsub!(/^!NOTES\s*(.*\n)$/m) do |note| '' end + end + + def is_absolute_path?(path) + path == File.expand_path(path) end end