diff --git a/README.markdown b/README.markdown
index 20e9c73..726d7a0 100644
--- a/README.markdown
+++ b/README.markdown
@@ -33,7 +33,7 @@ when you installed the plugin. Let's take a look at what's inside this helper:
def build_mmmenu(menu)
menu.item_markup(0, :active_markup => 'class="current"') do
- |link, text, options| "
#{text}\n"
+ |link, text, options| "#{text}\n"
end
menu.level_markup(0) { |menu| '' }
menu.level_markup(1) { |menu| '' }
@@ -43,7 +43,44 @@ when you installed the plugin. Let's take a look at what's inside this helper:
You can see now, that `#item_markup` method defines the html markup for menu item,
and `#level_markup` does the same for menu level wrapper. They may contain as much levels
as you want and you don't need to define a markup for each level: the deepest level markup
-defined will be used for all of the deeper levels. Now go ahead and change this method the way you like.
+defined will be used for all of the deeper levels.
+
+Moreover, you might want to highlight `li` tag and pass some class to `a` tag, you can
+do it like this:
+
+ def build_mmmenu(menu)
+ menu.item_markup(0, :active_markup => 'class="current"') do
+ |link, text, options| "#{text}\n"
+ end
+ menu.build
+ end
+
+ @menu = Mmmenu.new(:request => @request) do |m|
+ m.add 'Item1', '/items1', :match_subpaths => true
+ m.add 'Item2', '/items2', :html => 'class="special_link"' do |subm|
+ subm.add 'New', '/item2/new'
+ subm.add 'Edit', '/item2/edit', :html => 'huh'
+ end
+ end
+
+Or, in combination with powered by Rails `#content_tag` and `#link_to` like this:
+
+ def build_mmmenu(menu)
+ menu.item_markup(0, :active_markup => { :class => :current }) do
+ |link, text, options| content_tag(:li, link_to(text, link, options[:html]), options[:active])
+ end
+ menu.build
+ end
+
+ @menu = Mmmenu.new(:request => @request) do |m|
+ m.add 'Item1', '/items1', :match_subpaths => true
+ m.add 'Item2', '/items2', :html => { :class => :special_link } do |subm|
+ subm.add 'New', '/item2/new'
+ subm.add 'Edit', '/item2/edit'
+ end
+ end
+
+Now go ahead and change this method the way you like.
Finally, let's take a closer look at some of the options and what they mean.
---------------------------------------------------------------------
diff --git a/lib/mmmenu.rb b/lib/mmmenu.rb
index b0d46ce..5ec42b5 100644
--- a/lib/mmmenu.rb
+++ b/lib/mmmenu.rb
@@ -47,7 +47,7 @@ def build_level(items=@items, level=0)
raise("Mmmenu object #{self} is empty, no items defined!") if items.nil? or items.empty?
items.each do |item|
- option_current = nil
+ options = {}
child_menu = build_level(item[:children], level+1) if item[:children]
child_output = child_menu[:output] if child_menu
@@ -63,12 +63,13 @@ def build_level(items=@items, level=0)
) and !has_active_item
then
- option_current = item_markup[:active] and has_active_item = true
+ options[:active] = item_markup[:active] and has_active_item = true
end
#############################################################
- item_output = item_markup[:basic].call(item[:href], item[:title], option_current)
+ options.merge!(:html => item[:html]) if item[:html]
+ item_output = item_markup[:basic].call(item[:href], item[:title], options)
output += "#{item_output}#{child_output}"
end
@@ -122,7 +123,7 @@ def build_item_markup(level)
unless @item_markup.empty?
{ :basic => @item_markup.last[:block], :active => @item_markup.last[:active_markup] }
else
- { :basic => lambda { |link,text,options| "#{text} #{link} #{options}\n" }, :active => 'current' }
+ { :basic => lambda { |link,text,options| "#{text} #{link} #{options[:active]} #{options[:html]}\n" }, :active => 'current' }
end
end
end
diff --git a/spec/lib/mmmenu_spec.rb b/spec/lib/mmmenu_spec.rb
index e76a88b..58b1e4e 100644
--- a/spec/lib/mmmenu_spec.rb
+++ b/spec/lib/mmmenu_spec.rb
@@ -25,10 +25,10 @@
it "renders one level" do
@menu.item_markup(0, :active_markup => 'current') do |link, text, options|
- "#{text}: #{link} #{options}\n"
+ "#{text}: #{link} #{options[:active]}\n"
end
@menu.item_markup(2, :active_markup => 'current') do |link, text, options|
- " #{text}: #{link} #{options}\n"
+ " #{text}: #{link} #{options[:active]}\n"
end
@menu.level_markup(0) { |menu| menu }
(@menu.build.chomp(" \n") + "\n").should == < items, :request => request )
@menu.item_markup(0, :active_markup => 'current') do |link, text, options|
- "#{text}: #{link} #{options}\n"
+ "#{text}: #{link} #{options[:active]}\n"
end
@menu.build.should == < items, :request => request )
@menu.item_markup(0, :active_markup => 'current') do |link, text, options|
- "#{text}: #{link} #{options}\n"
+ "#{text}: #{link} #{options[:active]}\n"
end
@menu.build.should == < @request) do |m|
+ m.add 'Item1', '/items1', :match_subpaths => true
+ m.add 'Item2', '/items2', :html => 'whatever' do |subm|
+ subm.add 'New', '/item2/new'
+ subm.add 'Edit', '/item2/edit', :html => 'huh'
+ end
+ end
+
+ @menu.build.should == <