Module: Bandoleer::ErbHelper
- Included in:
- Outfitter
- Defined in:
- lib/bandoleer/erb_helper.rb
Overview
Provides a helper method for resolving erb templates.
Class Method Summary collapse
-
.included(base) ⇒ Object
Add the method .source_root to klass when included.
Instance Method Summary collapse
-
#fill_erb_template(template_name, hsh = {}) ⇒ String
Retrieve an erb template and fill it.
Class Method Details
.included(base) ⇒ Object
Add the method .source_root to klass when included.
7 8 9 10 11 |
# File 'lib/bandoleer/erb_helper.rb', line 7 def self.included( base ) base.define_singleton_method(:source_root) do File.join(__dir__, '/templates') end end |
Instance Method Details
#fill_erb_template(template_name, hsh = {}) ⇒ String
Retrieve an erb template and fill it. Uses an optional hash to provide variables, otherwise uses a binding of the current context to access any instance variables.
17 18 19 20 21 |
# File 'lib/bandoleer/erb_helper.rb', line 17 def fill_erb_template( template_name, hsh = {} ) erb = ERB.new source_template(template_name) return erb.result(get_binding) if hsh.empty? erb.result_with_hash hsh end |