I'm currently writing a modular rails app where every functionality is inside a rails engine. I've set up my first engine and everything's working fine so far. now I'm wondering what is the best way to hook the engine into my global navigation that is currently rendered in app/views/layouts/application.html.haml, like this:
%nav#main-nav
%ul
%li
= link_to "Users", users_path, :class => "no-submenu settings"
%ul
%li ...
The closest thing I found was the HookListener of spree, which uses the deface gem. unfortunately deface only works with html/erb output since it parses the DOM with nokogiri, which isn't the best idea anyway.
for the record, i've solved it like this:
Navigation classMyEnginecore/lib/navigation.rb:
class Navigation
@registered_blocks = {}
class << self
def register(name, &block)
@registered_blocks[name] ||= block
end
def bind(root)
@registered_blocks.each do |name, block|
block.call(root)
end
end
end
end
myext/lib/myext/engine.rb:
Navigation.register :myext do |root|
root.item :mylink, "My Link", "/"
end
config/navigation.rb (for simple-navigation):
navigation.items do |root|
Navigation.bind(root)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With