navigator 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +84 -10
- data/lib/navigator/menu.rb +21 -8
- data/lib/navigator/tag.rb +11 -3
- data/lib/navigator/version.rb +1 -1
- metadata +3 -3
- 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: 074bdec84f357eca1409cc391a09c56e70d02d57
|
4
|
+
data.tar.gz: e055f6c5572472f7d057e172dbc27c8825a87e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90dcd0846caf6e502ca898cfd7b9501aa1fd025c2db749ce0c5df370d307a01d0a48d459b02a1e9161c71e4114f930e491faea183ee04cd29ac4fc44046b627a
|
7
|
+
data.tar.gz: 4f0d277cd2e7f69f42ca2b903d7261c421406d7fe3034904965e8f4a0961adc162f2c1414956ceca92b33c851e1bfaf38584badc32f0deeb02707b4b6d0d5b3d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -14,8 +14,31 @@ Enhances Rails with a DSL for menu navigation.
|
|
14
14
|
- Provides a simple DSL for building navigation menus.
|
15
15
|
- Supports auto-detection/highlighting of active menu items based on current path (customizable for non-path usage too).
|
16
16
|
- Supports sub-menus, nested tags, HTML attributes, etc.
|
17
|
-
- Supports the following HTML tags:
|
18
|
-
-
|
17
|
+
- Supports the following HTML tags:
|
18
|
+
- div
|
19
|
+
- section
|
20
|
+
- header
|
21
|
+
- h1 - h6
|
22
|
+
- nav
|
23
|
+
- ul
|
24
|
+
- li
|
25
|
+
- a
|
26
|
+
- img
|
27
|
+
- b
|
28
|
+
- em
|
29
|
+
- s
|
30
|
+
- small
|
31
|
+
- span
|
32
|
+
- strong
|
33
|
+
- sub
|
34
|
+
- sup
|
35
|
+
- form
|
36
|
+
- label
|
37
|
+
- select
|
38
|
+
- option
|
39
|
+
- input
|
40
|
+
- button
|
41
|
+
- Provides `link`, `image`, and `item` convenience methods for succinct ways to build commonly used menu elements.
|
19
42
|
|
20
43
|
# Requirements
|
21
44
|
|
@@ -197,15 +220,61 @@ Result:
|
|
197
220
|
</li>
|
198
221
|
</ul>
|
199
222
|
|
223
|
+
## Menu Helpers
|
224
|
+
|
225
|
+
There are several convenience methods, in addition to the standard HTML tags, that can make for shorter lines of code.
|
226
|
+
The following describes each:
|
227
|
+
|
228
|
+
When building links, the default is:
|
229
|
+
|
230
|
+
navigation "nav", activator: activator do
|
231
|
+
a "Home", attributes: {href: home_path}
|
232
|
+
end
|
233
|
+
|
234
|
+
...but can be written as:
|
235
|
+
|
236
|
+
navigation "nav", activator: activator do
|
237
|
+
link "Home", home_path
|
238
|
+
end
|
239
|
+
|
240
|
+
When building images, the default is:
|
241
|
+
|
242
|
+
navigation "nav", activator: activator do
|
243
|
+
img attributes: {src: "http://placehold.it/50x50", alt: "Example"}
|
244
|
+
end
|
245
|
+
|
246
|
+
...but can be written as:
|
247
|
+
|
248
|
+
navigation "nav", activator: activator do
|
249
|
+
image "http://placehold.it/50x50", "Example"
|
250
|
+
end
|
251
|
+
|
252
|
+
When building menu items, the default is:
|
253
|
+
|
254
|
+
navigation "nav", activator: activator do
|
255
|
+
li do
|
256
|
+
a "Home", attributes: {href: home_path}
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
...but can be written as:
|
261
|
+
|
262
|
+
navigation "nav", activator: activator do
|
263
|
+
item "Home", "/dashboard"
|
264
|
+
end
|
265
|
+
|
266
|
+
These are just a few, simple, examples of what can be achieved. See the specs for additional usage and customization.
|
267
|
+
|
200
268
|
# Customization
|
201
269
|
|
202
270
|
The `navigation` view helper can accept an optional `Navigator::TagActivator` instance. Example:
|
203
271
|
|
204
272
|
# Code
|
205
273
|
activator = Navigator::TagActivator.new search_value: request.env["PATH_INFO"]
|
274
|
+
|
206
275
|
navigation "nav", activator: activator do
|
207
|
-
|
208
|
-
|
276
|
+
link "Home", home_path
|
277
|
+
link "About", about_path
|
209
278
|
end
|
210
279
|
|
211
280
|
<!-- Result -->
|
@@ -237,8 +306,8 @@ This customization allows for more sophisticated detection/updating of active HT
|
|
237
306
|
target_value: "current"
|
238
307
|
|
239
308
|
navigation "nav", activator: activator do
|
240
|
-
|
241
|
-
|
309
|
+
link "Home", home_path, attributes: {data: {id: "123", data-style="info"}}
|
310
|
+
link "About", about_path attributes: {data: {id: "789"}}
|
242
311
|
end
|
243
312
|
|
244
313
|
<!-- Result -->
|
@@ -266,13 +335,14 @@ Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
|
|
266
335
|
- Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
|
267
336
|
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
268
337
|
|
269
|
-
#
|
338
|
+
# Code of Conduct
|
270
339
|
|
271
|
-
|
340
|
+
Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By participating in this project
|
341
|
+
you agree to abide by its terms.
|
272
342
|
|
273
|
-
#
|
343
|
+
# Contributions
|
274
344
|
|
275
|
-
|
345
|
+
Read [CONTRIBUTING](CONTRIBUTING.md) for details.
|
276
346
|
|
277
347
|
# License
|
278
348
|
|
@@ -283,3 +353,7 @@ Read the [LICENSE](LICENSE.md) for details.
|
|
283
353
|
|
284
354
|
Read the [CHANGELOG](CHANGELOG.md) for details.
|
285
355
|
Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
|
356
|
+
|
357
|
+
# Credits
|
358
|
+
|
359
|
+
Developed by [Brooke Kuhlmann](https://www.alchemists.io) at [Alchemists](https://www.alchemists.io).
|
data/lib/navigator/menu.rb
CHANGED
@@ -2,7 +2,7 @@ module Navigator
|
|
2
2
|
# Renders a HTML menu.
|
3
3
|
class Menu
|
4
4
|
def self.allowed_methods
|
5
|
-
%r(^(section|h[1-6]|ul|li|a|b|em|s|small|span|strong|sub|sup)$)
|
5
|
+
%r(^(div|section|header|h[1-6]|nav|ul|li|a|img|b|em|s|small|span|strong|sub|sup|form|label|select|option|input|button)$)
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize template, tag: "ul", attributes: {}, activator: Navigator::TagActivator.new, &block
|
@@ -25,15 +25,23 @@ module Navigator
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
28
|
+
def link content = nil, url, attributes: {}, activator: menu_activator, &block
|
29
|
+
add "a", content, attributes: attributes.merge(href: url), activator: activator, &block
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def image url, alt = nil, attributes: {}, activator: menu_activator
|
33
|
+
modified_attributes = attributes.merge src: url, alt: alt
|
34
|
+
modified_attributes = modified_attributes.delete_if { |_, value| !value.present? }
|
35
|
+
|
36
|
+
add "img", attributes: modified_attributes, activator: activator
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
39
|
+
def item content = nil, url, item_attributes: {}, link_attributes: {}, activator: menu_activator, &block
|
40
|
+
modified_item_attributes = item_attributes.clone
|
41
|
+
activate_item_attributes! modified_item_attributes, url, activator
|
42
|
+
|
43
|
+
add "li", attributes: modified_item_attributes, activator: activator do
|
44
|
+
link content, url, attributes: link_attributes, activator: Navigator::TagActivator.new, &block
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
@@ -60,5 +68,10 @@ module Navigator
|
|
60
68
|
def method_allowed? name
|
61
69
|
self.class.allowed_methods === name
|
62
70
|
end
|
71
|
+
|
72
|
+
def activate_item_attributes! attributes, url, activator
|
73
|
+
return unless url == activator.search_value
|
74
|
+
attributes[activator.target_key] = [attributes[activator.target_key], activator.target_value].compact * ' '
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
data/lib/navigator/tag.rb
CHANGED
@@ -3,8 +3,12 @@ module Navigator
|
|
3
3
|
class Tag
|
4
4
|
attr_reader :name, :content
|
5
5
|
|
6
|
+
def self.names_without_suffix
|
7
|
+
%w(img input)
|
8
|
+
end
|
9
|
+
|
6
10
|
def initialize name, content = nil, attributes: {}, activator: Navigator::TagActivator.new
|
7
|
-
@name = name
|
11
|
+
@name = String(name)
|
8
12
|
@content = content
|
9
13
|
@attributes = attributes.with_indifferent_access
|
10
14
|
@activator = activator
|
@@ -14,12 +18,16 @@ module Navigator
|
|
14
18
|
["<#{name}", format_attributes, '>'].compact * ''
|
15
19
|
end
|
16
20
|
|
21
|
+
def computed_content
|
22
|
+
self.class.names_without_suffix.include?(name) ? nil : content
|
23
|
+
end
|
24
|
+
|
17
25
|
def suffix
|
18
|
-
"</#{name}>"
|
26
|
+
self.class.names_without_suffix.include?(name) ? nil : "</#{name}>"
|
19
27
|
end
|
20
28
|
|
21
29
|
def render
|
22
|
-
[prefix,
|
30
|
+
[prefix, computed_content, suffix].compact * ''
|
23
31
|
end
|
24
32
|
|
25
33
|
private
|
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: 1.
|
4
|
+
version: 1.1.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: 2015-
|
33
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: pry-byebug
|
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
267
|
version: '0'
|
268
268
|
requirements: []
|
269
269
|
rubyforge_project:
|
270
|
-
rubygems_version: 2.4.
|
270
|
+
rubygems_version: 2.4.6
|
271
271
|
signing_key:
|
272
272
|
specification_version: 4
|
273
273
|
summary: Enhances Rails with a DSL for menu navigation.
|
metadata.gz.sig
CHANGED
Binary file
|