Socket
Book a DemoInstallSign in
Socket

navlinks

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

navlinks

0.2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

= Very light-weight implementation for navigation links

= Simple navigation (HOW-TO)

=== Install

gem install navlinks --source http://gemcutter.org

=== First add navigation areas to the layout

==== app/views/layouts/application.html.erb

  • <%= nav_link_to :home, root_path %>
  • <%= nav_link_to :foo, foo_path %>
  <div id="content">
    <%= yield %>
  </div>
</body>

=== Next, label what views belong to what nav areas

Suppose we have following pages:

  • A home page that is rendered by +pages/home.html.erb+ template and that we want to belong to 'home' nav area.
  • A page where we show a Foo resource that is rendered by +foos/show.html.erb+ template and that we want to belong to 'foo' nav area.

Easy! Just assign the nav-areas at the top of the views like this:

==== app/views/pages/home.html.erb <%- self.nav_area = :home -%>

==== app/views/foos/show.html.erb

<%- self.nav_area = :foo -%>

=== Done!

Now when someone is viewing the +pages/home.html.erb+ template, the 'home' anchor tag will have a class +current+. If someone is viewing a +foos/show.html.erb+ template, then the 'foo' anchor tag will have a class +current+. When viewing any other page, however, both of the navigation anchors will not have any classes.

= Localization

+navlinks+ supports common localization but also allows some tricks. Suppose the localization file is as follows:

==== config/locate/en.yml en: navigation: home: Go home home_current: At home

This causes the 'home' area description to be usually 'Go home'. However if the user is looking at a page that belongs to 'home' nav area, it will display 'At home'. Cool, huh?

= Decoration Override

By default the plugin decorates the 'current' area with brackets. It is possible to override this behavior by overriding +decorate_current_label+ method:

==== app/helpers/application_helper.rb

module ApplicationHelper

# causes the current navigation label to be described as:
# * home *
def decorate_current_label( current_label )
  "* #{current_label} *"
end

end

Now instead of [ home ] you will see * home *

= Contact

Feel free to contact me with any questions/comments!

FAQs

Package last updated on 07 Apr 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.