preventing recursive loop when used as engine in an app
This commit is contained in:
parent
32f7552a50
commit
8298b2a4bf
@ -40,6 +40,8 @@ class Admin::MenuCell < Cell::Base
|
|||||||
method_name = "build_list_with_#{name}".to_sym
|
method_name = "build_list_with_#{name}".to_sym
|
||||||
previous_method_name = "build_list_without_#{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(:define_method, method_name) do
|
||||||
self.send(previous_method_name)
|
self.send(previous_method_name)
|
||||||
block.call(MenuProxy.new(self))
|
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
|
# Note: this might cause "stack level too deep" if called twice for the same name
|
||||||
alias_method_chain :build_list, name.to_sym
|
alias_method_chain :build_list, name.to_sym
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class Admin::SettingsMenuCell < ::Admin::MenuCell
|
class Admin::SettingsMenuCell < ::Admin::SubMenuCell #::Admin::MenuCell
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
@ -8,10 +8,10 @@ class Admin::SettingsMenuCell < ::Admin::MenuCell
|
|||||||
add :account, :url => edit_admin_my_account_url
|
add :account, :url => edit_admin_my_account_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_item(name, attributes)
|
# def build_item(name, attributes)
|
||||||
item = super
|
# item = super
|
||||||
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
|
# enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
|
||||||
item.merge(:class => enhanced_class)
|
# item.merge(:class => enhanced_class)
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
11
app/cells/admin/sub_menu_cell.rb
Normal file
11
app/cells/admin/sub_menu_cell.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user