Malt  Malt::Engine::Erb

[Validate]
Generated with RDazzle Newfish 1.4.0

Erb

ERB template implementation.

  http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html

ERB templates accept two options. safe sets the safe mode for rendering the template and trim is a weird string that controls a few rendering options —it can be ’%’ and/or ’>’ or ’<>’.

Public Instance Methods

compile(params={}) click to toggle source

Compile ERB template into Ruby source code.

    # File lib/malt/engines/erb.rb, line 43
43:     def compile(params={})
44:       file = params[:file]
45:       if cache?
46:         @source[file] ||= intermediate(params).src
47:       else
48:         intermediate(params).src
49:       end
50:     end
intermediate(params={}) click to toggle source

Returns instance of underlying ::ERB class.

    # File lib/malt/engines/erb.rb, line 53
53:     def intermediate(params={})
54:       text = params[:text]
55:       file = params[:file]
56: 
57:       opts = engine_options(params)
58:       safe = opts[:safe]
59:       trim = opts[:trim]
60: 
61:       if cache?
62:         @cache[file] ||= ::ERB.new(text, safe, trim)
63:       else
64:         ::ERB.new(text, safe, trim)
65:       end
66:     end
render(params={}, &yld) click to toggle source

Render ERB template.

The params can be:

  • :text - text of erb document

  • :file - file name where text was read (or nil)

  • :data - data source for template interpolation

  • :safe -

  • :trim -

Returns a String.

    # File lib/malt/engines/erb.rb, line 27
27:     def render(params={}, &yld)
28:       text = params[:text]
29:       file = params[:file]
30:       data = params[:data]
31: 
32:       data = make_binding(data, &yld)
33: 
34:       if settings[:precompile] == false
35:         intermediate(params).result(data)
36:       else
37:         ruby = compile(params)
38:         eval(ruby, data, file)
39:       end
40:     end

Private Instance Methods

engine_options(params) click to toggle source
    # File lib/malt/engines/erb.rb, line 76
76:     def engine_options(params)
77:       opts = {}
78:       opts[:safe] = params[:safe] || settings[:safe]
79:       opts[:trim] = params[:trim] || settings[:trim]
80:       opts
81:     end
initialize_engine() click to toggle source

Load ERB library if not already loaded.

    # File lib/malt/engines/erb.rb, line 71
71:     def initialize_engine
72:       return if defined? ::ERB
73:       require_library('erb')
74:     end

Disabled; run with --debug to generate this.