jejacks0n / navigasmic

Navigasmic: Semantic navigation for Rails using simple view level or configuration definitions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

:highlights_on for group?

jmuheim opened this issue Β· comments

I notice that nobody seems to care about this gem anymore. What a pity.

Anyways, another question: I'd like to use :highlights_on on groups: for example when displaying a user, the users group should be active, although there is no explicit show user item in it.

To compare, the "list users" has a menu entry, so the parent group is highlighted:

image

image

But for "show user", there's no entry, so the parent group isn't highlighted:

image

image

I know that I can manually assign a class: 'active' myself, but this should be possible in an easier way.

I still care! ;-p It's really useful when it's needed -- I can't count the number of times that I've seen this built out poorly per project though. So anyway.

You can do complex things with highlights on.. You can do things like just specify the controller (so if most of your actions are within one controller like your example shows). highlights_on: [{ controller: "users" }] -- this works similar to how routing works, so if the controller is named Admin::UsersController, you would use highlights_on: [{ controller: "admin/users" }].

Additionally, and sometimes better, is to use a regex to capture it by the path that you're on. So let's say everything user nested within a /users path prefix. Then you could use hightlights_on: %r{/users}.

Hope that helps.. there's more on that in the readme too.

Yes, but it doesn't seem to work on groups?

ah, so you can nest items.. that makes an item into a group more or less -- you can specify no link for the item (or "#") and it becomes a group with all the fanciness of an item.

you may have to adjust your css for that.

I have tried this:

= navigation.group User.model_name.human(count: 2), highlights_on: proc { true } do
  ...

But this only makes this:

image

By the way:

I can't count the number of times that I've seen this built out poorly per project though.

You're so right! I have worked with SimpleNavigation before, and feels so clumsy compared to Navigasmic. The thing I love most about Navigasmic is that one can mix items and normal HTML like this:

- navigation.group user_avatar(t('.user_menu')) do
  - navigation.item "#{fa_icon :user} #{t '.show_account'}", user_registration_path
  - navigation.item "#{fa_icon :edit} #{t '.edit_account'}", edit_user_registration_path

  li
    = link_to destroy_user_session_path, method: :delete do
      = fa_icon('sign-out')
      =< t('.log_out')

πŸ‘ πŸ‘ πŸ‘

try this:

- navigation.item user_avatar(t('.user_menu')), highlights_on: [{ controller: "users" }] do
  - navigation.item "#{fa_icon :user} #{t '.show_account'}", user_registration_path
  - navigation.item "#{fa_icon :edit} #{t '.edit_account'}", edit_user_registration_path

I'm using a helper for achieving this at the moment:

  def active_class?(controller_to_check)
    :active if controller_name == controller_to_check.to_s
  end

In view:

- navigation.group User.model_name.human(count: 2), class: active_class?(:users) do
  / ...

Still, it would be very nice to be able to use the sophisticated stuff of highlights_on on group items.

This issue should be reopened in my opinion.

Try passing nil or "#" as the first arg in my example. I know for a fact that you can do that.

- navigation.group User.model_name.human(count: 2), nil, highlights_on: [{controller: :user}] do

results in

wrong number of arguments (3 for 0..2)

Am I stupid or what? 😝