Class: Malt::Formats::Erb

Inherits:
AbstractTemplate
  • Object
show all
Defined in:
lib/malt/formats/erb.rb

Instance Method Summary collapse

Instance Method Details

#html(data = nil, &yld) ⇒ Object

Technically #method_missing will pick this up, but since it is likely to be the most commonly used, adding the method directly will provide a small speed boost.



33
34
35
# File 'lib/malt/formats/erb.rb', line 33

def html(data=nil, &yld)
  render(:html, data, &yld)
end

#rbObject

TODO: Lookup engine from engine registry.



14
15
16
# File 'lib/malt/formats/erb.rb', line 14

def rb(*)
  render_engine.compile(:text=>text, :file=>file)
end

#to_html(data = nil, &yld) ⇒ Object

Technically #method_missing will pick this up, but since it is likely to be the most commonly used, adding the method directly will provide a small speed boost.



40
41
42
43
44
45
# File 'lib/malt/formats/erb.rb', line 40

def to_html(data=nil, &yld)
  new_text    = render(:html, data, &yld)
  new_file    = refile(:html)
  new_options = options.merge(:text=>new_text, :file=>new_file, :type=>:html)
  HTML.new(new_options)
end

#to_rbObject Also known as: to_ruby, precompile

Erb templates can be “pre-compiled” into Ruby templates.



19
20
21
22
# File 'lib/malt/formats/erb.rb', line 19

def to_rb(*)
  text = rb
  Ruby.new(:text=>text, :file=>refile(:rb))
end