Module: ActionTree::Components::Tilt::Helpers

Defined in:
lib/action_tree/components/tilt.rb

Instance Method Summary collapse

Instance Method Details

#render(*args, &blk) ⇒ Object

Public: Renders a template



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/action_tree/components/tilt.rb', line 41

def render(*args, &blk)
  tilt    = args.find {|a| a.is_a?(Tilt::Template) }
  name    = args.find {|a| a.is_a?(Symbol) }
  source  = args.find {|a| a.is_a?(String) }
  options = args.find {|a| a.is_a?(Hash) }

  if tilt && source
    path = File.join(config[:template_path], source)
    tilt = Tilt.new(path, nil, options)
  end

  templates = @_match.templates[name]

  default :type, templates.first.class.default_mime_type

  result =  tilt ? tilt.render(self, options, &blk) : nil

  templates.reverse.inject(result) do |r, template|
    template.render(self) { r }
  end
end