navigator 0.7.0 → 0.8.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: 4b3adc76b790bfd51e87dc0f635c96dbb87abd6e
4
- data.tar.gz: 5c3e6b2f5ab6fe64f60fcef476297495197ae575
3
+ metadata.gz: 50aeb1e3d4da2ff847558e659609b7c05eb9943b
4
+ data.tar.gz: a5d04fbcb4d629600980986a8c393fab5f7fbc18
5
5
  SHA512:
6
- metadata.gz: 10766903636733ee83d52ffe1934631336bdc7d3d72c7c6760c2f1c8bcc176f8e68f902e402f6c0b7b6d03899681a7c3ae9fef5a5fa269a0030926ae8ef11e3e
7
- data.tar.gz: 7cf5ef2567d2990cb6869d7f92363930f107229f38d61098575849e05423254c031ce7bed0de28ab606fc046b45f964fe8bf5a82f83ed8b5690ee926305884ac
6
+ metadata.gz: efb8decf8ffa561b31ea79bb521e5998dec794c7e409d9b6baac45283fd91b56a69dfe563176526ef1059c922543e1337f29fe1f2a655c2a94de0fac1c656a14
7
+ data.tar.gz: 62ae481797701da993c1fa1c9a656574c433e6f02c147e0aefe9ca2ea50b637048aaed266eb9db7fd869eb37ad721bc8d7006ac7efba0ddb88073c2595e4fe43
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -14,7 +14,7 @@ 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, ul, li, a, b, em, s, small, span, strong, sub, and sup.
17
+ * Supports the following HTML tags: nav, section, h1-h6, ul, li, a, b, em, s, small, span, strong, sub, and sup.
18
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
@@ -79,6 +79,22 @@ Result:
79
79
  <li><a href="/posts">Posts</a></li>
80
80
  </ul>
81
81
 
82
+ ## Unordered List (with multiple data attributes)
83
+
84
+ Code:
85
+
86
+ navigation do
87
+ item "Home", "/home", data: {id: 1, type: "public"}
88
+ end
89
+
90
+ Result:
91
+
92
+ <ul>
93
+ <li data-id="1" data-type="public"><a href="/home">Home</a></li>
94
+ </ul>
95
+
96
+ *TIP: Nested data-* attributes can be applied to any menu item in the same manner as Rails view helpers.*
97
+
82
98
  ## Nav (with links)
83
99
 
84
100
  Code:
@@ -99,17 +115,55 @@ Result:
99
115
 
100
116
  Code:
101
117
 
102
- navigation "ul", class: "left" do
103
- item "Home", root_path
104
- item "About", about_path
118
+ navigation "nav", class: "top-bar", "data-topbar" => nil do
119
+ ul nil, class: "title-area" do
120
+ li nil, class: "name" do
121
+ h1 do
122
+ a "Demo", href: "/home"
123
+ end
124
+ end
125
+ end
126
+
127
+ section nil, class: "top-bar-section" do
128
+ ul nil, class: "left" do
129
+ item "Home", "/"
130
+ item "About", "/about"
131
+ end
132
+
133
+ ul nil, class: "right" do
134
+ item "v1.0.0", '#'
135
+ end
136
+
137
+ ul nil, class: "right" do
138
+ item "Login", "/login", {}, {class: "button tiny round"}
139
+ end
140
+ end
105
141
  end
106
142
 
107
143
  Result:
108
144
 
109
- <ul class="ul" class: "left">
110
- <li class="active"><a href="/home">Home</a></li>
111
- <li><a href="/about">About</a></li>
112
- </ul>
145
+ <nav class="top-bar" data-topbar="">
146
+ <ul class="title-area">
147
+ <li class="name">
148
+ <h1><a href="/" class="active">Demo</a></h1>
149
+ </li>
150
+ </ul>
151
+
152
+ <section class="top-bar-section">
153
+ <ul class="left">
154
+ <li class="active"><a href="/">Home</a></li>
155
+ <li><a href="/about">About</a></li>
156
+ </ul>
157
+
158
+ <ul class="right">
159
+ <li><a href="#">v1.0.0</a></li>
160
+ </ul>
161
+
162
+ <ul class="right">
163
+ <li><a class="button tiny round" href="/login">Login</a></li>
164
+ </ul>
165
+ </section>
166
+ </nav>
113
167
 
114
168
  ## Bootstrap Dropdown
115
169
 
@@ -1,6 +1,10 @@
1
1
  module Navigator
2
2
  # Renders a HTML menu.
3
3
  class Menu
4
+ def self.allowed_methods
5
+ %r(^(section|h[1-6]|ul|li|a|b|em|s|small|span|strong|sub|sup)$)
6
+ end
7
+
4
8
  def initialize template, tag = "ul", attributes = {}, menu_activator = Navigator::TagActivator.new, &block
5
9
  @template = template
6
10
  @tag = Tag.new tag, nil, attributes, menu_activator
@@ -33,12 +37,15 @@ module Navigator
33
37
  end
34
38
  end
35
39
 
40
+ def respond_to? name
41
+ method_allowed?(name) || super(name)
42
+ end
43
+
36
44
  def method_missing name, *args, &block
37
- case name.to_s
38
- when %r(^(ul|li|a|b|em|s|small|span|strong|sub|sup)$)
39
- add(*args.unshift(name), &block)
40
- else
41
- template.public_send name, *args
45
+ if method_allowed?(name.to_s)
46
+ add(*args.unshift(name), &block)
47
+ else
48
+ template.public_send name, *args
42
49
  end
43
50
  end
44
51
 
@@ -49,5 +56,9 @@ module Navigator
49
56
  private
50
57
 
51
58
  attr_accessor :template, :tag, :menu_activator, :items
59
+
60
+ def method_allowed? name
61
+ self.class.allowed_methods === name
62
+ end
52
63
  end
53
64
  end
data/lib/navigator/tag.rb CHANGED
@@ -26,7 +26,15 @@ module Navigator
26
26
 
27
27
  attr_reader :attributes, :activator
28
28
 
29
+ def expand_data_attributes!
30
+ if attributes.key? :data
31
+ attributes[:data].each { |key, value| attributes["data-#{key}"] = value }
32
+ attributes.delete :data
33
+ end
34
+ end
35
+
29
36
  def formatted_attributes
37
+ expand_data_attributes!
30
38
  attrs = activator.activate(attributes).map { |key, value| %(#{key}="#{value}") } * ' '
31
39
  attrs.empty? ? nil : " #{attrs}"
32
40
  end
@@ -1,3 +1,3 @@
1
1
  module Navigator
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.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: 0.7.0
4
+ version: 0.8.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: 2014-07-06 00:00:00.000000000 Z
33
+ date: 2014-07-10 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: pry-byebug
metadata.gz.sig CHANGED
Binary file