semantic_navigation 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abf4c82d6bcfc8817d5db2c942e7fa239cc4d742
4
- data.tar.gz: 328221d4986c1276a0eae9888a88ee860ff81369
3
+ metadata.gz: 3d11fbfc574d4f330af86cca8173569f75ee9327
4
+ data.tar.gz: 3124611a34e1d5a94174b978b5a2c08a11d48d26
5
5
  SHA512:
6
- metadata.gz: 851b361893e15ccc2edc8428515b1e6d5e013ac0e83de11d127a008a483b1024e74c407842031a0c3c1251264cdd73c5accc60ffb87341e4331cffe9487d81a6
7
- data.tar.gz: 5f572fb5112c5bee0ab1904837628fff49655c33f51b720209e9e2184457f225898ce1800052f6be9acd7b05d4f7a36766ad8b3f371117fe80205d11c695bac7
6
+ metadata.gz: f79196d81f87f41260903b52c6438b1e5373875074300aaaa6d7781c421b38c0efb45793d6da1c1bde6303767f8e723d98e1ae62207bf3b70e35173e4fa884fb
7
+ data.tar.gz: f5592c9a936c43ae524a1ca411e8ddfb0e340336435f9437a77828a2a2711f7e04dc2c0b593dd38be3092fb4387c10293962823c23c46ae7b346c73a8b9cff98
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- semantic_navigation (0.2.1)
4
+ semantic_navigation (0.2.3)
5
5
  rails (>= 3.2.0)
6
6
 
7
7
  GEM
@@ -6,7 +6,13 @@ module SemanticNavigation
6
6
  attr_writer :render_if
7
7
 
8
8
  def render_if
9
- !@render_if.nil? ? view_object.instance_exec(self, &@render_if) : true
9
+ unless @render_if.nil?
10
+ @render_if.map do |bl|
11
+ view_object.instance_exec(self, &bl)
12
+ end.all?
13
+ else
14
+ true
15
+ end
10
16
  end
11
17
 
12
18
  def initialize(options, level)
@@ -5,16 +5,16 @@ module SemanticNavigation
5
5
 
6
6
  def item(id, url=nil, options={}, &block)
7
7
  options[:id] = id.to_sym
8
- options[:render_if] ||= @scope_options[:render_if]
9
-
8
+ options[:render_if] = [*@render_if, options[:render_if], *@scope_render_if].compact
9
+
10
10
  if url.is_a?(Array)
11
11
  options[:url] = [url].flatten(1).map{|url| scope_url_params(decode_url(url))}
12
12
  else
13
13
  options[:url] = scope_url_params(decode_url(url))
14
14
  end
15
-
15
+
16
16
  options[:i18n_name] = @i18n_name
17
-
17
+
18
18
  if block_given?
19
19
  element = Node.new(options, @level+1)
20
20
  element.instance_eval &block
@@ -34,21 +34,21 @@ module SemanticNavigation
34
34
  'divider definition')
35
35
  end
36
36
  end
37
-
37
+
38
38
  @sub_elements.push element
39
39
  end
40
40
 
41
41
  def header(id, options={})
42
42
  options[:id] = id.to_sym
43
- options[:render_if] ||= @scope_options[:render_if]
43
+ options[:render_if] = [options[:render_if], *@scope_render_if].compact
44
44
  options[:url] = nil
45
45
  options[:i18n_name] = @i18n_name
46
46
  @sub_elements.push Leaf.new(options, @level+1)
47
47
  end
48
-
48
+
49
49
  def divider(options = {})
50
50
  options[:id] = :divider
51
- options[:render_if] ||= @scope_options[:render_if]
51
+ options[:render_if] ||= [options[:render_if], *@scope_render_if].compact
52
52
  options[:url] = nil
53
53
  options[:i18n_name] = nil
54
54
  options[:name] = nil
@@ -64,16 +64,20 @@ module SemanticNavigation
64
64
  end
65
65
 
66
66
  def scope(options = {}, &block)
67
- @scope_options = options
67
+ @scope_url ||= options[:url]
68
+ (@scope_render_if ||= []).push options[:render_if]
69
+
68
70
  self.instance_eval &block
69
- @scope_options = {}
71
+
72
+ @scope_render_if.pop
73
+ @scope_url = {}
70
74
  end
71
75
 
72
76
  private
73
77
 
74
78
  def scope_url_params(url)
75
79
  if url.is_a? Hash
76
- (@scope_options[:url] || {}).merge(url)
80
+ (@scope_url || {}).merge(url)
77
81
  else
78
82
  url
79
83
  end
@@ -87,7 +91,7 @@ module SemanticNavigation
87
91
  end
88
92
  end
89
93
  decoded_url || url
90
- end
94
+ end
91
95
 
92
96
  end
93
97
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticNavigation
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -7,7 +7,7 @@ describe SemanticNavigation::Core::Navigation do
7
7
  it 'creates instance of navigation with level 0 and empty subitems' do
8
8
  navigation = SemanticNavigation::Core::Navigation.new({})
9
9
  navigation.level.should == 0
10
-
10
+
11
11
  expect(navigation.sub_elements).to be_empty
12
12
  end
13
13
 
@@ -15,13 +15,13 @@ describe SemanticNavigation::Core::Navigation do
15
15
  navigation = SemanticNavigation::Core::Navigation.new :id => :some_id,
16
16
  :classes => [:one, :two]
17
17
  navigation.id.should == :some_id
18
-
18
+
19
19
  expect(navigation.classes).to eq [:one, :two]
20
20
  end
21
21
 
22
22
  it 'creates instance and save unintended properties' do
23
23
  navigation = SemanticNavigation::Core::Navigation.new :some_attribute => :some_value
24
-
24
+
25
25
  expect(navigation.instance_variable_get("@some_attribute")).to eq :some_value
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ describe SemanticNavigation::Core::Navigation do
35
35
  it "receives item method and make the leaf" do
36
36
  @navigation.item :some_id, 'some_url'
37
37
  @navigation.sub_elements.size.should == 1
38
-
38
+
39
39
  expect(@navigation.sub_elements.first).to be_is_a(SemanticNavigation::Core::Leaf)
40
40
  end
41
41
 
@@ -44,14 +44,14 @@ describe SemanticNavigation::Core::Navigation do
44
44
  item :leaf_id, 'leaf_url'
45
45
  end
46
46
  @navigation.sub_elements.size.should == 1
47
-
47
+
48
48
  expect(@navigation.sub_elements.first).to be_is_a(SemanticNavigation::Core::Node)
49
49
  end
50
50
 
51
51
  it "receives item method with array of urls and save them properly" do
52
52
  @navigation.item :leaf_id, ['string/url',"controller#action",:symbolic_name,['array','like','url']]
53
53
  urls = @navigation.sub_elements.first.instance_variable_get("@url")
54
-
54
+
55
55
  expect(urls).to eq ['string/url',
56
56
  {:controller => 'controller', :action => 'action'},
57
57
  :symbolic_name,
@@ -60,14 +60,14 @@ describe SemanticNavigation::Core::Navigation do
60
60
 
61
61
  it "receives item with Proc url and decode it to normal url (leaf)" do
62
62
  @navigation.item :leaf_id, proc{'some' + 'func'}
63
-
63
+
64
64
  expect(@navigation.sub_elements.first.url).to eq 'somefunc'
65
65
  end
66
66
 
67
67
  it 'receives item with array of urls one of each is a Proc (leaf)' do
68
68
  @navigation.item :leaf_id, ['string_url',proc{'some' + 'func'}]
69
69
  urls = @navigation.sub_elements.first.send :urls
70
-
70
+
71
71
  expect(urls).to eq ['string_url', 'somefunc']
72
72
  end
73
73
 
@@ -76,7 +76,7 @@ describe SemanticNavigation::Core::Navigation do
76
76
  item :first_value, '#'
77
77
  item :second_value, '#'
78
78
  end
79
-
79
+
80
80
  expect(@navigation.sub_elements.first.url).to eq 'somefunc'
81
81
  end
82
82
 
@@ -86,7 +86,7 @@ describe SemanticNavigation::Core::Navigation do
86
86
  item :second_value, '#'
87
87
  end
88
88
  urls = @navigation.sub_elements.first.send :urls
89
-
89
+
90
90
  expect(urls).to eq ['string_url', 'somefunc']
91
91
  end
92
92
  end
@@ -136,7 +136,7 @@ describe SemanticNavigation::Core::Navigation do
136
136
 
137
137
  @navigation.item :some_id, 'controller#action'
138
138
  @navigation.sub_elements.size.should == 1
139
-
139
+
140
140
  expect(@navigation.sub_elements.first.url).to eq({:controller => "controller", :action => "action"})
141
141
  end
142
142
  end
@@ -145,17 +145,17 @@ describe SemanticNavigation::Core::Navigation do
145
145
  context :returns do
146
146
  it 'true if render_if proc is nil' do
147
147
  navigation = SemanticNavigation::Core::Navigation.new({})
148
-
148
+
149
149
  expect(navigation.render_if).to eq true
150
150
  end
151
151
 
152
152
  it 'true if render_if proc return true' do
153
- navigation = SemanticNavigation::Core::Navigation.new({:render_if => proc{true}})
153
+ navigation = SemanticNavigation::Core::Navigation.new({:render_if => [proc{true}]})
154
154
  expect(navigation.render_if).to eq true
155
155
  end
156
156
 
157
157
  it 'false if render_if proc return false' do
158
- navigation = SemanticNavigation::Core::Navigation.new({:render_if => proc{false}})
158
+ navigation = SemanticNavigation::Core::Navigation.new({:render_if => [proc{false}]})
159
159
  expect(navigation.render_if).to eq false
160
160
  end
161
161
 
@@ -163,9 +163,9 @@ describe SemanticNavigation::Core::Navigation do
163
163
 
164
164
  context :passes do
165
165
  it 'self to passed proc' do
166
- navigation = SemanticNavigation::Core::Navigation.new({:id => :some_id, :render_if => proc{|o| o.id == :some_id}})
166
+ navigation = SemanticNavigation::Core::Navigation.new({:id => :some_id, :render_if => [proc{|o| o.id == :some_id}]})
167
167
  expect(navigation.render_if).to eq true
168
- navigation = SemanticNavigation::Core::Navigation.new({:id => :another_id, :render_if => proc{|o| o.id == :some_id}})
168
+ navigation = SemanticNavigation::Core::Navigation.new({:id => :another_id, :render_if => [proc{|o| o.id == :some_id}]})
169
169
  expect(navigation.render_if).to eq false
170
170
  end
171
171
  end
@@ -268,11 +268,11 @@ describe SemanticNavigation::Core::Navigation do
268
268
  item :first_item, "controller1#action"
269
269
  item :second_item, "controller2#action"
270
270
  end
271
-
271
+
272
272
  url1 = @navigation.sub_elements[0].instance_variable_get(:"@url")
273
273
  url1.should == {controller: 'controller1', action: 'action', some_attr: 'some_attr'}
274
274
  url2 = @navigation.sub_elements[1].instance_variable_get(:"@url")
275
- url2.should == {controller: 'controller2', action: 'action', some_attr: 'some_attr'}
275
+ url2.should == {controller: 'controller2', action: 'action', some_attr: 'some_attr'}
276
276
  end
277
277
 
278
278
  it 'scopes array of urls' do
@@ -306,7 +306,7 @@ describe SemanticNavigation::Core::Navigation do
306
306
  end
307
307
 
308
308
  @navigation.sub_elements[0..1].each do |element|
309
- element.instance_variable_get(:"@render_if").should == some_condition
309
+ element.instance_variable_get(:"@render_if").should == [some_condition]
310
310
  end
311
311
  end
312
312
 
@@ -319,7 +319,7 @@ describe SemanticNavigation::Core::Navigation do
319
319
  @navigation.item :third_item, "controller3#action"
320
320
 
321
321
  last_item = @navigation.sub_elements.last
322
- last_item.instance_variable_get(:"@render_if").should == nil
322
+ last_item.instance_variable_get(:"@render_if").should == []
323
323
  end
324
324
 
325
325
  it "doesnt override defined scopes" do
@@ -333,8 +333,8 @@ describe SemanticNavigation::Core::Navigation do
333
333
  first_item = @navigation.sub_elements.first
334
334
  second_item = @navigation.sub_elements.last
335
335
 
336
- first_item.instance_variable_get(:"@render_if").should == some_condition2
337
- second_item.instance_variable_get(:"@render_if").should == some_condition
336
+ first_item.instance_variable_get(:"@render_if").should == [some_condition2, some_condition]
337
+ second_item.instance_variable_get(:"@render_if").should == [some_condition]
338
338
  end
339
339
  end
340
340
 
@@ -346,4 +346,5 @@ describe SemanticNavigation::Core::Navigation do
346
346
  lambda{@navigation.unknow_method}.should raise_exception
347
347
  end
348
348
  end
349
+
349
350
  end
@@ -16,291 +16,320 @@ describe SemanticNavigation::Renderers::List do
16
16
  @view_object = ViewObject.new
17
17
  end
18
18
 
19
- it 'empty ul tag for empty navigation' do
19
+ # it 'empty ul tag for empty navigation' do
20
20
 
21
- @configuration.run do
22
- navigate :menu do
23
- end
24
- end
21
+ # @configuration.run do
22
+ # navigate :menu do
23
+ # end
24
+ # end
25
25
 
26
- result = @view_object.navigation_for :menu
27
- result.should == "<ul class=\"list\" id=\"menu\"><\/ul>"
28
- end
26
+ # result = @view_object.navigation_for :menu
27
+ # result.should == "<ul class=\"list\" id=\"menu\"><\/ul>"
28
+ # end
29
29
 
30
- it 'one level navigation' do
31
- @configuration.run do
32
- navigate :menu do
33
- item :url1, 'url1', :name => 'url1'
34
- item :url2, 'url2', :name => 'url2'
35
- end
36
- end
30
+ # it 'one level navigation' do
31
+ # @configuration.run do
32
+ # navigate :menu do
33
+ # item :url1, 'url1', :name => 'url1'
34
+ # item :url2, 'url2', :name => 'url2'
35
+ # end
36
+ # end
37
37
 
38
- result = @view_object.navigation_for :menu
39
- result.should == ["<ul class=\"list\" id=\"menu\">",
40
- "<li id=\"url1\">",
41
- "<a href=\"url1\" id=\"url1\">",
42
- "url1",
43
- "</a>",
44
- "</li>",
45
- "<li id=\"url2\">",
46
- "<a href=\"url2\" id=\"url2\">",
47
- "url2",
48
- "</a>",
49
- "</li>",
50
- "</ul>"].join
51
- end
38
+ # result = @view_object.navigation_for :menu
39
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
40
+ # "<li id=\"url1\">",
41
+ # "<a href=\"url1\" id=\"url1\">",
42
+ # "url1",
43
+ # "</a>",
44
+ # "</li>",
45
+ # "<li id=\"url2\">",
46
+ # "<a href=\"url2\" id=\"url2\">",
47
+ # "url2",
48
+ # "</a>",
49
+ # "</li>",
50
+ # "</ul>"].join
51
+ # end
52
52
 
53
- it 'one level navigation with specific menu tag' do
54
- @configuration.run do
53
+ # it 'one level navigation with specific menu tag' do
54
+ # @configuration.run do
55
55
 
56
- register_renderer :my_list, :list
56
+ # register_renderer :my_list, :list
57
57
 
58
- styles_for :my_list do
59
- menu_tag :ol
60
- end
58
+ # styles_for :my_list do
59
+ # menu_tag :ol
60
+ # end
61
61
 
62
- navigate :menu do
63
- item :url1, 'url1', :name => 'url1'
64
- item :url2, 'url2', :name => 'url2'
65
- end
66
- end
62
+ # navigate :menu do
63
+ # item :url1, 'url1', :name => 'url1'
64
+ # item :url2, 'url2', :name => 'url2'
65
+ # end
66
+ # end
67
67
 
68
- result = @view_object.navigation_for :menu, as: :my_list
69
- result.should == ["<ol class=\"list\" id=\"menu\">",
70
- "<li id=\"url1\">",
71
- "<a href=\"url1\" id=\"url1\">",
72
- "url1",
73
- "</a>",
74
- "</li>",
75
- "<li id=\"url2\">",
76
- "<a href=\"url2\" id=\"url2\">",
77
- "url2",
78
- "</a>",
79
- "</li>",
80
- "</ol>"].join
81
- end
68
+ # result = @view_object.navigation_for :menu, as: :my_list
69
+ # result.should == ["<ol class=\"list\" id=\"menu\">",
70
+ # "<li id=\"url1\">",
71
+ # "<a href=\"url1\" id=\"url1\">",
72
+ # "url1",
73
+ # "</a>",
74
+ # "</li>",
75
+ # "<li id=\"url2\">",
76
+ # "<a href=\"url2\" id=\"url2\">",
77
+ # "url2",
78
+ # "</a>",
79
+ # "</li>",
80
+ # "</ol>"].join
81
+ # end
82
82
 
83
- it 'one level navigation with specific menu tag' do
84
- @configuration.run do
83
+ # it 'one level navigation with specific menu tag' do
84
+ # @configuration.run do
85
85
 
86
- register_renderer :my_list, :list
86
+ # register_renderer :my_list, :list
87
87
 
88
- styles_for :my_list do
89
- menu_tag :ol
90
- end
88
+ # styles_for :my_list do
89
+ # menu_tag :ol
90
+ # end
91
91
 
92
- navigate :menu do
93
- item :url1, 'url1', :name => 'url1' do
94
- item :url2, 'url2', :name => 'url2'
95
- end
96
- end
97
- end
92
+ # navigate :menu do
93
+ # item :url1, 'url1', :name => 'url1' do
94
+ # item :url2, 'url2', :name => 'url2'
95
+ # end
96
+ # end
97
+ # end
98
98
 
99
- result = @view_object.navigation_for :menu, as: :my_list
100
- result.should == ["<ol class=\"list\" id=\"menu\">",
101
- "<li id=\"url1\">",
102
- "<a href=\"url1\" id=\"url1\">",
103
- "url1",
104
- "</a>",
105
- "<ol id=\"url1\">",
106
- "<li id=\"url2\">",
107
- "<a href=\"url2\" id=\"url2\">",
108
- "url2",
109
- "</a>",
110
- "</li>",
111
- "</ol>",
112
- "</li>",
113
- "</ol>"].join
114
- end
99
+ # result = @view_object.navigation_for :menu, as: :my_list
100
+ # result.should == ["<ol class=\"list\" id=\"menu\">",
101
+ # "<li id=\"url1\">",
102
+ # "<a href=\"url1\" id=\"url1\">",
103
+ # "url1",
104
+ # "</a>",
105
+ # "<ol id=\"url1\">",
106
+ # "<li id=\"url2\">",
107
+ # "<a href=\"url2\" id=\"url2\">",
108
+ # "url2",
109
+ # "</a>",
110
+ # "</li>",
111
+ # "</ol>",
112
+ # "</li>",
113
+ # "</ol>"].join
114
+ # end
115
115
 
116
- it 'one multilevel navigation' do
117
- @configuration.run do
118
- navigate :menu do
119
- item :url1, 'url1', :name => 'url1' do
120
- item :suburl1, 'suburl1', :name => 'suburl1'
121
- end
122
- item :url2, 'url2', :name => 'url2' do
123
- item :suburl2, 'suburl2', :name => 'suburl2'
124
- end
125
- end
126
- end
116
+ # it 'one multilevel navigation' do
117
+ # @configuration.run do
118
+ # navigate :menu do
119
+ # item :url1, 'url1', :name => 'url1' do
120
+ # item :suburl1, 'suburl1', :name => 'suburl1'
121
+ # end
122
+ # item :url2, 'url2', :name => 'url2' do
123
+ # item :suburl2, 'suburl2', :name => 'suburl2'
124
+ # end
125
+ # end
126
+ # end
127
127
 
128
- result = @view_object.navigation_for :menu
129
- result.should == ["<ul class=\"list\" id=\"menu\">",
130
- "<li id=\"url1\">",
131
- "<a href=\"url1\" id=\"url1\">",
132
- "url1",
133
- "</a>",
134
- "<ul id=\"url1\">",
135
- "<li id=\"suburl1\">",
136
- "<a href=\"suburl1\" id=\"suburl1\">",
137
- "suburl1",
138
- "</a>",
139
- "</li>",
140
- "</ul>",
141
- "</li>",
142
- "<li id=\"url2\">",
143
- "<a href=\"url2\" id=\"url2\">",
144
- "url2",
145
- "</a>",
146
- "<ul id=\"url2\">",
147
- "<li id=\"suburl2\">",
148
- "<a href=\"suburl2\" id=\"suburl2\">",
149
- "suburl2",
150
- "</a>",
151
- "</li>",
152
- "</ul>",
153
- "</li>",
154
- "</ul>"].join
155
- end
128
+ # result = @view_object.navigation_for :menu
129
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
130
+ # "<li id=\"url1\">",
131
+ # "<a href=\"url1\" id=\"url1\">",
132
+ # "url1",
133
+ # "</a>",
134
+ # "<ul id=\"url1\">",
135
+ # "<li id=\"suburl1\">",
136
+ # "<a href=\"suburl1\" id=\"suburl1\">",
137
+ # "suburl1",
138
+ # "</a>",
139
+ # "</li>",
140
+ # "</ul>",
141
+ # "</li>",
142
+ # "<li id=\"url2\">",
143
+ # "<a href=\"url2\" id=\"url2\">",
144
+ # "url2",
145
+ # "</a>",
146
+ # "<ul id=\"url2\">",
147
+ # "<li id=\"suburl2\">",
148
+ # "<a href=\"suburl2\" id=\"suburl2\">",
149
+ # "suburl2",
150
+ # "</a>",
151
+ # "</li>",
152
+ # "</ul>",
153
+ # "</li>",
154
+ # "</ul>"].join
155
+ # end
156
156
 
157
- it 'only root level' do
158
- @configuration.run do
159
- navigate :menu do
160
- item :url1, 'url1', :name => 'url1' do
161
- item :suburl1, 'suburl1', :name => 'suburl1'
162
- end
163
- item :url2, 'url2', :name => 'url2' do
164
- item :suburl2, 'suburl2', :name => 'suburl2'
165
- end
166
- end
167
- end
157
+ # it 'only root level' do
158
+ # @configuration.run do
159
+ # navigate :menu do
160
+ # item :url1, 'url1', :name => 'url1' do
161
+ # item :suburl1, 'suburl1', :name => 'suburl1'
162
+ # end
163
+ # item :url2, 'url2', :name => 'url2' do
164
+ # item :suburl2, 'suburl2', :name => 'suburl2'
165
+ # end
166
+ # end
167
+ # end
168
168
 
169
- result = @view_object.navigation_for :menu, :level => 0
170
- result.should == ["<ul class=\"list\" id=\"menu\">",
171
- "<li id=\"url1\">",
172
- "<a href=\"url1\" id=\"url1\">",
173
- "url1",
174
- "</a>",
175
- "</li>",
176
- "<li id=\"url2\">",
177
- "<a href=\"url2\" id=\"url2\">",
178
- "url2",
179
- "</a>",
180
- "</li>",
181
- "</ul>"].join
182
- end
169
+ # result = @view_object.navigation_for :menu, :level => 0
170
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
171
+ # "<li id=\"url1\">",
172
+ # "<a href=\"url1\" id=\"url1\">",
173
+ # "url1",
174
+ # "</a>",
175
+ # "</li>",
176
+ # "<li id=\"url2\">",
177
+ # "<a href=\"url2\" id=\"url2\">",
178
+ # "url2",
179
+ # "</a>",
180
+ # "</li>",
181
+ # "</ul>"].join
182
+ # end
183
183
 
184
- it 'second level if some item of first level is active' do
185
- @configuration.run do
186
- navigate :menu do
187
- item :url1, 'url1', :name => 'url1' do
188
- item :suburl1, 'suburl1', :name => 'suburl1'
189
- end
190
- item :url2, 'url2', :name => 'url2' do
191
- item :suburl2, 'suburl2', :name => 'suburl2'
192
- end
193
- end
194
- end
184
+ # it 'second level if some item of first level is active' do
185
+ # @configuration.run do
186
+ # navigate :menu do
187
+ # item :url1, 'url1', :name => 'url1' do
188
+ # item :suburl1, 'suburl1', :name => 'suburl1'
189
+ # end
190
+ # item :url2, 'url2', :name => 'url2' do
191
+ # item :suburl2, 'suburl2', :name => 'suburl2'
192
+ # end
193
+ # end
194
+ # end
195
195
 
196
- @view_object.should_receive(:current_page?).and_return(false, true, false, false)
196
+ # @view_object.should_receive(:current_page?).and_return(false, true, false, false)
197
197
 
198
- result = @view_object.navigation_for :menu, :level => 1
199
- result.should == ["<ul class=\"list active\" id=\"menu\">",
200
- "<li id=\"suburl1\">",
201
- "<a href=\"suburl1\" id=\"suburl1\">",
202
- "suburl1",
203
- "</a>",
204
- "</li>",
205
- "</ul>"].join
206
- end
198
+ # result = @view_object.navigation_for :menu, :level => 1
199
+ # result.should == ["<ul class=\"list active\" id=\"menu\">",
200
+ # "<li id=\"suburl1\">",
201
+ # "<a href=\"suburl1\" id=\"suburl1\">",
202
+ # "suburl1",
203
+ # "</a>",
204
+ # "</li>",
205
+ # "</ul>"].join
206
+ # end
207
207
 
208
- it 'the exact levels' do
209
- @configuration.run do
210
- navigate :menu do
211
- item :url1, 'url1', :name => 'url1' do
212
- item :suburl1, 'suburl1', :name => 'suburl1' do
213
- item :subsub1, 'subsub1', :name => 'subsub1'
214
- end
215
- end
216
- item :url2, 'url2', :name => 'url2' do
217
- item :suburl2, 'suburl2', :name => 'suburl2' do
218
- item :subsub2, 'subsub2', :name => 'subsub2'
219
- end
220
- end
221
- end
222
- end
208
+ # it 'the exact levels' do
209
+ # @configuration.run do
210
+ # navigate :menu do
211
+ # item :url1, 'url1', :name => 'url1' do
212
+ # item :suburl1, 'suburl1', :name => 'suburl1' do
213
+ # item :subsub1, 'subsub1', :name => 'subsub1'
214
+ # end
215
+ # end
216
+ # item :url2, 'url2', :name => 'url2' do
217
+ # item :suburl2, 'suburl2', :name => 'suburl2' do
218
+ # item :subsub2, 'subsub2', :name => 'subsub2'
219
+ # end
220
+ # end
221
+ # end
222
+ # end
223
223
 
224
- result = @view_object.navigation_for :menu, :levels => 0..1
225
- result.should == ["<ul class=\"list\" id=\"menu\">",
226
- "<li id=\"url1\">",
227
- "<a href=\"url1\" id=\"url1\">",
228
- "url1",
229
- "</a>",
230
- "<ul id=\"url1\">",
231
- "<li id=\"suburl1\">",
232
- "<a href=\"suburl1\" id=\"suburl1\">",
233
- "suburl1",
234
- "</a>",
235
- "</li>",
236
- "</ul>",
237
- "</li>",
238
- "<li id=\"url2\">",
239
- "<a href=\"url2\" id=\"url2\">",
240
- "url2",
241
- "</a>",
242
- "<ul id=\"url2\">",
243
- "<li id=\"suburl2\">",
244
- "<a href=\"suburl2\" id=\"suburl2\">",
245
- "suburl2",
246
- "</a>",
247
- "</li>",
248
- "</ul>",
249
- "</li>",
250
- "</ul>"].join
251
- end
224
+ # result = @view_object.navigation_for :menu, :levels => 0..1
225
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
226
+ # "<li id=\"url1\">",
227
+ # "<a href=\"url1\" id=\"url1\">",
228
+ # "url1",
229
+ # "</a>",
230
+ # "<ul id=\"url1\">",
231
+ # "<li id=\"suburl1\">",
232
+ # "<a href=\"suburl1\" id=\"suburl1\">",
233
+ # "suburl1",
234
+ # "</a>",
235
+ # "</li>",
236
+ # "</ul>",
237
+ # "</li>",
238
+ # "<li id=\"url2\">",
239
+ # "<a href=\"url2\" id=\"url2\">",
240
+ # "url2",
241
+ # "</a>",
242
+ # "<ul id=\"url2\">",
243
+ # "<li id=\"suburl2\">",
244
+ # "<a href=\"suburl2\" id=\"suburl2\">",
245
+ # "suburl2",
246
+ # "</a>",
247
+ # "</li>",
248
+ # "</ul>",
249
+ # "</li>",
250
+ # "</ul>"].join
251
+ # end
252
252
 
253
- it 'navigation except some item' do
254
- @configuration.run do
255
- navigate :menu do
256
- item :url1, 'url1', :name => 'url1' do
257
- item :suburl1, 'suburl1', :name => 'suburl1'
258
- end
259
- item :url2, 'url2', :name => 'url2' do
260
- item :suburl2, 'suburl2', :name => 'suburl2'
261
- end
262
- end
263
- end
253
+ # it 'navigation except some item' do
254
+ # @configuration.run do
255
+ # navigate :menu do
256
+ # item :url1, 'url1', :name => 'url1' do
257
+ # item :suburl1, 'suburl1', :name => 'suburl1'
258
+ # end
259
+ # item :url2, 'url2', :name => 'url2' do
260
+ # item :suburl2, 'suburl2', :name => 'suburl2'
261
+ # end
262
+ # end
263
+ # end
264
264
 
265
- result = @view_object.navigation_for :menu, :except_for => [:url1]
266
- result.should == ["<ul class=\"list\" id=\"menu\">",
267
- "<li id=\"url2\">",
268
- "<a href=\"url2\" id=\"url2\">",
269
- "url2",
270
- "</a>",
271
- "<ul id=\"url2\">",
272
- "<li id=\"suburl2\">",
273
- "<a href=\"suburl2\" id=\"suburl2\">",
274
- "suburl2",
275
- "</a>",
276
- "</li>",
277
- "</ul>",
278
- "</li>",
279
- "</ul>"].join
280
- end
265
+ # result = @view_object.navigation_for :menu, :except_for => [:url1]
266
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
267
+ # "<li id=\"url2\">",
268
+ # "<a href=\"url2\" id=\"url2\">",
269
+ # "url2",
270
+ # "</a>",
271
+ # "<ul id=\"url2\">",
272
+ # "<li id=\"suburl2\">",
273
+ # "<a href=\"suburl2\" id=\"suburl2\">",
274
+ # "suburl2",
275
+ # "</a>",
276
+ # "</li>",
277
+ # "</ul>",
278
+ # "</li>",
279
+ # "</ul>"].join
280
+ # end
281
+
282
+ # it 'navigation except some items' do
283
+ # @configuration.run do
284
+ # navigate :menu do
285
+ # item :url1, 'url1', :name => 'url1' do
286
+ # item :suburl1, 'suburl1', :name => 'suburl1'
287
+ # end
288
+ # item :url2, 'url2', :name => 'url2' do
289
+ # item :suburl2, 'suburl2', :name => 'suburl2'
290
+ # end
291
+ # end
292
+ # end
293
+
294
+ # result = @view_object.navigation_for :menu, :except_for => [:suburl1,:url2]
295
+ # result.should == ["<ul class=\"list\" id=\"menu\">",
296
+ # "<li id=\"url1\">",
297
+ # "<a href=\"url1\" id=\"url1\">",
298
+ # "url1",
299
+ # "</a>",
300
+ # "<ul id=\"url1\">",
301
+ # "</ul>",
302
+ # "</li>",
303
+ # "</ul>"].join
304
+ # end
281
305
 
282
- it 'navigation except some items' do
306
+ it 'considers scopes' do
307
+ allow(@view_object).to receive(:role?).with('manager').and_return false
308
+ allow(@view_object).to receive(:role?).with('trader').and_return true
283
309
  @configuration.run do
284
310
  navigate :menu do
285
- item :url1, 'url1', :name => 'url1' do
286
- item :suburl1, 'suburl1', :name => 'suburl1'
311
+ item :trader_space, '#', render_if: proc{role?('trader')} do
287
312
  end
288
- item :url2, 'url2', :name => 'url2' do
289
- item :suburl2, 'suburl2', :name => 'suburl2'
313
+
314
+ scope render_if: proc{role?('manager')} do
315
+ divider
316
+ item :manager_space, '#' do
317
+ item :one, 'url1'
318
+ item :two, 'url2'
319
+ end
290
320
  end
291
321
  end
292
322
  end
293
323
 
294
- result = @view_object.navigation_for :menu, :except_for => [:suburl1,:url2]
295
- result.should == ["<ul class=\"list\" id=\"menu\">",
296
- "<li id=\"url1\">",
297
- "<a href=\"url1\" id=\"url1\">",
298
- "url1",
299
- "</a>",
300
- "<ul id=\"url1\">",
301
- "</ul>",
302
- "</li>",
303
- "</ul>"].join
324
+ allow(@view_object).to receive(:current_page?).and_return false
325
+ allow(@view_object).to receive(:current_page?).with("url1").and_return true
326
+
327
+ result = @view_object.navigation_for :menu, from_level: 1
328
+ result.should == [
329
+ "<ul class=\"list active\" id=\"menu\">",
330
+ "</ul>"
331
+ ].join
304
332
  end
333
+
305
334
  end
306
335
  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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gribovski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec