Class: Hobber::Renderer::Tilt

Inherits:
Object
  • Object
show all
Defined in:
lib/hobber/renderer/tilt.rb

Instance Method Summary collapse

Instance Method Details

#render(path, data, context, vars, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hobber/renderer/tilt.rb', line 6

def render(path, data, context, vars, &block)
  # termination condition, if tilt template class
  # is  
  tilt_template_class = ::Tilt[path]
  unless tilt_template_class
    return data
  end

  template = tilt_template_class.new(path) { |t| data }

  # remove extention
  path = path.gsub(/\.\w+$/,'')
  data = template.render(context, vars, &block)

  # iterate again to next available template 
  # engine
  render(path, data, context, vars, &block)
rescue => e
  render_error = RenderError.new("#{self.class}: While rendering #{path} with #{tilt_template_class}: #{e.message}")
  render_error.set_backtrace(e.backtrace)
  raise render_error 
end