nav 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +149 -0
- data/lib/nav/builder.rb +3 -3
- data/lib/nav/version.rb +1 -1
- metadata +11 -9
- data/README.rdoc +0 -74
data/README.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
Navigation made easy
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
System wide
|
5
|
+
|
6
|
+
```console
|
7
|
+
gem install nav
|
8
|
+
```
|
9
|
+
|
10
|
+
In your Gemfile
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'nav'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Nav is writte for ActionView::Base and can be used in your rails views like so:
|
19
|
+
|
20
|
+
```erb
|
21
|
+
<%= nav do |n| %>
|
22
|
+
<% n.action "Home", "/" %>
|
23
|
+
<% n.action "Login", login_url %>
|
24
|
+
<% end %>
|
25
|
+
```
|
26
|
+
|
27
|
+
When rendered, this generates the following:
|
28
|
+
|
29
|
+
```html
|
30
|
+
<ul>
|
31
|
+
<li class="first current first_current">
|
32
|
+
<a href="/">Home</a>
|
33
|
+
</li>
|
34
|
+
<li class="last after_current last_after_current">
|
35
|
+
<a href="/login">Login</a>
|
36
|
+
</li>
|
37
|
+
</ul>
|
38
|
+
```
|
39
|
+
|
40
|
+
It will determine the current page you are on and add the `current` class to the <li> element. Also,
|
41
|
+
the element before and after the current element have the classes `before_current` and `after_current`
|
42
|
+
Additionally, Nav will mark the first and last <li> element of the list as `first` and `last`. Like so,
|
43
|
+
you can apply styles accordingly.
|
44
|
+
|
45
|
+
### Adding attributes to the nav element
|
46
|
+
|
47
|
+
You can give any possible html option to nav, like id, classes, etc.
|
48
|
+
|
49
|
+
```erb
|
50
|
+
<%= nav :class => 'main' do |n| %>
|
51
|
+
...
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
|
55
|
+
Which results in
|
56
|
+
|
57
|
+
```html
|
58
|
+
<ul class='main'>
|
59
|
+
...
|
60
|
+
</ul>
|
61
|
+
```
|
62
|
+
|
63
|
+
### Adding attributes to an action
|
64
|
+
|
65
|
+
#### Disabling an action
|
66
|
+
|
67
|
+
You are able to add specific behaviour when defining an `action`. For instance, if you want to disable a specific
|
68
|
+
element, you may pass `disabled` to it. It will add a disabled class to the `li` element.
|
69
|
+
|
70
|
+
```erb
|
71
|
+
<%= nav do |n| %>
|
72
|
+
<% n.action "Disabled", "/", :disabled => true %>
|
73
|
+
<% end %>
|
74
|
+
```
|
75
|
+
|
76
|
+
#### Manually set the current action
|
77
|
+
|
78
|
+
In case want to define which of the elements is the current one. You can pass `current` as
|
79
|
+
option. This can be done in various ways.
|
80
|
+
|
81
|
+
##### Boolean
|
82
|
+
|
83
|
+
```erb
|
84
|
+
<%= nav do |n| %>
|
85
|
+
<% n.action "My special current", "/", :current => true %>
|
86
|
+
<% end %>
|
87
|
+
```
|
88
|
+
##### Regular Expression
|
89
|
+
|
90
|
+
Pass a regular expression to the :current: argument. For instance, the following
|
91
|
+
will mark any url as current that has "account", followed by a "/" and any type
|
92
|
+
of numeric value, like "account/1" or "user/account/123". However, "account/my" will
|
93
|
+
not match.
|
94
|
+
|
95
|
+
```erb
|
96
|
+
<%= nav do |n| %>
|
97
|
+
<% n.action "My special current", "/", :current => /account\/\d+/ %>
|
98
|
+
<% end %>
|
99
|
+
```
|
100
|
+
|
101
|
+
##### Proc
|
102
|
+
|
103
|
+
Pass a Proc in order to determine the current on the fly. Make sure that it returns
|
104
|
+
`true` or `false`.
|
105
|
+
|
106
|
+
```erb
|
107
|
+
<%= nav do |n| %>
|
108
|
+
<% n.action "My special current", "/", :current => Proc.new { !current_user.nil? } %>
|
109
|
+
<% end %>
|
110
|
+
```
|
111
|
+
## Custom actions
|
112
|
+
|
113
|
+
If you prefer to not use links for your navigation or simply want to customize your
|
114
|
+
navigation, you may do so by padding a block to the `action`.
|
115
|
+
|
116
|
+
You can use any rails view helpers or just good old plain html. The following
|
117
|
+
examples are equivalent:
|
118
|
+
|
119
|
+
```erb
|
120
|
+
<%= nav do |n| %>
|
121
|
+
<% n.action :class => 'customized' do %>
|
122
|
+
<span>Home</span>
|
123
|
+
<% end %>
|
124
|
+
<% end %>
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
```erb
|
129
|
+
<%= nav do |n| %>
|
130
|
+
<% n.action :class => 'customized' do %>
|
131
|
+
<%= content_tag :span, 'Home' %>
|
132
|
+
<% end %>
|
133
|
+
<% end %>
|
134
|
+
```
|
135
|
+
|
136
|
+
... and will result in:
|
137
|
+
|
138
|
+
```html
|
139
|
+
<ul>
|
140
|
+
<li class="last">
|
141
|
+
<span>Home</span>
|
142
|
+
</li>
|
143
|
+
</ul>
|
144
|
+
```
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
Copyright (c) 2011-2012 Rudolf Schmidt, released under the MIT license
|
149
|
+
|
data/lib/nav/builder.rb
CHANGED
@@ -19,9 +19,9 @@ module Nav
|
|
19
19
|
# action :current => true do
|
20
20
|
# content_tag :span, "A simple text""
|
21
21
|
# end
|
22
|
-
def action( name = nil, options = {}, html_options = {} )
|
23
|
-
@actions << if
|
24
|
-
[
|
22
|
+
def action( name = nil, options = {}, html_options = {}, &block )
|
23
|
+
@actions << if block
|
24
|
+
[ @template.capture(&block), name || {}, {} ]
|
25
25
|
else
|
26
26
|
wrapper_options = {
|
27
27
|
:current => html_options.delete(:current),
|
data/lib/nav/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70123352610920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70123352610920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rr
|
27
|
-
requirement: &
|
27
|
+
requirement: &70123352610360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70123352610360
|
36
36
|
description: Simple nagivation builder
|
37
37
|
email:
|
38
38
|
executables: []
|
@@ -42,7 +42,7 @@ files:
|
|
42
42
|
- .gitignore
|
43
43
|
- Gemfile
|
44
44
|
- LICENSE.txt
|
45
|
-
- README.
|
45
|
+
- README.md
|
46
46
|
- Rakefile
|
47
47
|
- lib/nav.rb
|
48
48
|
- lib/nav/builder.rb
|
@@ -70,8 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project: nav
|
73
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.17
|
74
74
|
signing_key:
|
75
75
|
specification_version: 3
|
76
76
|
summary: Simple nagivation builder
|
77
|
-
test_files:
|
77
|
+
test_files:
|
78
|
+
- test/nav_test.rb
|
79
|
+
- test/test_helper.rb
|
data/README.rdoc
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
= Nav
|
2
|
-
Navigation made easy
|
3
|
-
|
4
|
-
== Installation
|
5
|
-
# system wide
|
6
|
-
gem install nav
|
7
|
-
|
8
|
-
# in your Gemfile
|
9
|
-
gem 'nav'
|
10
|
-
|
11
|
-
== Usage
|
12
|
-
=== Basics
|
13
|
-
Nav is automatically available within ActionView::Base and can be used like so:
|
14
|
-
<%= nav do |n| %>
|
15
|
-
<% n.action "Home", "/" %>
|
16
|
-
<% n.action "Login", login_url %>
|
17
|
-
<% end %>
|
18
|
-
|
19
|
-
# When rendered, this generates the following:
|
20
|
-
<ul>
|
21
|
-
<li class="first current first_current">
|
22
|
-
<a href="/">Home</a>
|
23
|
-
</li>
|
24
|
-
<li class="last after_current last_after_current">
|
25
|
-
<a href="/login">Login</a>
|
26
|
-
</li>
|
27
|
-
</ul>
|
28
|
-
|
29
|
-
It will determine the current page you are on and add the :current: class to the <li> element. Also,
|
30
|
-
the element before and after the current element have the classes :before_current: and :after_current:.
|
31
|
-
Additionally, Nav will mark the first and last <li> element of the list as :first: and :last:. Like so,
|
32
|
-
you can apply styles accordingly.
|
33
|
-
|
34
|
-
=== Adding attributes to the nav element
|
35
|
-
You can give any possible html option to nav, like classes, etc.
|
36
|
-
<%= nav :class => 'main' do |n| %>
|
37
|
-
...
|
38
|
-
<% end %>
|
39
|
-
|
40
|
-
# results in
|
41
|
-
<ul class='main'>
|
42
|
-
...
|
43
|
-
</ul>
|
44
|
-
|
45
|
-
=== Adding attributes to an action
|
46
|
-
You are able to add specific behaviour when defining an :action. For instance, if you want to disable a specific
|
47
|
-
element, you may pass :disabled: to it:
|
48
|
-
<%= nav do |n| %>
|
49
|
-
<%= n.action "Disabled", "/", :disabled => true %>
|
50
|
-
<% end %>
|
51
|
-
|
52
|
-
This will add a "disabled" class to the <li> element.
|
53
|
-
|
54
|
-
Sometimes you may want to define yourself which of the elements is the current one. You can pass :current: as
|
55
|
-
option. This can be done in various ways.
|
56
|
-
# Pass true or false to the :current: argument
|
57
|
-
<%= nav do |n| %>
|
58
|
-
<% n.action "My special current", "/", :current => true %>
|
59
|
-
<% end %>
|
60
|
-
|
61
|
-
# Pass a regular expression to the :current: argument. For instance, the following will mark any url as current
|
62
|
-
# that has "account", followed by a "/" and any typee of numeric value:
|
63
|
-
<%= nav do |n| %>
|
64
|
-
<% n.action "My special current", "/", :current => /account\/\d+/ %>
|
65
|
-
<% end %>
|
66
|
-
|
67
|
-
# Lastly, you may also pass a proc:
|
68
|
-
<%= nav do |n| %>
|
69
|
-
<% n.action "My special current", "/", :current => Proc.new { !current_user.nil? } %>
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Copyright (c) 2011 Rudolf Schmidt, released under the MIT license
|