semantic_navigation 0.1.4 → 0.1.5
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 +8 -8
- data/TODO +0 -1
- data/lib/semantic_navigation/core/mix_in/dsl_methods.rb +95 -0
- data/lib/semantic_navigation/core/navigation.rb +4 -80
- data/lib/semantic_navigation/core/node.rb +5 -2
- data/lib/semantic_navigation/core.rb +1 -0
- data/lib/semantic_navigation/version.rb +1 -1
- data/spec/lib/semantic_navigation/core/navigation_spec.rb +76 -27
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTJlZmViMTQyN2MwYzdkOWEzNGM3MjI3NzdhYjdmNDMxZTQ3YzI1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTYzMGYzYzVjZTJhNjg5YzQ4NzMyMDE4YTZhODJhYzkyNGY4MjVjYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjIzODE1YzM1YWQ5OTlhYjA1Njk3NGMyOTc4ZWYxNzU3NDQ0ZTg4OTMyMWJk
|
10
|
+
NTgzZTNjMmM3Mjk5Zjk1YmQ2YjM3OWM0MmVlOTM3MDQ5YjlhZGI5NTc1Nzgx
|
11
|
+
YmFkN2EyNDUxYTExZGNjNDk3ZGY1MTllZWJhZWI2MzczMjZkYWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Zjk0YTU4YzQyYTExNDU1Mjg5ZjZiYTdmZTliOGI4OTZiMjBmZjEwODQwODc0
|
14
|
+
NTFkOTM2OWYyNTUxZWI5Y2VlMTZmYjljOTRkYzMyZjRlNzY1Y2I3NmIyNzdj
|
15
|
+
OWU4NjcxZDAxMzcyYzNlNmIwYzgxNzk0YjFkZWMyZThlMTYxNzQ=
|
data/TODO
CHANGED
@@ -9,7 +9,6 @@ Concept:
|
|
9
9
|
- Move bootstrap renderers to bootstrap version 4.0.0
|
10
10
|
- Possible to make dynamic items in menu (database or something else)
|
11
11
|
- Pattern routes, can accept Proc
|
12
|
-
- scope can set default url params
|
13
12
|
- active_if method, can accept Proc
|
14
13
|
- add possibility for routes like {controller: 'some_controller', actions: ['index', 'new', 'create']}, or
|
15
14
|
"some_controller#(index|new|create)"
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Core
|
3
|
+
module MixIn
|
4
|
+
module DslMethods
|
5
|
+
|
6
|
+
def item(id, url=nil, options={}, &block)
|
7
|
+
options[:id] = id.to_sym
|
8
|
+
options[:render_if] ||= @scope_options[:render_if]
|
9
|
+
|
10
|
+
if url.is_a?(Array)
|
11
|
+
options[:url] = [url].flatten(1).map{|url| scope_url_params(decode_url(url))}
|
12
|
+
else
|
13
|
+
options[:url] = scope_url_params(decode_url(url))
|
14
|
+
end
|
15
|
+
|
16
|
+
options[:i18n_name] = @i18n_name
|
17
|
+
|
18
|
+
if block_given?
|
19
|
+
element = Node.new(options, @level+1)
|
20
|
+
element.instance_eval &block
|
21
|
+
else
|
22
|
+
element = Leaf.new(options, @level+1)
|
23
|
+
#Deprecation warning message
|
24
|
+
#TODO:Should be deleted after moving the header and divider definition via item
|
25
|
+
if element.url.nil? && !element.name.empty?
|
26
|
+
SemanticNavigation.deprecation_message(:method,
|
27
|
+
'item',
|
28
|
+
'header',
|
29
|
+
'header definition')
|
30
|
+
elsif element.url.nil? && element.name.empty?
|
31
|
+
SemanticNavigation.deprecation_message(:method,
|
32
|
+
'item',
|
33
|
+
'header',
|
34
|
+
'divider definition')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@sub_elements.push element
|
39
|
+
end
|
40
|
+
|
41
|
+
def header(id, options={})
|
42
|
+
options[:id] = id.to_sym
|
43
|
+
options[:render_if] ||= @scope_options[:render_if]
|
44
|
+
options[:url] = nil
|
45
|
+
options[:i18n_name] = @i18n_name
|
46
|
+
@sub_elements.push Leaf.new(options, @level+1)
|
47
|
+
end
|
48
|
+
|
49
|
+
def divider(options = {})
|
50
|
+
options[:id] = :divider
|
51
|
+
options[:render_if] ||= @scope_options[:render_if]
|
52
|
+
options[:url] = nil
|
53
|
+
options[:i18n_name] = nil
|
54
|
+
options[:name] = nil
|
55
|
+
@sub_elements.push Leaf.new(options, @level+1)
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(m,*args,&block)
|
59
|
+
if m.to_s.match(/^[_]+$/).to_a.size > 0
|
60
|
+
divider
|
61
|
+
else
|
62
|
+
super(m,args,&block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def scope(options = {}, &block)
|
67
|
+
@scope_options = options
|
68
|
+
self.instance_eval &block
|
69
|
+
@scope_options = {}
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def scope_url_params(url)
|
75
|
+
if url.is_a? Hash
|
76
|
+
(@scope_options[:url] || {}).merge(url)
|
77
|
+
else
|
78
|
+
url
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def decode_url(url)
|
83
|
+
if url.is_a? String
|
84
|
+
controller_name, action_name = url.split('#')
|
85
|
+
if controller_name && action_name
|
86
|
+
decoded_url = {:controller => controller_name, :action => action_name}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
decoded_url || url
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,78 +1,14 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
module Core
|
3
3
|
class Navigation < Base
|
4
|
+
include MixIn::DslMethods
|
5
|
+
|
4
6
|
attr_accessor :sub_elements
|
5
7
|
|
6
|
-
def initialize(options
|
8
|
+
def initialize(options)
|
7
9
|
@sub_elements = []
|
8
10
|
@scope_options = {}
|
9
|
-
super options,
|
10
|
-
end
|
11
|
-
|
12
|
-
def item(id, url=nil, options={}, &block)
|
13
|
-
options[:id] = id.to_sym
|
14
|
-
options[:render_if] ||= @scope_options[:render_if]
|
15
|
-
|
16
|
-
if url.is_a?(Array)
|
17
|
-
options[:url] = [url].flatten(1).map{|url| decode_url(url)}
|
18
|
-
else
|
19
|
-
options[:url] = decode_url(url)
|
20
|
-
end
|
21
|
-
|
22
|
-
options[:i18n_name] = @i18n_name
|
23
|
-
|
24
|
-
if block_given?
|
25
|
-
element = Node.new(options, @level+1)
|
26
|
-
element.instance_eval &block
|
27
|
-
else
|
28
|
-
element = Leaf.new(options, @level+1)
|
29
|
-
#Deprecation warning message
|
30
|
-
#TODO:Should be deleted after moving the header and divider definition via item
|
31
|
-
if element.url.nil? && !element.name.empty?
|
32
|
-
SemanticNavigation.deprecation_message(:method,
|
33
|
-
'item',
|
34
|
-
'header',
|
35
|
-
'header definition')
|
36
|
-
elsif element.url.nil? && element.name.empty?
|
37
|
-
SemanticNavigation.deprecation_message(:method,
|
38
|
-
'item',
|
39
|
-
'header',
|
40
|
-
'divider definition')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
@sub_elements.push element
|
45
|
-
end
|
46
|
-
|
47
|
-
def header(id, options={})
|
48
|
-
options[:id] = id.to_sym
|
49
|
-
options[:render_if] ||= @scope_options[:render_if]
|
50
|
-
options[:url] = nil
|
51
|
-
options[:i18n_name] = @i18n_name
|
52
|
-
@sub_elements.push Leaf.new(options, @level+1)
|
53
|
-
end
|
54
|
-
|
55
|
-
def divider(options = {})
|
56
|
-
options[:id] = :divider
|
57
|
-
options[:render_if] ||= @scope_options[:render_if]
|
58
|
-
options[:url] = nil
|
59
|
-
options[:i18n_name] = nil
|
60
|
-
options[:name] = nil
|
61
|
-
@sub_elements.push Leaf.new(options, @level+1)
|
62
|
-
end
|
63
|
-
|
64
|
-
def method_missing(m,*args,&block)
|
65
|
-
if m.to_s.match(/^[_]+$/).to_a.size > 0
|
66
|
-
divider
|
67
|
-
else
|
68
|
-
super(m,args,&block)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def scope(options = {}, &block)
|
73
|
-
@scope_options = options
|
74
|
-
self.instance_eval &block
|
75
|
-
@scope_options = {}
|
11
|
+
super options, 0
|
76
12
|
end
|
77
13
|
|
78
14
|
def mark_active
|
@@ -82,18 +18,6 @@ module SemanticNavigation
|
|
82
18
|
@active = !@sub_elements.find{|element| element.active}.nil?
|
83
19
|
end
|
84
20
|
|
85
|
-
private
|
86
|
-
|
87
|
-
def decode_url(url)
|
88
|
-
if url.is_a? String
|
89
|
-
controller_name, action_name = url.split('#')
|
90
|
-
if controller_name && action_name
|
91
|
-
decoded_url = {:controller => controller_name, :action => action_name}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
decoded_url || url
|
95
|
-
end
|
96
|
-
|
97
21
|
end
|
98
22
|
end
|
99
23
|
end
|
@@ -1,16 +1,19 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
module Core
|
3
|
-
class Node <
|
3
|
+
class Node < Base
|
4
4
|
include MixIn::UrlMethods
|
5
5
|
include MixIn::NameMethods
|
6
|
+
include MixIn::DslMethods
|
6
7
|
|
7
8
|
attr_accessor :link_classes, :node_classes,
|
8
|
-
:link_html, :node_html
|
9
|
+
:link_html, :node_html, :sub_elements
|
9
10
|
|
10
11
|
def initialize(options, level)
|
11
12
|
@url = []
|
12
13
|
@link_html = {}
|
13
14
|
@node_html = {}
|
15
|
+
@scope_options = {}
|
16
|
+
@sub_elements = []
|
14
17
|
super options, level
|
15
18
|
end
|
16
19
|
|
@@ -221,7 +221,7 @@ describe SemanticNavigation::Core::Navigation do
|
|
221
221
|
|
222
222
|
end
|
223
223
|
|
224
|
-
describe "#
|
224
|
+
describe "#scope" do
|
225
225
|
before :each do
|
226
226
|
@navigation = SemanticNavigation::Core::Navigation.new({})
|
227
227
|
|
@@ -238,43 +238,92 @@ describe SemanticNavigation::Core::Navigation do
|
|
238
238
|
@navigation.sub_elements.size.should == 2
|
239
239
|
end
|
240
240
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
241
|
+
describe ':url' do
|
242
|
+
it 'scopes hashed url' do
|
243
|
+
@navigation.scope url: {controller: 'common_controller'} do
|
244
|
+
item :first_item, {action: 'first_action'}
|
245
|
+
item :second_item, {action: 'second_item'}
|
246
|
+
end
|
247
|
+
|
248
|
+
@navigation.sub_elements[0..1].each do |element|
|
249
|
+
url = element.instance_variable_get(:"@url")
|
250
|
+
url[:controller].should == 'common_controller'
|
251
|
+
end
|
246
252
|
end
|
247
253
|
|
248
|
-
|
249
|
-
|
254
|
+
it 'scopes route like urls' do
|
255
|
+
@navigation.scope url: {some_attr: 'some_attr'} do
|
256
|
+
item :first_item, "controller1#action"
|
257
|
+
item :second_item, "controller2#action"
|
258
|
+
end
|
259
|
+
|
260
|
+
url1 = @navigation.sub_elements[0].instance_variable_get(:"@url")
|
261
|
+
url1.should == {controller: 'controller1', action: 'action', some_attr: 'some_attr'}
|
262
|
+
url2 = @navigation.sub_elements[1].instance_variable_get(:"@url")
|
263
|
+
url2.should == {controller: 'controller2', action: 'action', some_attr: 'some_attr'}
|
250
264
|
end
|
251
|
-
end
|
252
265
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
266
|
+
it 'scopes array of urls' do
|
267
|
+
@navigation.scope url: {some_attr: 'some_attr'} do
|
268
|
+
item :item, ["controller#action1", "controller#action2"]
|
269
|
+
end
|
270
|
+
|
271
|
+
urls = @navigation.sub_elements[0].instance_variable_get(:"@url")
|
272
|
+
urls[0].should == {controller: 'controller', action: 'action1', some_attr: 'some_attr'}
|
273
|
+
urls[1].should == {controller: 'controller', action: 'action2', some_attr: 'some_attr'}
|
258
274
|
end
|
259
|
-
@navigation.item :third_item, "controller3#action"
|
260
275
|
|
261
|
-
|
262
|
-
|
276
|
+
it "can't override defined url attributes" do
|
277
|
+
@navigation.scope url: {some_attr: 'some_attr'} do
|
278
|
+
item :item, {controller: 'controller', action: 'action', some_attr: 'old_attr'}
|
279
|
+
end
|
280
|
+
|
281
|
+
url = @navigation.sub_elements[0].instance_variable_get(:"@url")
|
282
|
+
url[:some_attr].should == 'old_attr'
|
283
|
+
end
|
263
284
|
end
|
264
285
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
286
|
+
describe ':render_if' do
|
287
|
+
|
288
|
+
|
289
|
+
it "scopes the creating items options" do
|
290
|
+
some_condition = mock
|
291
|
+
@navigation.scope :render_if => some_condition do
|
292
|
+
item :first_item, "controller1#action"
|
293
|
+
item :second_item, "controller2#action"
|
294
|
+
end
|
295
|
+
|
296
|
+
@navigation.sub_elements[0..1].each do |element|
|
297
|
+
element.instance_variable_get(:"@render_if").should == some_condition
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
it "doesnt scope unscoped items" do
|
302
|
+
some_condition = mock
|
303
|
+
@navigation.scope render_if: some_condition do
|
304
|
+
item :first_item, "controller1#action"
|
305
|
+
item :second_item, "controller2#action"
|
306
|
+
end
|
307
|
+
@navigation.item :third_item, "controller3#action"
|
308
|
+
|
309
|
+
last_item = @navigation.sub_elements.last
|
310
|
+
last_item.instance_variable_get(:"@render_if").should == nil
|
271
311
|
end
|
272
312
|
|
273
|
-
|
274
|
-
|
313
|
+
it "doesnt override defined scopes" do
|
314
|
+
some_condition = mock
|
315
|
+
some_condition2 = mock
|
316
|
+
@navigation.scope :render_if => some_condition do
|
317
|
+
item :first_item, "controller1#action", render_if: some_condition2
|
318
|
+
item :second_item, "controller2#action"
|
319
|
+
end
|
275
320
|
|
276
|
-
|
277
|
-
|
321
|
+
first_item = @navigation.sub_elements.first
|
322
|
+
second_item = @navigation.sub_elements.last
|
323
|
+
|
324
|
+
first_item.instance_variable_get(:"@render_if").should == some_condition2
|
325
|
+
second_item.instance_variable_get(:"@render_if").should == some_condition
|
326
|
+
end
|
278
327
|
end
|
279
328
|
|
280
329
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Gribovski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/semantic_navigation/core.rb
|
101
101
|
- lib/semantic_navigation/core/base.rb
|
102
102
|
- lib/semantic_navigation/core/leaf.rb
|
103
|
+
- lib/semantic_navigation/core/mix_in/dsl_methods.rb
|
103
104
|
- lib/semantic_navigation/core/mix_in/name_methods.rb
|
104
105
|
- lib/semantic_navigation/core/mix_in/url_methods.rb
|
105
106
|
- lib/semantic_navigation/core/navigation.rb
|