Malt  Malt::Engine::Radius

[Validate]
Generated with RDazzle Newfish 1.4.0

Radius

Radius Template

  http://github.com/jlong/radius/

Public Instance Methods

render(params, &yld) click to toggle source
    # File lib/malt/engines/radius.rb, line 14
14:     def render(params, &yld)
15:       text = params[:text]
16:       data = params[:data]
17:       into = params[:to]
18:       case into
19:       when :html, :xml, nil
20:         data = make_context(data, &yld)
21:         opts = engine_options(params)
22:         parser = ::Radius::Parser.new(data, opts)
23:         parser.parse(text)
24:       else
25:         super(params, &yld)
26:       end
27:     end

Private Instance Methods

engine_options(params) click to toggle source
    # File lib/malt/engines/radius.rb, line 82
82:     def engine_options(params)
83:       opts = {}
84:       opts[:tag_prefix] = params[:tag_prefix] || settings[:tag_prefix]
85:       opts
86:     end
initialize_engine() click to toggle source

Load Radius library if not already loaded.

    # File lib/malt/engines/radius.rb, line 32
32:     def initialize_engine
33:       return if defined? ::Radius
34:       require_library 'radius'
35:     end
make_context(data, &yld) click to toggle source

Radius templates have a very special data source.

    # File lib/malt/engines/radius.rb, line 38
38:     def make_context(data, &yld)
39:       case data
40:       when Hash
41:         context = make_context_from_hash(data, &yld)
42:       else
43:         if data.respond_to(:to_hash)
44:           data = data.to_hash
45:           context = make_context_from_hash(data, &yld)
46:         else
47:           context = make_context_from_object(data, &yld)
48:         end
49:       end
50:       context
51:     end
make_context_from_hash(data, &yld) click to toggle source
    # File lib/malt/engines/radius.rb, line 69
69:     def make_context_from_hash(data, &yld)
70:       context = Class.new(::Radius::Context).new
71:       #data = make_hash(data)
72:       data.each do |tag, value|
73:         context.define_tag(tag){ value }
74:       end
75:       context.define_tag("yield") do
76:         yld.call
77:       end
78:       context
79:     end
make_context_from_object(db, &yld) click to toggle source
    # File lib/malt/engines/radius.rb, line 54
54:     def make_context_from_object(db, &yld)
55:       context = Class.new(::Radius::Context).new
56:       db = make_object(db)
57:       (class << context; self; end).class_eval do
58:         define_method :tag_missing do |tag, attr|
59:           db.__send__(tag) # any way to support attr as args?
60:         end
61:       end
62:       context.define_tag("yield") do
63:         yld.call
64:       end
65:       context
66:     end

Disabled; run with --debug to generate this.