Class: Lilu::Update

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(arg = nil, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/lilu.rb', line 76

def with(arg=nil,&block)
  return element.collect {|e| self.element = e ; renderer.instance_eval { action.with(arg,&block) } } if element.is_a?(Hpricot::Elements)
  case arg
  when Hash
    arg.each_pair do |path,value|
      value = value.call if value.is_a?(Proc)
      case path
      when ElementAt
        elem = path.find_at(element)
        raise ElementNotFound.new(elem) unless elem

        saved_element = element
        self.element = elem
        res = with(value,&block)
        self.element = saved_element
        res
      when Replacing
        Replace.new(path.element,renderer).with value.to_s
      when ElementText
        element._inner_html = value.to_s
      else
        element[path] = value.to_s
      end
    end
  when Proc
    with arg.call
  when nil
    with renderer.instance_eval(&block) if block_given?
  else  
    element._inner_html = arg.to_s
  end
end