Skip to content

sunkencity/joels_menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JoelsMenu

Menu plugin for rails.

  • Highlights the current items

  • Support for submenu

  • Support for crumbtrail

Example screenshot

Changes

To simplify and add the possibility of more advanced privilege handling, I’ve moved all the privilege handling out of the library and made it just take a block instead, the configuration is no longer read through YAML and there’s no automatic handling of user visibility & privileges. I was thinking of adding the possibility to add a proc through YAML but then it seemed more sane to just have the configuration in plain ruby instead. I’ve added a legacy-yaml branch if anyone wants to keep on using that.

Example usage

Shows how you might configure if you are using asciicasts.com/episodes/188-declarative-authorization

  <% 
    menu = joels_menu(request.path) do |m|
        m.menu_item("Home Sweet home", "/")
        if current_user
          if current_user.role_symbols.include?(:client)
            m.menu_item("Foos", "/foos")
            m.menu_item("Bars", "/bars")
            m.menu_item("FooBars", "/foobars") if current_user.can_has?(:foo_bars, cookies[:foo_bars])
          end

          if current_user.role_symbols.include?(:admin)
            m.menu_item("Admin", "/admin") do |admin|
              admin.menu_item("Accounts", "/accounts")
            end
          end
        end
    end
  %>

  <ul id="navlist">
    <% for n in menu.mainmenu %>
      <li class="<%= n.css_class %>">
         <a href="<%= n.path %>" class="<%= n.css_class %>"><%= n.name %></a>
      </li>
    <% end %>
  </ul>

<ul id="submenu">
  <% for n in menu.submenu %>
    <li class="<%= n.css_class %>">
       <a href="<%= n.path %>" class="<%= n.css_class %>"><%= n.name %></a>
    </li>
  <% end %>
</ul>

<div id="breadcrumbs">
  <% for i in menu.crumbtrail %>
  <%= link_to i.name, i.path %> &raquo;
  <% end %>
</div>

CSS

#navlist
{
margin: 0;
}

#navlist ul, #navlist li
{
margin: 0;
padding: 0;
display: inline;
list-style-type: none;
}

#navlist a:link, #navlist a:visited
{
float: left;
line-height: 18px;
font-weight: bold;
margin: 0 10px 0 0;
text-decoration: none;
color: #999;
background: white;
padding: 6px 10px 5px 10px;
font-size: 14px;
}

#navlist a:link.active, #navlist a:visited.active, #navlist a:hover
{
  color: #000;
}

#navlist a:hover { color: #000; }

/* =SUBMENU===================================================== */

#submenu {
    padding: 0;
    margin: 0;
    list-style: none;
}

#submenu li { display: inline; padding: 0; margin: 0; }

#submenu li:before { content: "| "; }
#submenu li:first-child:before { content: ""; }

#submenu a:link, #submenu a:visited {
    text-decoration: none;
    color: black;
}

#submenu a:link.active, #submenu a:visited.active, #submenu a:hover {
    font-weight: bold;
}

Copyright © 2010 Joel Westerberg, released under the MIT license

About

A plugin to create menu, submenu and breadcrumbs for rails.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages