Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion: menu modification #138

Closed
wvengen opened this issue Oct 25, 2013 · 6 comments
Closed

Feature suggestion: menu modification #138

wvengen opened this issue Oct 25, 2013 · 6 comments

Comments

@wvengen
Copy link

wvengen commented Oct 25, 2013

When putting some functionality of an app in engines, it can be useful to add something to the menu, or modify it. This is possible currently, but not documented and as such unclear if the method will keep working on updates.

Suggestion: add menu modification to the wishlist.

Perhaps it would be to (allow to) load menus from <plugin>/config/navigation.rb, but the order of loading would require some thought.

I'm currently using this method based on this gist.

@ianneub
Copy link

ianneub commented Jan 31, 2014

I'm also following the Engines pattern and this little trick was awesome. Thanks!

👍 For a more "official" solution.

@simonc
Copy link
Contributor

simonc commented Jul 29, 2014

I don't really know what to think about this. @andi do you have any thoughts on that subject?

@mjtko
Copy link
Contributor

mjtko commented Jul 29, 2014

Wow, I wrote that gist an awful long time ago. 😀

I'm not sure how we can support this without cluttering the configuration code with Rails specifics. I think this is two things:

  1. A request for supporting the enhancement of navigation from engines
  2. A request to define a cleaner API for modifying existing navigation programatically

(Warning, thinking aloud follows!)

Perhaps, for (1) we could introduce a SimpleNavigation::Provider mixin that, when included into an Engine (or any other class) registers its interest in enhancing the navigation when it's configured. At configuration time, SImpleNavigation would configure the navigation and then hand it off to each provider for further enhancement.

For (2), we could add to the API to replace the invocation of: primary[:existing_sub_menu].sub_navigation.items with modify(:existing_sub_menu) { |nav| ... } or somesuch.

@andi
Copy link
Collaborator

andi commented Jul 30, 2014

I think I would prefer 2)… But in general I’m not sure if this is an edge
case. What are real world examples of changing the menu in an engine?

On Tue, Jul 29, 2014 at 3:04 PM, Mark J. Titorenko <notifications@github.com

wrote:

Wow, I wrote that gist an awful long time ago. [image: 😀]

I'm not sure how we can support this without cluttering the configuration
code with Rails specifics. I think this is two things:

  1. A request for supporting the enhancement of navigation from engines
  2. A request to define a cleaner API for modifying existing navigation
    programatically

(Warning, thinking aloud follows!)

Perhaps, for (1) we could introduce a SimpleNavigation::Provider mixin
that, when included into an Engine (or any other class) registers its
interest in enhancing the navigation when it's configured. At configuration
time, SImpleNavigation would configure the navigation and then hand it off
the each provider for further enhancement.

For (2), we could add to the API to replace the invocation of:
primary[:existing_sub_menu].sub_navigation.items with modify(:existing_sub_menu)
{ |nav| ... } or somesuch.


Reply to this email directly or view it on GitHub
#138 (comment)
.

@simonc
Copy link
Contributor

simonc commented Jul 31, 2014

I suppose a blog engine could want to add the "Blog" entry to the menu or something like that. If you adopt the completely decoupled approach to Rails with engines composition, it could probably make sense.

@ianneub
Copy link

ianneub commented Jul 31, 2014

Here is a use case from my application:

I have a Rails app that is split up into many Rails engines. I have one Rails app that acts as the "top level" that includes all the other apps and sets up the layout. In that application I use Simple Navigation, and each engine needs to be able to plug into that interface to be able to display its navigation items.

The way I "fixed" it was the following:

In one of the engines (the ui engine) I have this:

SimpleNavigation::Configuration.run do |navigation|
  engines = Rails::Engine.subclasses.map(&:instance).select do |e|
    e.respond_to?(:navigation)
  end

  navigation.items do |primary|
    engines.sort{|a,b| a.class.to_s <=> b.class.to_s }.each do |e|
      e.navigation(primary, self)
    end
  end
end

In each of the other included engines I have something like this (from the pages engine):

def navigation(primary, context)
  primary.item :pages, {text: "Pages", icon: 'fa fa-cube'}, context.pages.root_path, if: proc{ context.can?(:read, Page) }, highlights_on: proc{ context.controller.class.name.split("::").first == "Pages" }
end

This effectively lets each engine add its own navigation items to the menu.

@andi andi closed this as completed Aug 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants