Class: Saga::Formatter
- Inherits:
-
Object
- Object
- Saga::Formatter
- Defined in:
- lib/saga/formatter.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.('../../../templates', __FILE__)
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(document, options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(document, options = {}) ⇒ Formatter
Returns a new instance of Formatter.
7 8 9 10 11 |
# File 'lib/saga/formatter.rb', line 7 def initialize(document, ={}) @document = document @options = @options[:template] ||= 'default' end |
Class Method Details
.format(document, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/saga/formatter.rb', line 26 def self.format(document, ={}) formatter = new(document, ) formatter.format end |
.template_path ⇒ Object
31 32 33 |
# File 'lib/saga/formatter.rb', line 31 def self.template_path TEMPLATE_PATH end |
Instance Method Details
#format ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/saga/formatter.rb', line 13 def format 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(template_path, 'document.erb') template = Erubis::Eruby.new(File.read(template_file)) template.result(binding) end |