codeplant/simple-navigation

Simple way to specify an font awsome icon as a parameter

Closed this issue · 1 comments

Instead of having to do this;

  navigation.name_generator = Proc.new do |name, item|

    if item.key == :'dashboard'
      "<i class='fa fa-2x fa-file'></i> #{name}".html_safe
    elsif item.key == :'organisations'
      "<i class='fa fa-2x fa-handshake-o'></i> #{name}".html_safe
    elsif item.key == :'users'
      "<i class='fa fa-2x fa-vcard-o'></i> #{name}".html_safe
    elsif item.key == :'settings'
      "<i class='fa fa-2x fa-cog'></i> #{name}".html_safe
    else
      name
    end

  end

I would like to specify the icon in the navigation block instead.

navigation.items do |primary|

    primary.dom_class           = ''
    navigation.selected_class   = 'active'

    primary.item :dashboard, "Dashboard", admin_dashboard_path,
                 **:icon => { 'cog'},
                :html => {:class => 'fa fa2x'},**
                 :highlights_on => lambda { ["admin/dashboard"].member?(params[:controller]) }

I have not been able to figure out how to do this, can this feature be added?
Font awesome is very popular ( or any other icon library in that matter ) and currently its a big pain to add icons at all before an navigational item.

andi commented

although FA is very popular, there are still a lot of other icon fonts or means to generate icons. simple-navigation is framework agnostic and therefore we do not want to introduce coupling to other libraries.

You can either use name_generator as you described (maybe you extract the if-else logic into a helper). That's exactly the use case of name_generator.

Or you could simply write your own renderer similar to the existing ListRenderer:
https://github.com/codeplant/simple-navigation/blob/master/lib/simple_navigation/renderer/list.rb