navlinks 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ = Very light-weight implementation for navigation links
2
+
3
+ = Simple navigation (HOWTO)
4
+
5
+ === First add navigation areas to the layout
6
+
7
+ ==== app/views/layouts/application.html.erb
8
+ <html>
9
+ <head>
10
+ </head>
11
+ <body>
12
+ <ul id="nav">
13
+ <li><%= nav_link_to :home, root_path %></li>
14
+ <li><%= nav_link_to :foo, foo_ath %></li>
15
+ </ul>
16
+
17
+ <div id="content">
18
+ <%= yield %>
19
+ </div>
20
+ </body>
21
+ </html>
22
+
23
+ === Next, label different views to belong to different nav areas.
24
+
25
+ Let's have the home page be part of 'home' area and showing a Foo resource part of 'foo' area.
26
+
27
+ ==== app/views/pages/home.html.erb
28
+ <%- self.nav_area = :home -%>
29
+
30
+ ==== app/views/foos/show.html.erb
31
+
32
+ <%- self.nav_area = :foo -%>
33
+
34
+ === Done!
35
+
36
+ = Localization
37
+
38
+ +navlinks+ supports common localization but also allows some tricks. Suppose the localization file is as follows:
39
+
40
+ ==== config/locate/en.yml
41
+ en:
42
+ navigation:
43
+ home: Go home
44
+ home_current: At home
45
+
46
+ This causes the 'home' area description to be usually 'Go home'. However if the user is looking at a page that belongs to 'home', it will display 'At home'. Cool, huh?
47
+
48
+ = Decoration Override
49
+
50
+ By default the plugin decorates the 'current' area with brackets. It is possible to override this behavior by overriding +decorate_current_label+ method:
51
+
52
+ ==== app/helpers/application_helper.rb
53
+
54
+ module ApplicationHelper
55
+
56
+ # causes the current navigation label to be described as:
57
+ # * home *
58
+ def decorate_current_label( current_label )
59
+ "* #{current_label} *"
60
+ end
61
+ end
62
+
63
+ Now instead of [ home ] you will see * home *
64
+
65
+ = Contact
66
+
67
+ Feel free to contact me with any questions/comments!
@@ -0,0 +1,3 @@
1
+ module ApplicationHelper
2
+ helper :navigation
3
+ end
@@ -0,0 +1,21 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module NavigationHelper
3
+ attr_accessor :nav_area
4
+
5
+ def nav_link_to area, path, options = nil
6
+ label = translate(area, :scope => 'navigation', :default => area.to_s)
7
+ current_label = translate([ area, 'current' ].join('_'), :scope => 'navigation', :default => label)
8
+
9
+ if nav_area == area
10
+ link_to(decorate_current(current_label), path, :class => 'current')
11
+ else
12
+ link_to(label, path)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def decorate_current( current_label )
19
+ "[ #{current_label} ]"
20
+ end
21
+ end
data/lib/navlinks.rb ADDED
@@ -0,0 +1 @@
1
+ # blank, since doesn't require anything
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: navlinks
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Ratnikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-25 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ratnikov@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - app/helpers/application_helper.rb
27
+ - app/helpers/navigation_helper.rb
28
+ - lib/navlinks.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/ratnikov/navlinks
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.3.5
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Provides very light-weight navigation implementation
57
+ test_files: []
58
+