navigator 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE.md +1 -1
- data/README.md +43 -45
- data/app/helpers/navigator/navigation_helper.rb +2 -2
- data/lib/navigator/menu.rb +9 -9
- data/lib/navigator/tag.rb +1 -1
- data/lib/navigator/tag_activator.rb +6 -24
- data/lib/navigator/version.rb +1 -1
- metadata +33 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a40ffa146eec750cb69650d516300c6aa7e77388
|
4
|
+
data.tar.gz: d3022dd4a03f044859b88d1f6fe47d1007faa2f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bf010f6da84cbb4da2cce6db6c5671f106a782b70e321a2e107654cd6533ceb2456d4a3db5708eea072c9592855d2b98ded0844df24c3de603214c33ec99cd
|
7
|
+
data.tar.gz: 085e7c6c6e4768d453206e8666af056d8e345b83934dc9c0dbebdc732e7978c92d935b5771ec3d5984dfc73e95b46b5a2dabb6a64cbe6e393af7772d4895001a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -11,25 +11,24 @@ Enhances Rails with a DSL for menu navigation.
|
|
11
11
|
|
12
12
|
# Features
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
- Provides a simple DSL for building navigation menus.
|
15
|
+
- Supports auto-detection/highlighting of active menu items based on current path (customizable for non-path usage too).
|
16
|
+
- Supports sub-menus, nested tags, HTML attributes, etc.
|
17
|
+
- Supports the following HTML tags: nav, section, h1-h6, ul, li, a, b, em, s, small, span, strong, sub, and sup.
|
18
|
+
- Provides an "item" convenience method which combines the "li" and "a" HTML tags into a single method for less typing.
|
19
19
|
|
20
20
|
# Requirements
|
21
21
|
|
22
22
|
0. Any of the following Ruby VMs:
|
23
|
-
|
24
|
-
|
25
|
-
* [Rubinius 2.x.x](http://rubini.us)
|
23
|
+
- [MRI 2.x.x](http://www.ruby-lang.org)
|
24
|
+
- [JRuby 1.x.x](http://jruby.org)
|
26
25
|
0. [Ruby on Rails 4.1.x](http://rubyonrails.org).
|
27
26
|
|
28
27
|
# Setup
|
29
28
|
|
30
29
|
For a secure install, type the following from the command line (recommended):
|
31
30
|
|
32
|
-
gem cert --add <(curl -Ls
|
31
|
+
gem cert --add <(curl -Ls https://www.alchemists.io/gem-public.pem)
|
33
32
|
gem install navigator --trust-policy MediumSecurity
|
34
33
|
|
35
34
|
NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while
|
@@ -67,8 +66,8 @@ Result:
|
|
67
66
|
|
68
67
|
Code:
|
69
68
|
|
70
|
-
navigation "ul", class: "nav" do
|
71
|
-
item "Dashboard", "/dashboard", class: "active"
|
69
|
+
navigation "ul", attributes: {class: "nav"} do
|
70
|
+
item "Dashboard", "/dashboard", item_attributes: {class: "active"}
|
72
71
|
item "News", "/posts"
|
73
72
|
end
|
74
73
|
|
@@ -84,7 +83,7 @@ Result:
|
|
84
83
|
Code:
|
85
84
|
|
86
85
|
navigation do
|
87
|
-
item "Home", "/home", data: {id: 1, type: "public"}
|
86
|
+
item "Home", "/home", item_attributes: {data: {id: 1, type: "public"}}
|
88
87
|
end
|
89
88
|
|
90
89
|
Result:
|
@@ -93,15 +92,15 @@ Result:
|
|
93
92
|
<li data-id="1" data-type="public"><a href="/home">Home</a></li>
|
94
93
|
</ul>
|
95
94
|
|
96
|
-
*TIP: Nested data
|
95
|
+
*TIP: Nested data-- attributes can be applied to any menu item in the same manner as Rails view helpers.*
|
97
96
|
|
98
97
|
## Nav (with links)
|
99
98
|
|
100
99
|
Code:
|
101
100
|
|
102
101
|
navigation "nav" do
|
103
|
-
a "Dashboard", href: "/dashboard"
|
104
|
-
a "News", href: "/posts"
|
102
|
+
a "Dashboard", attributes: {href: "/dashboard"}
|
103
|
+
a "News", attributes: {href: "/posts"}
|
105
104
|
end
|
106
105
|
|
107
106
|
Result:
|
@@ -115,27 +114,27 @@ Result:
|
|
115
114
|
|
116
115
|
Code:
|
117
116
|
|
118
|
-
navigation "nav", class: "top-bar", "data-topbar" => nil do
|
119
|
-
ul
|
120
|
-
li
|
117
|
+
navigation "nav", attributes: {class: "top-bar", "data-topbar" => nil} do
|
118
|
+
ul attributes: {class: "title-area"} do
|
119
|
+
li attributes: {class: "name"} do
|
121
120
|
h1 do
|
122
|
-
a "Demo", href: "/home"
|
121
|
+
a "Demo", attributes: {href: "/home"}
|
123
122
|
end
|
124
123
|
end
|
125
124
|
end
|
126
125
|
|
127
|
-
section
|
128
|
-
ul
|
126
|
+
section attributes: {class: "top-bar-section"} do
|
127
|
+
ul attributes: {class: "left"} do
|
129
128
|
item "Home", "/"
|
130
129
|
item "About", "/about"
|
131
130
|
end
|
132
131
|
|
133
|
-
ul
|
132
|
+
ul attributes: {class: "right"} do
|
134
133
|
item "v1.0.0", '#'
|
135
134
|
end
|
136
135
|
|
137
|
-
ul
|
138
|
-
item "Login", "/login",
|
136
|
+
ul attributes: {class: "right"} do
|
137
|
+
item "Login", "/login", link_attributes: {class: "button tiny round"}
|
139
138
|
end
|
140
139
|
end
|
141
140
|
end
|
@@ -171,11 +170,11 @@ Code:
|
|
171
170
|
|
172
171
|
navigation "nav" do
|
173
172
|
item "Dashboard", admin_dashboard_path
|
174
|
-
li
|
175
|
-
a "Manage", href: "#", class: "dropdown-toggle", "data-toggle" => "dropdown" do
|
176
|
-
b
|
173
|
+
li attributes: {class: "dropdown"} do
|
174
|
+
a "Manage", attributes: {href: "#", class: "dropdown-toggle", "data-toggle" => "dropdown"} do
|
175
|
+
b attributes: {class: "caret"}
|
177
176
|
end
|
178
|
-
ul
|
177
|
+
ul attributes: {class: "dropdown-menu"} do
|
179
178
|
item "Dashboard", admin_dashboard_path
|
180
179
|
item "Users", admin_users_path
|
181
180
|
end
|
@@ -204,9 +203,9 @@ The `navigation` view helper can accept an optional `Navigator::TagActivator` in
|
|
204
203
|
|
205
204
|
# Code
|
206
205
|
activator = Navigator::TagActivator.new search_value: request.env["PATH_INFO"]
|
207
|
-
navigation "nav",
|
208
|
-
a "Home", href: home_path
|
209
|
-
a "About", href: about_path
|
206
|
+
navigation "nav", activator: activator do
|
207
|
+
a "Home", attributes: {href: home_path}
|
208
|
+
a "About", attributes: {href: about_path}
|
210
209
|
end
|
211
210
|
|
212
211
|
<!-- Result -->
|
@@ -220,13 +219,12 @@ item URL (in this case "/home") matches the `request.env[“PATH_INFO"]` to indi
|
|
220
219
|
|
221
220
|
`Navigator::TagActivator` instances can be configured as follows:
|
222
221
|
|
223
|
-
|
224
|
-
|
222
|
+
- search_key = Optional. The HTML tag attribute to search for. Default: :href.
|
223
|
+
- search_value = Required. The value to match against the search_key value in order to update the value of the
|
225
224
|
target_key. Default: nil.
|
226
|
-
|
227
|
-
Default:
|
228
|
-
|
229
|
-
* target_value = Optional. The value to be applied to the target_key value. If no value exists, then the value is added.
|
225
|
+
- target_key = Optional. The HTML tag attribute key value to update when the search_value and search_key value match.
|
226
|
+
Default: :class.
|
227
|
+
- target_value = Optional. The value to be applied to the target_key value. If no value exists, then the value is added.
|
230
228
|
Otherwise, if a value exists then the value is appended to the existing value. Default: "active".
|
231
229
|
|
232
230
|
This customization allows for more sophisticated detection/updating of active HTML tags. For example, the example code
|
@@ -238,9 +236,9 @@ This customization allows for more sophisticated detection/updating of active HT
|
|
238
236
|
target_key: "data-style"
|
239
237
|
target_value: "current"
|
240
238
|
|
241
|
-
navigation "nav",
|
242
|
-
a "Home", href: home_path, "data-id" => "123", data-style="info"
|
243
|
-
a "About", href: about_path, "data-id" => "789"
|
239
|
+
navigation "nav", activator: activator do
|
240
|
+
a "Home", attributes: {href: home_path, "data-id" => "123", data-style="info"}
|
241
|
+
a "About", attributes: {href: about_path, "data-id" => "789"}
|
244
242
|
end
|
245
243
|
|
246
244
|
<!-- Result -->
|
@@ -264,9 +262,9 @@ To test the dummy application, run:
|
|
264
262
|
|
265
263
|
Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
|
266
264
|
|
267
|
-
|
268
|
-
|
269
|
-
|
265
|
+
- Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
|
266
|
+
- Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
|
267
|
+
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
270
268
|
|
271
269
|
# Contributions
|
272
270
|
|
@@ -274,11 +272,11 @@ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
|
|
274
272
|
|
275
273
|
# Credits
|
276
274
|
|
277
|
-
Developed by [Brooke Kuhlmann](
|
275
|
+
Developed by [Brooke Kuhlmann](https://www.alchemists.io) at [Alchemists](https://www.alchemists.io)
|
278
276
|
|
279
277
|
# License
|
280
278
|
|
281
|
-
Copyright (c) 2012 [Alchemists](
|
279
|
+
Copyright (c) 2012 [Alchemists](https://www.alchemists.io).
|
282
280
|
Read the [LICENSE](LICENSE.md) for details.
|
283
281
|
|
284
282
|
# History
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Navigator
|
2
2
|
module NavigationHelper
|
3
|
-
def navigation tag = "ul", attributes
|
4
|
-
raw Navigator::Menu.new(self, tag, attributes, activator, &block).render
|
3
|
+
def navigation tag = "ul", attributes: {}, activator: navigation_activator, &block
|
4
|
+
raw Navigator::Menu.new(self, tag: tag, attributes: attributes, activator: activator, &block).render
|
5
5
|
end
|
6
6
|
|
7
7
|
module_function
|
data/lib/navigator/menu.rb
CHANGED
@@ -5,16 +5,16 @@ module Navigator
|
|
5
5
|
%r(^(section|h[1-6]|ul|li|a|b|em|s|small|span|strong|sub|sup)$)
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize template, tag
|
8
|
+
def initialize template, tag: "ul", attributes: {}, activator: Navigator::TagActivator.new, &block
|
9
9
|
@template = template
|
10
|
-
@tag = Navigator::Tag.new tag,
|
11
|
-
@menu_activator =
|
10
|
+
@tag = Navigator::Tag.new tag, attributes: attributes, activator: activator
|
11
|
+
@menu_activator = activator
|
12
12
|
@items = []
|
13
13
|
instance_eval(&block) if block_given?
|
14
14
|
end
|
15
15
|
|
16
|
-
def add name, content = nil, attributes
|
17
|
-
tag = Navigator::Tag.new name, content, attributes, activator
|
16
|
+
def add name, content = nil, attributes: {}, activator: menu_activator, &block
|
17
|
+
tag = Navigator::Tag.new name, content, attributes: attributes, activator: activator
|
18
18
|
if block_given?
|
19
19
|
items << tag.prefix
|
20
20
|
items << tag.content
|
@@ -25,15 +25,15 @@ module Navigator
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def item content, url, item_attributes
|
28
|
+
def item content, url, item_attributes: {}, link_attributes: {}, activator: menu_activator
|
29
29
|
link_attributes.reverse_merge! href: url
|
30
30
|
|
31
31
|
if link_attributes[:href] == activator.search_value
|
32
32
|
item_attributes[activator.target_key] = activator.target_value
|
33
33
|
end
|
34
34
|
|
35
|
-
add "li",
|
36
|
-
add "a", content, link_attributes, Navigator::TagActivator.new
|
35
|
+
add "li", attributes: item_attributes, activator: activator do
|
36
|
+
add "a", content, attributes: link_attributes, activator: Navigator::TagActivator.new
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,7 +43,7 @@ module Navigator
|
|
43
43
|
|
44
44
|
def method_missing name, *args, &block
|
45
45
|
if method_allowed?(name.to_s)
|
46
|
-
add(*args
|
46
|
+
add(name, *args, &block)
|
47
47
|
else
|
48
48
|
template.public_send name, *args
|
49
49
|
end
|
data/lib/navigator/tag.rb
CHANGED
@@ -3,7 +3,7 @@ module Navigator
|
|
3
3
|
class Tag
|
4
4
|
attr_reader :name, :content
|
5
5
|
|
6
|
-
def initialize name, content = nil, attributes
|
6
|
+
def initialize name, content = nil, attributes: {}, activator: Navigator::TagActivator.new
|
7
7
|
@name = name
|
8
8
|
@content = content
|
9
9
|
@attributes = attributes.with_indifferent_access
|
@@ -1,27 +1,13 @@
|
|
1
1
|
module Navigator
|
2
2
|
# Conditionally activates a tag.
|
3
3
|
class TagActivator
|
4
|
-
|
5
|
-
@settings = settings.with_indifferent_access.reverse_merge search_key: :href,
|
6
|
-
search_value: nil,
|
7
|
-
target_key: :class,
|
8
|
-
target_value: "active"
|
9
|
-
end
|
10
|
-
|
11
|
-
def search_key
|
12
|
-
settings.fetch :search_key
|
13
|
-
end
|
14
|
-
|
15
|
-
def search_value
|
16
|
-
settings.fetch :search_value
|
17
|
-
end
|
4
|
+
attr_reader :search_key, :search_value, :target_key, :target_value
|
18
5
|
|
19
|
-
def target_key
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
settings.fetch :target_value
|
6
|
+
def initialize search_key: :href, search_value: nil, target_key: :class, target_value: "active"
|
7
|
+
@search_key = search_key
|
8
|
+
@search_value = search_value
|
9
|
+
@target_key = target_key
|
10
|
+
@target_value = target_value
|
25
11
|
end
|
26
12
|
|
27
13
|
def activatable? attributes = {}
|
@@ -38,9 +24,5 @@ module Navigator
|
|
38
24
|
|
39
25
|
attributes
|
40
26
|
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
attr_reader :settings
|
45
27
|
end
|
46
28
|
end
|
data/lib/navigator/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navigator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
fMlZDUGx3lQarp/vPjK+6XH7DLXjBEKqeIGBIpLthYUvDxJRp23C+T3liGSL32vg
|
31
31
|
mSpxxwmK95GDFuEy2mNPaxnazdkw8c+7DbrSpzd/CnNZkRgitxOavs8=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
33
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: pry-byebug
|
@@ -186,6 +186,34 @@ dependencies:
|
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '0'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: terminal-notifier
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
- !ruby/object:Gem::Dependency
|
204
|
+
name: terminal-notifier-guard
|
205
|
+
requirement: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
type: :development
|
211
|
+
prerelease: false
|
212
|
+
version_requirements: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
189
217
|
- !ruby/object:Gem::Dependency
|
190
218
|
name: codeclimate-test-reporter
|
191
219
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,7 +230,8 @@ dependencies:
|
|
202
230
|
version: '0'
|
203
231
|
description: Enhances Rails with a DSL for menu navigation complete with sub-menus,
|
204
232
|
nested tags, HTML attributes, etc.
|
205
|
-
email:
|
233
|
+
email:
|
234
|
+
- brooke@alchemists.io
|
206
235
|
executables: []
|
207
236
|
extensions: []
|
208
237
|
extra_rdoc_files:
|
@@ -238,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
267
|
version: '0'
|
239
268
|
requirements: []
|
240
269
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.
|
270
|
+
rubygems_version: 2.4.5
|
242
271
|
signing_key:
|
243
272
|
specification_version: 4
|
244
273
|
summary: Enhances Rails with a DSL for menu navigation.
|
metadata.gz.sig
CHANGED
Binary file
|