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.



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

Raises:

  • (NoMethodError)


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

#actionObject

Returns the value of attribute action.



176
177
178
# File 'lib/lilu.rb', line 176

def action
  @action
end

#docObject

Returns the value of attribute doc.



176
177
178
# File 'lib/lilu.rb', line 176

def doc
  @doc
end

#html_sourceObject (readonly)

Returns the value of attribute html_source.



177
178
179
# File 'lib/lilu.rb', line 177

def html_source
  @html_source
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



177
178
179
# File 'lib/lilu.rb', line 177

def instructions
  @instructions
end

Instance Method Details

#applyObject



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

#elementObject



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

#replacing(element) ⇒ Object

Helper for replacing



236
237
238
# File 'lib/lilu.rb', line 236

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