Class: Lilu::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/lilu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instructions, html_source, local_assignments = {}) ⇒ Renderer

Returns a new instance of Renderer.



187
188
189
190
191
192
193
# File 'lib/lilu.rb', line 187

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

Raises:

  • (NoMethodError)


232
233
234
235
236
237
# File 'lib/lilu.rb', line 232

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

#actionObject

Returns the value of attribute action.



180
181
182
# File 'lib/lilu.rb', line 180

def action
  @action
end

#docObject

Returns the value of attribute doc.



180
181
182
# File 'lib/lilu.rb', line 180

def doc
  @doc
end

#html_sourceObject (readonly)

Returns the value of attribute html_source.



181
182
183
# File 'lib/lilu.rb', line 181

def html_source
  @html_source
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



181
182
183
# File 'lib/lilu.rb', line 181

def instructions
  @instructions
end

Instance Method Details

#applyObject



196
197
198
199
200
201
202
203
# File 'lib/lilu.rb', line 196

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

#elementObject



183
184
185
# File 'lib/lilu.rb', line 183

def element
  action.element
end

#element_at(path) ⇒ Object



228
229
230
# File 'lib/lilu.rb', line 228

def element_at(path)
  doc.at(path)
end

#mapping(opts = {}) ⇒ Object



216
217
218
# File 'lib/lilu.rb', line 216

def mapping(opts={})
  opts
end

#partial(name, opts = {}) ⇒ Object

Helper for partials



221
222
223
# File 'lib/lilu.rb', line 221

def partial(name,opts={})
  render({:partial => name}.merge(opts))
end

#replacing(element) ⇒ Object

Helper for replacing



240
241
242
# File 'lib/lilu.rb', line 240

def replacing(element)
  Replacing.new(self,element)
end