Skip to content

Commit

Permalink
add customization of li content rendering via block
Browse files Browse the repository at this point in the history
  • Loading branch information
George F Murphy committed Nov 30, 2011
1 parent be11ed2 commit f926f7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/helpers/spree/base_helper_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Spree::BaseHelper.module_eval do

def featured_taxon_list(taxons, *args)
def featured_taxon_list(taxons, *args, &b)
return '' if taxons.empty?
opt = args.extract_options!
list_id = opt.fetch(:id) { 'featured-taxons' }
Expand All @@ -11,7 +11,7 @@ def featured_taxon_list(taxons, *args)
taxons.map do |taxon|
item_class = current.include?(taxon) ? 'current' : nil
content_tag :li, :class => item_class do
link_to(taxon.name, seo_url(taxon))
block_given? ? b.call(taxon) : link_to(taxon.name, seo_url(taxon))
end
end.join("\n").html_safe
end
Expand Down
16 changes: 16 additions & 0 deletions spec/helpers/spree/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
it "should not give a current class for list items" do
featured_taxon_list(taxons).should_not have_selector("li.current")
end

it "should link to taxons" do
list = featured_taxon_list(taxons)
taxons.each do |t|
list.should have_selector("a[href='/t/#{t.permalink}']")
end
end
end

describe "with given options" do
Expand All @@ -50,4 +57,13 @@
should have_selector("li.current")
end
end

describe "when customizing item renderer" do
it "should yield to given block for taxon rendering inside of li" do
list = featured_taxon_list(taxons) { |t| "Hello, #{t.name}" }
taxons.each do |t|
list.should have_selector("li", :text => "Hello, #{t.name}")
end
end
end
end

0 comments on commit f926f7c

Please sign in to comment.