Skip to content

Commit

Permalink
Rails 3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvlopes committed Jun 23, 2010
1 parent 6464122 commit 5d7e5bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
14 changes: 7 additions & 7 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ in controller. Easy like always should be!

== Instalation

As a Rail2.1+ gem
Rail2

gem.config "menu_builder"

As Rails plugin
gem.config "menu_builder", :version => '0.2.1'
Rails3

ruby script/plugin install git://github.com/danielvlopes/menu_builder.git
gem "menu_builder", '>=0.2.2'

== Usage

Expand All @@ -30,7 +30,7 @@ Just install the plugin and see the example below:

==== ERB code

<% menu(:id=>"mainMenu", :class=>"menu") do |m| %>
<%= menu(:id=>"mainMenu", :class=>"menu") do |m| %>
<%= m.account 'Account', account_path, :style => 'float: right' %>
<%= m.users 'Users', users_path, :style => 'float: right' %>
<%= m.mydashboard 'Dashboard', '/' %>
Expand All @@ -51,7 +51,7 @@ Just install the plugin and see the example below:
Also is possible to pass blocks instead of simple strings for content.
In this way you can create menu item with icons. Like below:

<% menu do |m| %>
<%= menu do |m| %>
<% m.account account_path do %>
<%= image_tag "icon.jpg" /> Accounts
<% end %>
Expand Down
11 changes: 2 additions & 9 deletions lib/menu_builder/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ def method_missing(item, *args, &block)

end

def menu(options={})
concat tag(:ul, options, true)
yield Menu.new(self)
concat safe_html("</ul>")
def menu(options={}, &block)
content_tag :ul, capture(Menu.new(self), &block), options
end

private
def safe_html(html)
html.respond_to?(:html_safe) ? html.html_safe : html
end

end
end
2 changes: 1 addition & 1 deletion menu_builder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Daniel Lopes"]
s.date = %q{2010-03-20}
s.date = %q{2010-06-23}
s.description = %q{ helper and controller macros to define current menu item and also create the menu in view. }
s.email = %q{danielvlopes@gmail.com}
s.extra_rdoc_files = [
Expand Down
26 changes: 13 additions & 13 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ class HelperTest < ActionView::TestCase
tests MenuBuilder::ViewHelpers

test "menu yields an instance of Menu" do
menu do |m|
concat(menu do |m|
assert m.instance_of?(MenuBuilder::ViewHelpers::Menu)
end
end)
end

test "menu create an unordered list" do
menu :id=>"menu" do |m| end
concat(menu(:id => "menu") { |m| })
assert_select "ul#menu"
end

test "menu should accept html options like classes and id" do
menu :id=>"menu", :class=>"tabs" do |m| end
concat(menu :id=>"menu", :class=>"tabs" do |m| end)
assert_select "ul#menu.tabs"
end

test "menu should create a line item" do
menu { |m| concat m.home "Home", "#" }
concat(menu { |m| concat m.home "Home", "#" })
assert_select "li", 1
end

test "should create a link inside line item" do
menu { |m| concat m.home "Home", "/" }
concat(menu { |m| concat m.home "Home", "/" })
expected = %(<ul><li><a href="/">Home</a></li></ul>)
assert_dom_equal expected, output_buffer
end

test "should set the class to the current item li" do
@menu_item = :home
menu do |m|
concat(menu do |m|
concat m.home "Home", "/"
concat m.contact "Store", "/store"
end

end)
assert_select "li.current", 1
end

Expand Down

0 comments on commit 5d7e5bb

Please sign in to comment.