Class: Builder::Wat::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/builder/wat/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_klassObject (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_pathObject (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