Class: Lilu::Populate

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

Instance Attribute Summary

Attributes inherited from Action

#element, #renderer

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from Lilu::Action

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



22
23
24
# File 'lib/lilu.rb', line 22

def method_missing(sym,*args)
  send :for, sym, *args
end

Instance Method Details

#for(method, data, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lilu.rb', line 26

def for(method,data,&block)
  return element.collect {|e| self.element = e ; renderer.instance_eval { action.for(method,data,&block) } } if element.is_a?(Hpricot::Elements)

  element.cache_search = true
  update_action = Update.new(element,renderer)
  parent = element.parent
  element_html = element.to_html
  data.send(method) do |*objects| 
    update_action.element = element
    update_action.with(block.call(*objects))

    parent.insert_before(Hpricot.make(element.to_html),element) 
    element = Hpricot.make(element_html)
  end
  renderer.action = self 

  Hpricot::Elements[element].remove
end