codeplant / simple-navigation

A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
http://simple-navigation-demo.codeplant.ch/
MIT License
885 stars 136 forks source link

Hide primary if childs empty #169

Closed osaris closed 10 years ago

osaris commented 10 years ago

I have a menu with primary items that I want to be hidden when their childs are empty (due to user rights). My code looks like :

  navigation.items do |primary|
    primary.item(:personnel, icon_label_text('glyphicon glyphicon-user', 'Personnel')) do |personnel|
      personnel.item(:firemen, 'Hommes', firemen_path, :highlights_on => /^\/firemen/, if: proc { can?(:read, Fireman) })
      personnel.item(:convocations, 'Convocations', convocations_path, :highlights_on => /^\/convocations/, if: proc { can?(:read, Convocation) })
      personnel.item(:trainings, 'Formations', trainings_path, :highlights_on => /^\/trainings/, if: proc { can?(:read, Training) })
      personnel.item(:uniforms, 'Tenues', uniforms_path, :highlights_on => /^\/uniforms/, if: proc { can?(:read, Uniform) })
    end
  end

I can't use a if on the primary item (:personnel) and it seems that :skip_if_empty => true didn't work on primary items ?

Any advice ?

andi commented 10 years ago

Just put your if statements directly around your primary items calls, this should work.

osaris commented 10 years ago

Ok sorry for the useless ticket, don't know what I did but it didn't work when I tested last night ... It's okay right now ! Thx again.

altun commented 9 years ago

hi @osaris

in my project i can't use icon_label_text feaure. it says me undefined method. i want to add glyphicons to my menu but i can't.

Can u help me about this?

osaris commented 9 years ago

@altun it's a custom helper :

  def icon_label_text(icon_name, label)
    content_tag(:i, '', :class => icon_name) + (" " + label).html_safe
  end
altun commented 9 years ago

@altun it's a custom helper :

Oh sure! Thanks a lot.