Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "SemanticMenu may be cached."

This reverts commit 6d47cd6.
  • Loading branch information...
commit 99118845a47c4eb8ab4dd93d411088dd68ba1691 1 parent 4dbc605
Daniel Haran authored
View
2  lib/menu_helper.rb
@@ -16,6 +16,6 @@
# </ul>
module MenuHelper
def semantic_menu(opts={}, &block)
- SemanticMenu.new(opts, &block).to_s(controller)
+ SemanticMenu.new(controller, opts, &block).to_s
end
end
View
12 lib/semantic_menu.rb
@@ -20,8 +20,7 @@ def add(title, link, link_opts={}, &block)
end
end
- def to_s(controller=nil)
- @controller = controller
+ def to_s
content_tag :li, link_to(@title, @link, @link_opts) + child_output, ({:class => 'active'} if active?)
end
@@ -38,13 +37,15 @@ def active?
end
def on_current_page?
- @controller && current_page?(@link)
+ @controller = @@controller # set it for current_page? defined in UrlHelper
+ current_page?(@link)
end
end
class SemanticMenu < MenuItem
- def initialize(opts={},&block)
+ def initialize(controller, opts={},&block)
+ @@controller = controller
@opts = {:class => 'menu'}.merge opts
@level = 0
@children = []
@@ -52,8 +53,7 @@ def initialize(opts={},&block)
yield self if block_given?
end
- def to_s(controller=nil)
- @controller = controller
+ def to_s
content_tag(:ul, @children.collect(&:to_s).join, @opts)
end
end
View
10 test/semantic_menu_test.rb
@@ -8,7 +8,7 @@
class SemanticMenuTest < ActiveSupport::TestCase
def test_menu_to_s
- assert_equal SemanticMenu.new {}.to_s, '<ul class="menu"></ul>'
+ assert_equal SemanticMenu.new(nil) {}.to_s, '<ul class="menu"></ul>'
end
def test_menu_item_to_s
@@ -46,7 +46,7 @@ def test_menu_item_shows_active_if_on_current_page
def test_nested_menu
MenuItem.any_instance.stubs(:active?).returns(true)
- menu = SemanticMenu.new do |root|
+ menu = SemanticMenu.new(nil) do |root|
root.add 'top_level', 'some_page_path' do |link1|
link1.add 'first_child', 'lower_page_path'
end
@@ -60,12 +60,12 @@ def test_nested_menu
</li>
</ul>
NESTED
- assert_equal expected.gsub(/\n */, '').gsub(/\n/, ''), menu.to_s(nil)
+ assert_equal expected.gsub(/\n */, '').gsub(/\n/, ''), menu.to_s
end
def test_parent_is_active_when_any_child_is
l1, l1_1, l1_2 = [nil] * 3
- menu = SemanticMenu.new do |root|
+ menu = SemanticMenu.new(nil) do |root|
l1 = root.add 'level1.1', 'link_1.1' do |link1|
l1_1 = link1.add 'I-1', 'link_I-1'
l1_2 = link1.add 'I-2', 'link_I-2-active'
@@ -93,7 +93,7 @@ def test_parent_is_active_when_any_child_is
protected
def default_menu
- SemanticMenu.new :class => 'mymenu' do |root|
+ SemanticMenu.new nil, :class => 'mymenu' do |root|
root.add 'title', 'link'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.