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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a40ffa146eec750cb69650d516300c6aa7e77388
4
- data.tar.gz: d3022dd4a03f044859b88d1f6fe47d1007faa2f7
3
+ metadata.gz: 074bdec84f357eca1409cc391a09c56e70d02d57
4
+ data.tar.gz: e055f6c5572472f7d057e172dbc27c8825a87e48
5
5
  SHA512:
6
- metadata.gz: 50bf010f6da84cbb4da2cce6db6c5671f106a782b70e321a2e107654cd6533ceb2456d4a3db5708eea072c9592855d2b98ded0844df24c3de603214c33ec99cd
7
- data.tar.gz: 085e7c6c6e4768d453206e8666af056d8e345b83934dc9c0dbebdc732e7978c92d935b5771ec3d5984dfc73e95b46b5a2dabb6a64cbe6e393af7772d4895001a
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: 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.
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
- a "Home", attributes: {href: home_path}
208
- a "About", attributes: {href: about_path}
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
- a "Home", attributes: {href: home_path, "data-id" => "123", data-style="info"}
241
- a "About", attributes: {href: about_path, "data-id" => "789"}
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
- # Contributions
338
+ # Code of Conduct
270
339
 
271
- Read [CONTRIBUTING](CONTRIBUTING.md) for details.
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
- # Credits
343
+ # Contributions
274
344
 
275
- Developed by [Brooke Kuhlmann](https://www.alchemists.io) at [Alchemists](https://www.alchemists.io)
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).
@@ -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 item content, url, item_attributes: {}, link_attributes: {}, activator: menu_activator
29
- link_attributes.reverse_merge! href: url
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
- if link_attributes[:href] == activator.search_value
32
- item_attributes[activator.target_key] = activator.target_value
33
- end
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
- add "li", attributes: item_attributes, activator: activator do
36
- add "a", content, attributes: link_attributes, activator: Navigator::TagActivator.new
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, content, suffix].compact * ''
30
+ [prefix, computed_content, suffix].compact * ''
23
31
  end
24
32
 
25
33
  private
@@ -1,3 +1,3 @@
1
1
  module Navigator
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
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-01-01 00:00:00.000000000 Z
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.5
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