navlinks 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -6
- data/VERSION +1 -1
- data/lib/navlinks/helper.rb +15 -6
- metadata +12 -5
data/README.rdoc
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
= Very light-weight implementation for navigation links
|
2
2
|
|
3
|
-
= Simple navigation (
|
3
|
+
= Simple navigation (HOW-TO)
|
4
4
|
|
5
5
|
=== Install
|
6
6
|
|
7
7
|
gem install navlinks --source http://gemcutter.org
|
8
8
|
|
9
|
-
|
10
9
|
=== First add navigation areas to the layout
|
11
10
|
|
12
11
|
==== app/views/layouts/application.html.erb
|
@@ -16,7 +15,7 @@
|
|
16
15
|
<body>
|
17
16
|
<ul id="nav">
|
18
17
|
<li><%= nav_link_to :home, root_path %></li>
|
19
|
-
<li><%= nav_link_to :foo,
|
18
|
+
<li><%= nav_link_to :foo, foo_path %></li>
|
20
19
|
</ul>
|
21
20
|
|
22
21
|
<div id="content">
|
@@ -25,9 +24,13 @@
|
|
25
24
|
</body>
|
26
25
|
</html>
|
27
26
|
|
28
|
-
=== Next, label
|
27
|
+
=== Next, label what views belong to what nav areas
|
28
|
+
|
29
|
+
Suppose we have following pages:
|
30
|
+
1. A home page that is rendered by +pages/home.html.erb+ template and that we want to belong to 'home' nav area.
|
31
|
+
2. 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.
|
29
32
|
|
30
|
-
|
33
|
+
Easy! Just assign the nav-areas at the top of the views like this:
|
31
34
|
|
32
35
|
==== app/views/pages/home.html.erb
|
33
36
|
<%- self.nav_area = :home -%>
|
@@ -38,6 +41,10 @@ Let's have the home page be part of 'home' area and showing a Foo resource part
|
|
38
41
|
|
39
42
|
=== Done!
|
40
43
|
|
44
|
+
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
|
45
|
+
+foos/show.html.erb+ template, then the 'foo' anchor tag will have a class +current+. When viewing any other page, however, both of the
|
46
|
+
navigation anchors will not have any classes.
|
47
|
+
|
41
48
|
= Localization
|
42
49
|
|
43
50
|
+navlinks+ supports common localization but also allows some tricks. Suppose the localization file is as follows:
|
@@ -48,7 +55,7 @@ Let's have the home page be part of 'home' area and showing a Foo resource part
|
|
48
55
|
home: Go home
|
49
56
|
home_current: At home
|
50
57
|
|
51
|
-
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?
|
58
|
+
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?
|
52
59
|
|
53
60
|
= Decoration Override
|
54
61
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/navlinks/helper.rb
CHANGED
@@ -3,18 +3,27 @@ module Navlinks
|
|
3
3
|
module Helper
|
4
4
|
attr_accessor :nav_area
|
5
5
|
|
6
|
-
def nav_link_to
|
6
|
+
def nav_link_to(area, path, options = nil)
|
7
|
+
link_to(nav_label_for(area), path, :class => (nav_current?(area) ? 'current' : nil))
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def nav_current?(area)
|
13
|
+
nav_area == area
|
14
|
+
end
|
15
|
+
|
16
|
+
def nav_label_for(area)
|
7
17
|
label = translate(area, :scope => 'navigation', :default => area.to_s)
|
8
|
-
current_label = translate([ area, 'current' ].join('_'), :scope => 'navigation', :default => label)
|
9
18
|
|
10
|
-
if
|
11
|
-
|
19
|
+
if nav_current?(area)
|
20
|
+
current_label = translate([ area, 'current' ].join('_'), :scope => 'navigation', :default => label)
|
21
|
+
decorate_current( current_label )
|
12
22
|
else
|
13
|
-
|
23
|
+
label
|
14
24
|
end
|
15
25
|
end
|
16
26
|
|
17
|
-
private
|
18
27
|
|
19
28
|
def decorate_current( current_label )
|
20
29
|
"[ #{current_label} ]"
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navlinks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Dmitry Ratnikov
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-07 00:00:00 -05:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -40,18 +45,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
45
|
requirements:
|
41
46
|
- - ">="
|
42
47
|
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
43
50
|
version: "0"
|
44
|
-
version:
|
45
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
52
|
requirements:
|
47
53
|
- - ">="
|
48
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
49
57
|
version: "0"
|
50
|
-
version:
|
51
58
|
requirements: []
|
52
59
|
|
53
60
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.3.
|
61
|
+
rubygems_version: 1.3.6
|
55
62
|
signing_key:
|
56
63
|
specification_version: 3
|
57
64
|
summary: Very light-weight navigation
|