Browse files

Add populate(path).for(:each,list) construct

  • Loading branch information...
1 parent bbbb6c1 commit b168f0bcbec2ba30fb63930d0085035162a2c5ed @DimaD DimaD committed Jun 5, 2008
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/actions/populate.rb
  2. +10 −0 spec/lilu_spec.rb
View
2 lib/actions/populate.rb
@@ -14,7 +14,7 @@ def for(method,data,&block)
element_html = element.to_html
data.send(method) do |*objects|
update_action.element = element
- update_action.with(block.call(*objects))
+ update_action.with( block ? block.call(*objects) : objects )
parent.insert_before(Hpricot.make(element.to_html),element)
element = Hpricot.make(element_html)
View
10 spec/lilu_spec.rb
@@ -95,6 +95,16 @@
li_items.last[:id].should == "2"
end
+ it "should populate element details on populate(path).for(:each,list) construct" do
+ @list = %w[apple orange grapefruit]
+ @instructions = %{populate("#fruits li").for(:each, list)}
+ @html_source = %{<ul id="fruits"><li>watermelon</li></ul>}
+ @Document = Lilu::Document.new(@instructions,@html_source, {'list' => @list})
+ result = Hpricot(@Document.render)
+ li_items = result.search("#fruits li")
+ @list.each_with_index {|el, i| li_items[i].inner_html.should == el}
+ end
+
it "should populate element details on populate(:all,path).for(:each,@blogs) { block } construct" do
@blogs = [OpenStruct.new(:url => "http://railsware.com", :blog_id => 1, :name => "Railsware")]
@instructions = %{populate(:all,".blog-example").for(:each,@blogs) {|blog| mapping at('a') => {:href => blog.url, text => blog.name}, :id => blog.blog_id } }

0 comments on commit b168f0b

Please sign in to comment.