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
-
#at(element) ⇒ Object
Helper for ElementAt.
- #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.
-
#text ⇒ Object
Helper for ElementText.
Constructor Details
#initialize(instructions, html_source, local_assignments = {}) ⇒ Renderer
Returns a new instance of Renderer.
163 164 165 166 167 168 169 |
# File 'lib/lilu.rb', line 163 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
220 221 222 223 224 225 |
# File 'lib/lilu.rb', line 220 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.
156 157 158 |
# File 'lib/lilu.rb', line 156 def action @action end |
#doc ⇒ Object
Returns the value of attribute doc.
156 157 158 |
# File 'lib/lilu.rb', line 156 def doc @doc end |
#html_source ⇒ Object (readonly)
Returns the value of attribute html_source.
157 158 159 |
# File 'lib/lilu.rb', line 157 def html_source @html_source end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
157 158 159 |
# File 'lib/lilu.rb', line 157 def instructions @instructions end |
Instance Method Details
#apply ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/lilu.rb', line 172 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 |
#at(element) ⇒ Object
Helper for ElementAt
211 212 213 |
# File 'lib/lilu.rb', line 211 def at(element) ElementAt.new(self,element) end |
#element ⇒ Object
159 160 161 |
# File 'lib/lilu.rb', line 159 def element action.element end |
#element_at(path) ⇒ Object
201 202 203 |
# File 'lib/lilu.rb', line 201 def element_at(path) doc.at(path) end |
#mapping(opts = {}) ⇒ Object
192 193 194 |
# File 'lib/lilu.rb', line 192 def mapping(opts={}) opts end |
#partial(name, opts = {}) ⇒ Object
Helper for partials
197 198 199 |
# File 'lib/lilu.rb', line 197 def partial(name,opts={}) render({:partial => name}.merge(opts)) end |
#replacing(element) ⇒ Object
Helper for Replacing
206 207 208 |
# File 'lib/lilu.rb', line 206 def replacing(element) Replacing.new(self,element) end |
#text ⇒ Object
Helper for ElementText
216 217 218 |
# File 'lib/lilu.rb', line 216 def text ElementText.instance end |