preventing recursive loop when used as engine in an app

This commit is contained in:
did 2011-10-18 18:45:45 +02:00
parent 32f7552a50
commit 8298b2a4bf
4 changed files with 27 additions and 12 deletions

View File

@ -40,6 +40,8 @@ class Admin::MenuCell < Cell::Base
method_name = "build_list_with_#{name}".to_sym
previous_method_name = "build_list_without_#{name}".to_sym
unless self.instance_methods.include?(method_name) # prevents the method to be called twice which will raise a "stack level too deep" exception
self.send(:define_method, method_name) do
self.send(previous_method_name)
block.call(MenuProxy.new(self))
@ -47,6 +49,8 @@ class Admin::MenuCell < Cell::Base
# Note: this might cause "stack level too deep" if called twice for the same name
alias_method_chain :build_list, name.to_sym
end
end
protected

View File

@ -1,4 +1,4 @@
class Admin::SettingsMenuCell < ::Admin::MenuCell
class Admin::SettingsMenuCell < ::Admin::SubMenuCell #::Admin::MenuCell
protected
@ -8,10 +8,10 @@ class Admin::SettingsMenuCell < ::Admin::MenuCell
add :account, :url => edit_admin_my_account_url
end
def build_item(name, attributes)
item = super
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
item.merge(:class => enhanced_class)
end
# def build_item(name, attributes)
# item = super
# enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
# item.merge(:class => enhanced_class)
# end
end

View File

@ -0,0 +1,11 @@
class Admin::SubMenuCell < ::Admin::MenuCell
protected
def build_item(name, attributes)
item = super
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
item.merge(:class => enhanced_class)
end
end