lib/saga/formatter.rb in saga-0.1.0 vs lib/saga/formatter.rb in saga-0.2.0
- old
+ new
@@ -1,28 +1,31 @@
-require 'rubygems'
require 'erubis'
module Saga
class Formatter
TEMPLATE_PATH = File.expand_path('../../../templates', __FILE__)
- def initialize(document)
+ def initialize(document, options={})
@document = document
+ @options = options
+ @options[:template] ||= 'default'
end
def format
- helpers_file = File.join(self.class.template_path, 'default/helpers.rb')
+ template_path = File.join(self.class.template_path, @options[:template])
+
+ helpers_file = File.join(template_path, 'helpers.rb')
load helpers_file
@document.extend(Helpers)
binding = @document.send(:binding)
- template_file = File.join(self.class.template_path, 'default/document.erb')
+ template_file = File.join(template_path, 'document.erb')
template = Erubis::Eruby.new(File.read(template_file))
template.result(binding)
end
- def self.format(document)
- formatter = new(document)
+ def self.format(document, options={})
+ formatter = new(document, options)
formatter.format
end
def self.template_path
TEMPLATE_PATH
\ No newline at end of file