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] ||= File.join(self.class.template_path, 'default') end |
Class Method Details
.format(document, options = {}) ⇒ Object
29 30 31 32 |
# File 'lib/saga/formatter.rb', line 29 def self.format(document, ={}) formatter = new(document, ) formatter.format end |
.saga_format(document) ⇒ Object
38 39 40 |
# File 'lib/saga/formatter.rb', line 38 def self.saga_format(document) format(document, :template => File.join(template_path, 'saga')) end |
.template_path ⇒ Object
34 35 36 |
# File 'lib/saga/formatter.rb', line 34 def self.template_path TEMPLATE_PATH end |
Instance Method Details
#format ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/saga/formatter.rb', line 13 def format helpers_file = File.join(@options[:template], 'helpers.rb') if File.exist?(helpers_file) load helpers_file @document.extend(Helpers) end template_file = File.join(@options[:template], 'document.erb') if File.exist?(template_file) template = Erubis::Eruby.new(File.read(template_file)) template.result(@document.send(:binding)) else raise ArgumentError, "The template at path `#{template_file}' could not be found." end end |