Class: Lilu::Renderer
- Inherits:
-
Object
- Object
- Lilu::Renderer
- Defined in:
- lib/lilu.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#html_source ⇒ Object
readonly
Returns the value of attribute html_source.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
Instance Method Summary collapse
- #apply ⇒ Object
- #element ⇒ Object
- #element_at(path) ⇒ Object
-
#initialize(instructions, html_source, local_assignments = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #mapping(opts = {}) ⇒ Object
- #method_missing(sym, *args) ⇒ Object
-
#partial(name, opts = {}) ⇒ Object
Helper for partials.
-
#replacing(element) ⇒ Object
Helper for replacing.
Constructor Details
#initialize(instructions, html_source, local_assignments = {}) ⇒ Renderer
Returns a new instance of Renderer.
183 184 185 186 187 188 189 |
# File 'lib/lilu.rb', line 183 def initialize(instructions,html_source,local_assignments={}) @instructions = instructions @html_source = html_source @doc = Hpricot(@html_source) @view = local_assignments["___view"] if local_assignments.is_a?(Hash) inject_local_assignments(local_assignments) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/lilu.rb', line 228 def method_missing(sym,*args) return @view.send(sym,*args) if @view and @view.respond_to?(sym) return instance_variable_get("@#{sym}") if args.empty? and instance_variables.member? "@#{sym}" return @controller.send(sym, *args) if @controller and @controller.respond_to?(sym) raise NoMethodError.new(sym.to_s) end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
176 177 178 |
# File 'lib/lilu.rb', line 176 def action @action end |
#doc ⇒ Object
Returns the value of attribute doc.
176 177 178 |
# File 'lib/lilu.rb', line 176 def doc @doc end |
#html_source ⇒ Object (readonly)
Returns the value of attribute html_source.
177 178 179 |
# File 'lib/lilu.rb', line 177 def html_source @html_source end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
177 178 179 |
# File 'lib/lilu.rb', line 177 def instructions @instructions end |
Instance Method Details
#apply ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/lilu.rb', line 192 def apply eval(@instructions) do |*name| name = name.first name = 'layout' if name.nil? instance_variable_get("@content_for_#{name}") end @doc.to_html end |
#element ⇒ Object
179 180 181 |
# File 'lib/lilu.rb', line 179 def element action.element end |
#element_at(path) ⇒ Object
224 225 226 |
# File 'lib/lilu.rb', line 224 def element_at(path) doc.at(path) end |
#mapping(opts = {}) ⇒ Object
212 213 214 |
# File 'lib/lilu.rb', line 212 def mapping(opts={}) opts end |
#partial(name, opts = {}) ⇒ Object
Helper for partials
217 218 219 |
# File 'lib/lilu.rb', line 217 def partial(name,opts={}) render({:partial => name}.merge(opts)) end |