Skip to content

Commit c489b17

Browse files
committed
Added support for blocks in menu_item, to be more inline with link_to's capabilities.
1 parent 0afff97 commit c489b17

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

app/helpers/navbar_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def menu_group(options={}, &block)
1515
content_tag(:ul, :class => "nav #{pull_class}", &block)
1616
end
1717

18-
def menu_item(name, path="#", *args)
18+
def menu_item(name=nil, path="#", *args, &block)
19+
path = name || path if block_given?
1920
options = args.extract_options!
2021
content_tag :li, :class => is_active?(path) do
21-
link_to name, path, options
22+
name, path = path, options if block_given?
23+
link_to name, path, options, &block
2224
end
2325
end
2426

spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@
101101
self.stub!("uri_state").and_return(:active)
102102
menu_item("Log out", "/users/sign_out", :class => "home_link", :method => :delete).should eql('<li class="active"><a href="/users/sign_out" class="home_link" data-method="delete" rel="nofollow">Log out</a></li>')
103103
end
104+
it "should pass a block but no name if a block is present" do
105+
self.stub!("current_page?").and_return(false)
106+
menu_item("/"){content_tag("i", "", :class => "icon-home") + " Home"}.should eql('<li><a href="/"><i class="icon-home"></i> Home</a></li>')
107+
end
108+
it "should work with just a block" do
109+
self.stub!("current_page?").and_return(false)
110+
menu_item{ content_tag("i", "", :class => "icon-home") + " Home" }.should eql('<li><a href="#"><i class="icon-home"></i> Home</a></li>')
111+
end
112+
it "should return the link with class 'active' if on current page with a block" do
113+
self.stub!("uri_state").and_return(:active)
114+
menu_item("/"){ content_tag("i", "", :class => "icon-home") + " Home" }.should eql('<li class="active"><a href="/"><i class="icon-home"></i> Home</a></li>')
115+
end
104116
end
105117

106118
describe "drop_down" do

0 commit comments

Comments
 (0)