Malt  Malt::Engine::Abstract

[Validate]
Generated with RDazzle Newfish 1.4.0

Abstract

Abstract Template class serves as the base class for all other Template classes.

Attributes

settings[R]

Access to the options given to the initializer.

Public Class Methods

default(*exts) click to toggle source

Register and set as the default for given extensions.

    # File lib/malt/engines/abstract.rb, line 42
42:     def self.default(*exts)
43:       register(*exts)
44:       exts.each do |ext|
45:         Engine.defaults[ext.to_sym] = self
46:       end
47:     end
new(settings={}) click to toggle source
    # File lib/malt/engines/abstract.rb, line 55
55:     def initialize(settings={})
56:       @settings = settings.rekey
57: 
58:       @cache  = {}
59:       @source = {}
60: 
61:       initialize_engine
62:     end
register(*exts) click to toggle source

Register the class to an extension type.

    # File lib/malt/engines/abstract.rb, line 37
37:     def self.register(*exts)
38:       Engine.register(self, *exts)
39:     end
type() click to toggle source
    # File lib/malt/engines/abstract.rb, line 50
50:     def self.type
51:       basename.downcase.to_sym
52:     end

Public Instance Methods

cache?() click to toggle source
    # File lib/malt/engines/abstract.rb, line 82
82:     def cache?
83:       !settings[:nocache]
84:     end
compile(db, &yld) click to toggle source
    # File lib/malt/engines/abstract.rb, line 77
77:     def compile(db, &yld)
78:       raise "not implemented"
79:     end
render(text, options={}) click to toggle source
    # File lib/malt/engines/abstract.rb, line 68
68:     def render(text, options={}) #format, text, file, db, &yld)
69:       if format = options[:format]
70:         raise "unsupported rendering -- #{format}"
71:       else
72:         raise "unsupported rendering"
73:       end
74:     end

Private Instance Methods

initialize_engine() click to toggle source

Override this to load template engine library and prepare is for geeral usage.

    # File lib/malt/engines/abstract.rb, line 90
90:     def initialize_engine
91:     end
make_binding(db, &yld) click to toggle source

Convert a data source into a Binding. TODO: handle yld.

     # File lib/malt/engines/abstract.rb, line 100
100:     def make_binding(db, &yld)
101:       return db if Binding === db  # FIXME: no yld
102: 
103:       if db.respond_to?(:to_binding)
104:         return db.to_binding(&yld)
105:       end
106: 
107:       db = make_object(db, &yld)
108: 
109:       return db.instance_eval{ binding }        
110:     end
make_hash(db, &yld) click to toggle source

Convert a data source into a Hash.

     # File lib/malt/engines/abstract.rb, line 129
129:     def make_hash(db, &yld)
130:       if Binding === db
131:         db = make_object(db)
132:       end
133: 
134:       if db.respond_to?(:to_hash)
135:         db = db.to_hash
136:         db[:yield] = yld.call if yld
137:         return db
138:       end
139: 
140:       if db.respond_to?(:to_h)
141:         db = db.to_h
142:         db[:yield] = yld.call if yld
143:         return db
144:       end
145: 
146:       # last resort
147:       db = db.instance_variables.inject({}) do |h, i|
148:         k = i.sub('@','').to_sym
149:         v = instance_variable_get(i)
150:         h[k] = v
151:         h
152:       end
153:       db[:yield] = yld.call if yld
154:       return db
155:     end
make_object(db, &yld) click to toggle source

Convert a data source into an Object (aka a “scope”).

     # File lib/malt/engines/abstract.rb, line 113
113:     def make_object(db, &yld)
114:       if db.respond_to?(:to_hash)
115:         hash  = db.to_hash
116:         hash[:yield] = yld.call if yld
117:         attrs = hash.keys.map{ |k| k.to_sym }
118:         return Struct.new(*attrs).new(*hash.values)
119:       end
120: 
121:       if Binding === db
122:         eval('self', binding) # FIXME: no yld
123:       end
124: 
125:       return db
126:     end
require_library(path) click to toggle source

Require template library.

    # File lib/malt/engines/abstract.rb, line 94
94:     def require_library(path)
95:       require(path)
96:     end

Disabled; run with --debug to generate this.