Module: ErbHelper
- Included in:
- RockBooks::BalanceSheet, RockBooks::IncomeStatement, RockBooks::JournalReport, RockBooks::MultidocTransactionByAccountReport, RockBooks::MultidocTransactionReport, RockBooks::TxOneAccount
- Defined in:
- lib/rock_books/reports/helpers/erb_helper.rb
Class Method Summary collapse
- .erb_template(erb_relative_filespec) ⇒ Object
- .render_binding(erb_relative_filespec, template_binding) ⇒ Object
-
.render_hashes(erb_relative_filespec, data_hash, presentation_hash) ⇒ Object
Takes 2 hashes, one with data, and the other with presentation functions/lambdas, and passes their union to ERB for rendering.
Class Method Details
.erb_template(erb_relative_filespec) ⇒ Object
3 4 5 6 7 |
# 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) ⇒ Object
10 11 12 13 |
# 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) ⇒ Object
Takes 2 hashes, one with data, and the other with presentation functions/lambdas, and passes their union to ERB for rendering.
17 18 19 20 |
# 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 |