Class: RbTmpl::Tmpl
- Inherits:
-
Object
- Object
- RbTmpl::Tmpl
- Defined in:
- lib/rb-tmpl.rb
Defined Under Namespace
Classes: HashWrapper
Instance Attribute Summary collapse
-
#template_extensions ⇒ Object
readonly
Returns the value of attribute template_extensions.
-
#template_search_paths ⇒ Object
readonly
Returns the value of attribute template_search_paths.
Instance Method Summary collapse
- #add(name, template) ⇒ Object
- #call(name, data = nil) ⇒ Object
-
#initialize ⇒ Tmpl
constructor
A new instance of Tmpl.
Constructor Details
#initialize ⇒ Tmpl
Returns a new instance of Tmpl.
8 9 10 11 12 13 14 |
# File 'lib/rb-tmpl.rb', line 8 def initialize @template_search_paths = [] @template_extensions = [] @templates = {} @compiled_templates = {} end |
Instance Attribute Details
#template_extensions ⇒ Object (readonly)
Returns the value of attribute template_extensions.
6 7 8 |
# File 'lib/rb-tmpl.rb', line 6 def template_extensions @template_extensions end |
#template_search_paths ⇒ Object (readonly)
Returns the value of attribute template_search_paths.
5 6 7 |
# File 'lib/rb-tmpl.rb', line 5 def template_search_paths @template_search_paths end |
Instance Method Details
#add(name, template) ⇒ Object
16 17 18 19 20 |
# File 'lib/rb-tmpl.rb', line 16 def add(name, template) name = name.to_s @templates[name] = template @compiled_templates.delete(name) end |
#call(name, data = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rb-tmpl.rb', line 22 def call(name, data = nil) name = name.to_s code = compiled(name) return '' if code.nil? data = HashWrapper.new(data) if data.kind_of?(Hash) bind = data.instance_eval{ binding } unless data.nil? eval(code, bind) end |