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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/lilu.rb', line 110

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 String
        elem = element.at(path)
        raise ElementNotFound.new("Element #{elem} not found") 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 renderer
        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