Class: Builder::Wat::Renderer
Instance Attribute Summary collapse
-
#binding_klass ⇒ Object
readonly
Returns the value of attribute binding_klass.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize(template_paths) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(erb_file) ⇒ Object
Constructor Details
#initialize(template_paths) ⇒ Renderer
Returns a new instance of Renderer.
13 14 15 16 |
# File 'lib/builder/wat/renderer.rb', line 13 def initialize(template_paths) # an array of load path to consider for erb files @template_paths = template_paths end |
Instance Attribute Details
#binding_klass ⇒ Object (readonly)
Returns the value of attribute binding_klass.
11 12 13 |
# File 'lib/builder/wat/renderer.rb', line 11 def binding_klass @binding_klass end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
11 12 13 |
# File 'lib/builder/wat/renderer.rb', line 11 def template_path @template_path end |
Instance Method Details
#render(erb_file) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/builder/wat/renderer.rb', line 18 def render(erb_file) path = '' unless Pathname.new(erb_file).absolute? path = @template_paths.find { |tp| File.exist?(File.join(tp, erb_file)) } || '' end #puts "Rendering #{File.join(path, erb_file)}" ERB.new(File.read(File.join(path, erb_file))).result(binding) end |