semantic_navigation 0.0.14 → 0.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.
Files changed (34) hide show
  1. data/Changelog.md +6 -1
  2. data/README.md +3 -3
  3. data/lib/generators/semantic_navigation/breadcrumb_renderer/breadcrumb_renderer_generator.rb +19 -0
  4. data/lib/generators/semantic_navigation/breadcrumb_renderer/templates/breadcrumb_renderer.rb +62 -0
  5. data/lib/generators/semantic_navigation/install/install_generator.rb +2 -2
  6. data/lib/generators/semantic_navigation/install/templates/semantic_navigation.rb +5 -5
  7. data/lib/generators/semantic_navigation/list_renderer/list_renderer_generator.rb +19 -0
  8. data/lib/generators/semantic_navigation/list_renderer/templates/list_renderer.rb +64 -0
  9. data/lib/semantic_navigation/configuration.rb +10 -10
  10. data/lib/semantic_navigation/core.rb +8 -4
  11. data/lib/semantic_navigation/core/base.rb +8 -8
  12. data/lib/semantic_navigation/core/leaf.rb +5 -33
  13. data/lib/semantic_navigation/core/name_methods.rb +24 -0
  14. data/lib/semantic_navigation/core/navigation.rb +23 -12
  15. data/lib/semantic_navigation/core/node.rb +6 -34
  16. data/lib/semantic_navigation/core/url_methods.rb +24 -0
  17. data/lib/semantic_navigation/railtie.rb +17 -7
  18. data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +8 -8
  19. data/lib/semantic_navigation/renderers/acts_as_list.rb +34 -33
  20. data/lib/semantic_navigation/renderers/bread_crumb.rb +5 -5
  21. data/lib/semantic_navigation/renderers/list.rb +9 -9
  22. data/lib/semantic_navigation/renderers/render_helpers.rb +19 -32
  23. data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +8 -8
  24. data/lib/semantic_navigation/twitter_bootstrap/list.rb +15 -15
  25. data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +14 -14
  26. data/lib/semantic_navigation/version.rb +1 -1
  27. data/spec/lib/semantic_navigation/configuration_spec.rb +50 -42
  28. data/spec/lib/semantic_navigation/core/navigation_spec.rb +58 -0
  29. data/spec/lib/semantic_navigation/helper_methods_spec.rb +31 -31
  30. data/spec/lib/semantic_navigation/twitter_bootstrap/breadcrumb_spec.rb +46 -46
  31. data/spec/lib/semantic_navigation/twitter_bootstrap/list_spec.rb +49 -49
  32. data/spec/lib/semantic_navigation_spec.rb +4 -1
  33. metadata +14 -9
  34. data/spec/lib/semantic_navigation/custom_renderer.rb +0 -3
@@ -6,9 +6,9 @@ module SemanticNavigation
6
6
 
7
7
  style_accessor :last_as_link => false,
8
8
  :breadcrumb_separator => '/'
9
-
9
+
10
10
  navigation_default_classes [:breadcrumb]
11
-
11
+
12
12
  show_navigation_active_class false
13
13
  show_node_active_class false
14
14
  show_leaf_active_class false
@@ -17,18 +17,18 @@ module SemanticNavigation
17
17
  show_node_id false
18
18
  show_leaf_id false
19
19
  show_link_id false
20
-
20
+
21
21
  property_for :base, :ico
22
-
22
+
23
23
  private
24
-
24
+
25
25
  def navigation(object)
26
26
  content_tag :ul, nil, :id => show_id(:navigation, object.id),
27
27
  :class => merge_classes(:navigation, object.active, object.classes) do
28
28
  yield
29
29
  end
30
30
  end
31
-
31
+
32
32
  def node(object)
33
33
  content_tag(:li, nil, :id => show_id(:leaf, object.id),
34
34
  :class => merge_classes(:leaf, object.active, object.classes)) do
@@ -39,7 +39,7 @@ module SemanticNavigation
39
39
  end +
40
40
  yield
41
41
  end
42
-
42
+
43
43
  def leaf(object)
44
44
  content_tag :li, nil, :id => show_id(:leaf, object.id),
45
45
  :class => merge_classes(:leaf, object.active, object.classes) do
@@ -52,7 +52,7 @@ module SemanticNavigation
52
52
  end].sum
53
53
  end
54
54
  end
55
-
55
+
56
56
  end
57
57
  end
58
58
  end
@@ -3,24 +3,24 @@ module SemanticNavigation
3
3
  class List
4
4
  include SemanticNavigation::Renderers::RenderHelpers
5
5
  include SemanticNavigation::Renderers::ActsAsList
6
-
6
+
7
7
  navigation_default_classes [:nav, 'nav-list']
8
8
  show_navigation_id false
9
9
  show_node_id false
10
10
  show_leaf_id false
11
- show_link_id false
12
-
11
+ show_link_id false
12
+
13
13
  property_for :base, :ico
14
-
14
+
15
15
  private
16
-
16
+
17
17
  def navigation(object)
18
18
  content_tag :ul, nil, :id => show_id(:navigation, object.id),
19
19
  :class => merge_classes(:navigation, object.active, object.classes) do
20
20
  yield
21
- end
21
+ end
22
22
  end
23
-
23
+
24
24
  def node(object)
25
25
  if object.ico
26
26
  name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
@@ -28,22 +28,22 @@ module SemanticNavigation
28
28
  else
29
29
  name = object_name(object)
30
30
  end
31
-
31
+
32
32
  content_tag :li, nil, :id => show_id(:leaf, object.id),
33
33
  :class => merge_classes(:leaf, object.active, object.classes) do
34
34
  link_to(name, object.url, :id => show_id(:link, object.id),
35
35
  :class => merge_classes(:link, object.active, object.link_classes)) +
36
36
  yield
37
- end
37
+ end
38
38
  end
39
-
39
+
40
40
  def node_content(object)
41
41
  content_tag(:ul, nil, :id => show_id(:node, object.id),
42
42
  :class => merge_classes(:node, object.active, object.node_classes)) do
43
43
  yield
44
44
  end
45
45
  end
46
-
46
+
47
47
  def leaf(object)
48
48
  if object_name(object).empty? && object.url.nil?
49
49
  classes = 'divider'
@@ -52,25 +52,25 @@ module SemanticNavigation
52
52
  else
53
53
  classes = merge_classes(:leaf, object.active, object.classes)
54
54
  end
55
-
55
+
56
56
  if object.ico
57
57
  name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
58
58
  object_name(object)].sum
59
59
  else
60
60
  name = object_name(object)
61
61
  end
62
-
62
+
63
63
  content_tag :li, nil, :id => show_id(:leaf, object.id),
64
64
  :class => classes do
65
65
  if object.url.nil?
66
66
  name
67
67
  else
68
68
  link_to name, object.url, :id => show_id(:link, object.id),
69
- :class => merge_classes(:link, object.active, object.link_classes)
69
+ :class => merge_classes(:link, object.active, object.link_classes)
70
70
  end
71
71
  end
72
72
  end
73
-
73
+
74
74
  end
75
75
  end
76
76
  end
@@ -3,26 +3,26 @@ module SemanticNavigation
3
3
  class Tabs
4
4
  include SemanticNavigation::Renderers::RenderHelpers
5
5
  include SemanticNavigation::Renderers::ActsAsList
6
-
6
+
7
7
  style_accessor :direction => 'left'
8
-
8
+
9
9
  navigation_default_classes [:nav, 'nav-tabs']
10
10
  show_navigation_id false
11
11
  show_node_id false
12
12
  show_leaf_id false
13
- show_link_id false
14
-
13
+ show_link_id false
14
+
15
15
  property_for :base, :ico
16
-
16
+
17
17
  private
18
-
18
+
19
19
  def navigation(object)
20
20
  content_tag :ul, nil, :id => show_id(:navigation, object.id),
21
21
  :class => merge_classes(:navigation, object.active, [object.classes,"pull-#{direction}"]) do
22
22
  yield
23
23
  end
24
24
  end
25
-
25
+
26
26
  def node(object)
27
27
  content_tag :li, nil, :id => show_id(:leaf, object.id),
28
28
  :class => merge_classes(:leaf, object.active, [object.classes,'dropdown'].flatten) do
@@ -33,19 +33,19 @@ module SemanticNavigation
33
33
  [object.ico ? content_tag(:i,nil,:class => "icon-#{object.ico}") : '',
34
34
  object_name(object),
35
35
  content_tag(:b,nil,:class => :caret)
36
- ].sum.html_safe
36
+ ].sum.html_safe
37
37
  end +
38
38
  yield
39
- end
39
+ end
40
40
  end
41
-
41
+
42
42
  def node_content(object)
43
43
  content_tag(:ul, nil, :id => show_id(:node, object.id),
44
44
  :class => merge_classes(:node, false, [object.node_classes,'dropdown-menu'].flatten)) do
45
45
  yield
46
46
  end
47
47
  end
48
-
48
+
49
49
  def leaf(object)
50
50
  if object.ico
51
51
  name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
@@ -53,18 +53,18 @@ module SemanticNavigation
53
53
  else
54
54
  name = object_name(object)
55
55
  end
56
-
56
+
57
57
  content_tag :li, nil, :id => show_id(:leaf, object.id),
58
58
  :class => merge_classes(:leaf, object.active, object.classes) do
59
59
  if object.url.nil?
60
60
  name
61
61
  else
62
62
  link_to name, object.url, :id => show_id(:link, object.id),
63
- :class => merge_classes(:link, object.active, object.link_classes)
63
+ :class => merge_classes(:link, object.active, object.link_classes)
64
64
  end
65
65
  end
66
66
  end
67
-
67
+
68
68
  end
69
69
  end
70
70
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticNavigation
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,35 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SemanticNavigation::Configuration do
4
-
4
+
5
5
  before :each do
6
6
  SemanticNavigation::Configuration.class_variable_set("@@navigations",{})
7
7
  end
8
8
 
9
9
  describe "#run" do
10
- it 'should receive class eval if block passed' do
10
+ it 'should receive class eval if block passed' do
11
11
  SemanticNavigation::Configuration.should_receive(:class_eval)
12
12
  SemanticNavigation::Configuration.run do
13
- do_something
13
+ do_something
14
14
  end
15
- end
15
+ end
16
16
 
17
- it 'should not receive class_eval if block not passed' do
17
+ it 'should not receive class_eval if block not passed' do
18
18
  SemanticNavigation::Configuration.run
19
- end
19
+ end
20
20
  end
21
21
 
22
22
  describe '#navigate' do
23
- it 'should receive at least only id and save navigation instance in class variables' do
24
- nav_instance = SemanticNavigation::Configuration.navigate :some_menu
25
- navigations = SemanticNavigation::Configuration.class_variable_get("@@navigations")
26
- navigations.keys.should == [:some_menu]
27
- navigations[:some_menu].should == nav_instance
28
- end
23
+ it 'should receive at least only id and save navigation instance in class variables' do
24
+ nav_instance = SemanticNavigation::Configuration.navigate :some_menu
25
+ navigations = SemanticNavigation::Configuration.class_variable_get("@@navigations")
26
+ navigations.keys.should == [:some_menu]
27
+ navigations[:some_menu].should == nav_instance
28
+ end
29
29
 
30
30
  it 'should receive id and pass to Navigation instance create options hash' do
31
- SemanticNavigation::Core::Navigation.should_receive(:new).with({:id=>:some_menu,
32
- :i18n_name=>"semantic_navigation.some_menu"})
31
+ SemanticNavigation::Core::Navigation.should_receive(:new).with({:id=>:some_menu,
32
+ :i18n_name=>"semantic_navigation.some_menu"})
33
33
  SemanticNavigation::Configuration.navigate :some_menu
34
34
  end
35
35
 
@@ -38,40 +38,40 @@ describe SemanticNavigation::Configuration do
38
38
  navigation.should_receive(:instance_eval)
39
39
  SemanticNavigation::Core::Navigation.should_receive(:new).and_return navigation
40
40
  SemanticNavigation::Configuration.navigate :some_menu do
41
- do_something
41
+ do_something
42
42
  end
43
43
  end
44
44
 
45
45
  it 'should merge id, i18n_name and received params and pass them to navigation instance create method' do
46
46
  SemanticNavigation::Core::Navigation.should_receive(:new).with({:id => :some_menu,
47
- :i18n_name=>"semantic_navigation.some_menu",
48
- :some_attr => 1,
49
- :some_attr2 => 2})
47
+ :i18n_name=>"semantic_navigation.some_menu",
48
+ :some_attr => 1,
49
+ :some_attr2 => 2})
50
50
  SemanticNavigation::Configuration.navigate :some_menu, :some_attr => 1, :some_attr2 => 2
51
51
  end
52
52
  end
53
53
 
54
54
  describe '#navigation' do
55
- it 'should return navigation instance by name' do
56
- nav_instance = SemanticNavigation::Configuration.navigate :some_menu
55
+ it 'should return navigation instance by name' do
56
+ nav_instance = SemanticNavigation::Configuration.navigate :some_menu
57
57
  SemanticNavigation::Configuration.navigation(:some_menu).should == nav_instance
58
- end
58
+ end
59
59
  end
60
60
 
61
61
  describe '#styles_for' do
62
- it 'should save styles block as a proc' do
63
- proc_object = SemanticNavigation::Configuration.styles_for :some_renderer do
64
- do_something1 true
65
- do_something2 'some_attr'
66
- end
67
- styles = SemanticNavigation::Configuration.class_variable_get("@@render_styles")
68
- styles[:some_renderer].should == proc_object
69
-
70
- mock_renderer = mock
71
- mock_renderer.should_receive(:do_something1).with(true)
72
- mock_renderer.should_receive(:do_something2).with('some_attr')
73
- mock_renderer.instance_eval &proc_object
74
- end
62
+ it 'should save styles block as a proc' do
63
+ proc_object = SemanticNavigation::Configuration.styles_for :some_renderer do
64
+ do_something1 true
65
+ do_something2 'some_attr'
66
+ end
67
+ styles = SemanticNavigation::Configuration.class_variable_get("@@render_styles")
68
+ styles[:some_renderer].should == proc_object
69
+
70
+ mock_renderer = mock
71
+ mock_renderer.should_receive(:do_something1).with(true)
72
+ mock_renderer.should_receive(:do_something2).with('some_attr')
73
+ mock_renderer.instance_eval &proc_object
74
+ end
75
75
  end
76
76
 
77
77
  describe '#register_renderer' do
@@ -93,10 +93,18 @@ describe SemanticNavigation::Configuration do
93
93
  renderers[:some_renderer].should == SomeRenderer
94
94
  end
95
95
 
96
+ it 'should reregister the renderer class regigstered before' do
97
+ SemanticNavigation::Configuration.register_renderer SomeRenderer
98
+ SemanticNavigation::Configuration.register_renderer :another_name, :some_renderer
99
+ renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
100
+ renderers[:another_name].should_not be_nil
101
+ renderers[:another_name].should == SomeRenderer
102
+ end
103
+
96
104
  it 'should register a new helper method based on name of a renderer and depending on method navigation_for' do
97
105
  SemanticNavigation::Configuration.register_renderer SomeRenderer
98
106
  SemanticNavigation::HelperMethods.method_defined?(:some_renderer_for).should be_true
99
-
107
+
100
108
  class SomeClass
101
109
  include SemanticNavigation::HelperMethods
102
110
  end
@@ -109,7 +117,7 @@ describe SemanticNavigation::Configuration do
109
117
 
110
118
  describe '#render' do
111
119
 
112
- before :each do
120
+ before :each do
113
121
  @view_object = mock
114
122
  @renderer = mock
115
123
  @renderer_instance = mock
@@ -123,7 +131,7 @@ describe SemanticNavigation::Configuration do
123
131
  it 'should send render method to Renderer class; mark active navigation elements;' do
124
132
  @navigation.should_receive(:mark_active)
125
133
  @navigation.should_receive(:render).with(@renderer_instance)
126
- @renderer_instance.should_receive(:name=).with(:renderer)
134
+ @renderer_instance.should_receive(:name=).with(:renderer)
127
135
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
128
136
  end
129
137
 
@@ -131,15 +139,15 @@ describe SemanticNavigation::Configuration do
131
139
  @navigation.should_receive(:mark_active)
132
140
  @navigation.should_receive(:render).with(@renderer_instance)
133
141
  @renderer_instance.should_receive(:level=).with(1)
134
- @renderer_instance.should_receive(:name=).with(:renderer)
135
- SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {:level => 1}, @view_object)
142
+ @renderer_instance.should_receive(:name=).with(:renderer)
143
+ SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {:level => 1}, @view_object)
136
144
  end
137
145
 
138
146
  it 'should exec default renderer styles from configuration' do
139
147
  render_styles = proc{}
140
148
  SemanticNavigation::Configuration.class_variable_set "@@render_styles", {:renderer => render_styles}
141
149
  @renderer_instance.should_receive(:instance_eval).with(&render_styles)
142
- @renderer_instance.should_receive(:name=).with(:renderer)
150
+ @renderer_instance.should_receive(:name=).with(:renderer)
143
151
  @navigation.should_receive(:mark_active)
144
152
  @navigation.should_receive(:render).with(@renderer_instance)
145
153
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
@@ -148,11 +156,11 @@ describe SemanticNavigation::Configuration do
148
156
  it 'should set @@view_object in configuration class' do
149
157
  @navigation.should_receive(:mark_active)
150
158
  @navigation.should_receive(:render).with(@renderer_instance)
151
- @renderer_instance.should_receive(:name=).with(:renderer)
159
+ @renderer_instance.should_receive(:name=).with(:renderer)
152
160
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
153
161
  SemanticNavigation::Configuration.view_object.should == @view_object
154
162
  end
155
163
 
156
164
  end
157
165
 
158
- end
166
+ end
@@ -216,6 +216,64 @@ describe SemanticNavigation::Core::Navigation do
216
216
 
217
217
  end
218
218
 
219
+ describe "#render_if scope" do
220
+ before :each do
221
+ @navigation = SemanticNavigation::Core::Navigation.new({})
222
+
223
+ @view_object = mock
224
+ SemanticNavigation::Configuration.stub(:view_object).and_return @view_object
225
+ end
226
+
227
+ it "should scope the items" do
228
+ @navigation.scope do
229
+ item :first_item, "controller1#action"
230
+ item :second_item, "controller2#action"
231
+ end
232
+
233
+ @navigation.sub_elements.size.should == 2
234
+ end
235
+
236
+ it "should scope the creating items options" do
237
+ some_condition = mock
238
+ @navigation.scope :render_if => some_condition do
239
+ item :first_item, "controller1#action"
240
+ item :second_item, "controller2#action"
241
+ end
242
+
243
+ @navigation.sub_elements[0..1].each do |element|
244
+ element.instance_variable_get(:"@render_if").should == some_condition
245
+ end
246
+ end
247
+
248
+ it "should not scope unscoped items" do
249
+ some_condition = mock
250
+ @navigation.scope render_if: some_condition do
251
+ item :first_item, "controller1#action"
252
+ item :second_item, "controller2#action"
253
+ end
254
+ @navigation.item :third_item, "controller3#action"
255
+
256
+ last_item = @navigation.sub_elements.last
257
+ last_item.instance_variable_get(:"@render_if").should == nil
258
+ end
259
+
260
+ it "should not override defined scopes" do
261
+ some_condition = mock
262
+ some_condition2 = mock
263
+ @navigation.scope :render_if => some_condition do
264
+ item :first_item, "controller1#action", render_if: some_condition2
265
+ item :second_item, "controller2#action"
266
+ end
267
+
268
+ first_item = @navigation.sub_elements.first
269
+ second_item = @navigation.sub_elements.last
270
+
271
+ first_item.instance_variable_get(:"@render_if").should == some_condition2
272
+ second_item.instance_variable_get(:"@render_if").should == some_condition
273
+ end
274
+
275
+ end
276
+
219
277
  describe '#method_missing' do
220
278
  it 'should get unknown method and call super' do
221
279
  @navigation = SemanticNavigation::Core::Navigation.new({})