Sha256: 88a65b9ffb65331b42d9c0b577277aed6ef457b49ef2493aa335c311027f9047

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

= menu_builder

A simple helper to make easier the process of highlighting menu items based on current
url. The goal here is to reduce the amount of if/elses you would typically need in your
views to achieve the same results.

== Instalation

  gem "menu_builder"

== Usage

First flag at class level in your Controller which item should be highlighted

=== Controller

  class DashboardController < ApplicationController
    menu_item :mydashboard
    ...
  end

You can also change to menu item at action level instead of class level. This
option is helpful when you have most of the actions pointing to one menu item
but a few actions pointing to another.

  class DashboardController < ApplicationController
    menu_item :mydashboard

    def prices
      menu_item :prices
      ...
    end
  end

=== View

==== ERB code

  <%= menu(:id=>"mainMenu", :class=>"menu") do |m| %>
    <%= m.account 'Account', account_path, :style => 'float: right' %>
    <%= m.users 'Users', users_path, :style => 'float: right' %>
    <%= m.mydashboard 'Dashboard', '/' %>
    <%= m.projects 'Projects', projects_path %>
  <% end %>

==== HTML Result

   <ul id="mainMenu" class="menu">
     <li><a href="/accounts">Account</a></li>
     <li><a href="/users">Users</a></li>
     <li><a href="/" class="current">Dashboard</a></li>
     <li><a href="/projects">Projects</a></li>
   </ul>

==== Blocks for content

You can also pass blocks:

  <%= menu do |m| %>
    <% m.account account_path do %>
      <%= image_tag "icon.jpg" /> Accounts
    <% end %>
    <%= m.users "Users", users_path %>
    <%= m.posts "Posts", posts_path %>
  <% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
menu_builder-0.4.4 README.rdoc