Class: Lilu::Replace

Inherits:
Action 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

Instance Method Details

#with(new_element = nil, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lilu.rb', line 55

def with(new_element=nil,&block)
  return element.collect {|e| self.element = e ; renderer.instance_eval { action.with(new_element) } } if element.is_a?(Hpricot::Elements)
  case new_element
  when String
    element.swap new_element
  when Hpricot::Elem
    Hpricot::Elements[new_element].remove
    element.parent.insert_after(new_element,element)
    Hpricot::Elements[element].remove
  when Proc
    with(new_element.call.to_s)
  when nil
    with renderer.instance_eval(&block) if block_given?
  else
    element.swap new_element.to_s
  end
end