class Saga::Formatter
Constants
- TEMPLATE_PATH
Attributes
document[R]
template_path[R]
Public Class Methods
format(document, **kwargs)
click to toggle source
# File lib/saga/formatter.rb, line 29 def self.format(document, **kwargs) formatter = new(document, **kwargs) formatter.format end
new(document, template_path: nil)
click to toggle source
# 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
saga_format(document)
click to toggle source
# File lib/saga/formatter.rb, line 38 def self.saga_format(document) format(document, template_path: File.join(template_path, 'saga')) end
template_path()
click to toggle source
# File lib/saga/formatter.rb, line 34 def self.template_path TEMPLATE_PATH end
Public Instance Methods
format()
click to toggle source
# 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()
click to toggle source
# File lib/saga/formatter.rb, line 15 def template @template ||= build_template end
Private Instance Methods
build_erb()
click to toggle source
# File lib/saga/formatter.rb, line 45 def build_erb ERB.new(File.read(template_file), nil, '-') end
build_template()
click to toggle source
# File lib/saga/formatter.rb, line 54 def build_template if File.exist?(template_file) build_erb else raise ArgumentError, "The template at path `#{template_file}' could not be found." end end
helpers_file()
click to toggle source
# File lib/saga/formatter.rb, line 62 def helpers_file File.join(template_path, 'helpers.rb') end
template_file()
click to toggle source
# File lib/saga/formatter.rb, line 66 def template_file File.join(template_path, 'document.erb') end