Class: Templette::MethodCollector
- Inherits:
-
Object
- Object
- Templette::MethodCollector
- Includes:
- DataAccessors
- Defined in:
- lib/templette/method_collector.rb
Overview
Loads a template and evaluates it. When a missing method is found, MethodColletor loads that method into a hash, to be rendered as yaml.
Instance Method Summary collapse
-
#initialize(template = nil) ⇒ MethodCollector
constructor
A new instance of MethodCollector.
- #method_missing(symbol) ⇒ Object
- #to_hash ⇒ Object
Methods included from DataAccessors
#attributes, #generate_accessors, #include_helpers, #partial
Methods included from Helpers
#image_tag, #script_tag, #stylesheet_tag
Constructor Details
#initialize(template = nil) ⇒ MethodCollector
Returns a new instance of MethodCollector.
9 10 11 12 13 14 15 |
# File 'lib/templette/method_collector.rb', line 9 def initialize(template = nil) @methods = {} if template include_helpers(template.helpers) template.render(binding) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol) ⇒ Object
17 18 19 |
# File 'lib/templette/method_collector.rb', line 17 def method_missing(symbol) @methods[symbol.to_s] = MethodCollector.new end |
Instance Method Details
#to_hash ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/templette/method_collector.rb', line 21 def to_hash return nil if @methods.empty? hash = {} @methods.each_pair do |k, v| hash[k] = v.to_hash end hash end |