module ErbHelper

Public Class Methods

erb_template(erb_relative_filespec) click to toggle source
# File lib/rock_books/reports/helpers/erb_helper.rb, line 3
def self.erb_template(erb_relative_filespec)
  erb_filespec = File.absolute_path(File.join(File.dirname(__FILE__), '..', 'templates', erb_relative_filespec))
  eoutvar = "@outvar_#{erb_relative_filespec.split('.').first.split('/').last}" # dots will be evaulated by `eval`, must remove them
  ERB.new(File.read(erb_filespec), eoutvar: eoutvar, trim_mode: '-')
end
render_binding(erb_relative_filespec, template_binding) click to toggle source
# File lib/rock_books/reports/helpers/erb_helper.rb, line 10
def self.render_binding(erb_relative_filespec, template_binding)
  result = erb_template(erb_relative_filespec).result(template_binding)
  result
end
render_hashes(erb_relative_filespec, data_hash, presentation_hash) click to toggle source

Takes 2 hashes, one with data, and the other with presentation functions/lambdas, and passes their union to ERB for rendering.

# File lib/rock_books/reports/helpers/erb_helper.rb, line 17
def self.render_hashes(erb_relative_filespec, data_hash, presentation_hash)
  combined_hash = (data_hash || {}).merge(presentation_hash || {})
  erb_template(erb_relative_filespec).result_with_hash(combined_hash)
end