Class: Malt::Format::Erb

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

Instance Attribute Summary

Attributes inherited from Abstract

#options

Instance Method Summary collapse

Methods inherited from AbstractTemplate

#method_missing, #render, #to

Methods inherited from Abstract

#default, #engine, engine, extensions, #extensions, #file, #parse_type_and_data, #refile, register, #render, #subtype, #text, #to, #to_default, #to_s, #type

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Malt::Format::AbstractTemplate

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