Class: Saga::Formatter
- Inherits:
-
Object
- Object
- Saga::Formatter
- Defined in:
- lib/saga/formatter.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.('../../templates', __dir__)
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(document, template_path: nil) ⇒ Formatter
constructor
A new instance of Formatter.
- #template ⇒ Object
Constructor Details
#initialize(document, template_path: nil) ⇒ Formatter
Returns a new instance of Formatter.
10 11 12 13 |
# File 'lib/saga/formatter.rb', line 10 def initialize(document, template_path: nil) @document = document @template_path ||= template_path || File.join(self.class.template_path, 'default') end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
7 8 9 |
# File 'lib/saga/formatter.rb', line 7 def document @document end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
8 9 10 |
# File 'lib/saga/formatter.rb', line 8 def template_path @template_path end |
Class Method Details
.format(document, **kwargs) ⇒ Object
29 30 31 32 |
# File 'lib/saga/formatter.rb', line 29 def self.format(document, **kwargs) formatter = new(document, **kwargs) 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_path: 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
19 20 21 22 23 24 25 26 27 |
# File 'lib/saga/formatter.rb', line 19 def format @document.extend(ERB::Util) unless @document.is_a?(ERB::Util) if File.exist?(helpers_file) @document.instance_eval(File.read(helpers_file)) end template.result(@document._binding) end |
#template ⇒ Object
15 16 17 |
# File 'lib/saga/formatter.rb', line 15 def template @template ||= build_template end |