semantic_navigation 0.0.13 → 0.0.14
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.
- data/.travis.yml +7 -0
- data/Changelog.md +7 -0
- data/README.md +25 -8
- data/Rakefile +2 -0
- data/gemfiles/rails3 +7 -0
- data/lib/generators/semantic_navigation/install/templates/semantic_navigation.rb +6 -2
- data/lib/semantic_navigation/configuration.rb +5 -0
- data/lib/semantic_navigation/core/base.rb +2 -2
- data/lib/semantic_navigation/core/leaf.rb +28 -10
- data/lib/semantic_navigation/core/navigation.rb +11 -4
- data/lib/semantic_navigation/core/node.rb +24 -12
- data/lib/semantic_navigation/helper_methods.rb +3 -1
- data/lib/semantic_navigation/renderers/bread_crumb.rb +3 -3
- data/lib/semantic_navigation/renderers/list.rb +2 -2
- data/lib/semantic_navigation/renderers/render_helpers.rb +6 -2
- data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +4 -4
- data/lib/semantic_navigation/twitter_bootstrap/list.rb +6 -6
- data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +3 -3
- data/lib/semantic_navigation/version.rb +1 -1
- data/spec/lib/semantic_navigation/configuration_spec.rb +153 -0
- data/spec/lib/semantic_navigation/core/leaf_spec.rb +50 -0
- data/spec/lib/semantic_navigation/core/navigation_spec.rb +35 -0
- data/spec/lib/semantic_navigation/core/node_spec.rb +25 -0
- data/spec/lib/semantic_navigation/helper_methods_spec.rb +82 -0
- data/spec/lib/semantic_navigation/renderers/bread_crumb_spec.rb +203 -0
- data/spec/lib/semantic_navigation/renderers/list_spec.rb +241 -0
- data/spec/lib/semantic_navigation/twitter_bootstrap/breadcrumb_spec.rb +202 -0
- data/spec/lib/semantic_navigation/twitter_bootstrap/list_spec.rb +316 -0
- data/spec/lib/semantic_navigation/twitter_bootstrap/tabs_spec.rb +310 -0
- data/spec/spec_helper.rb +1 -0
- metadata +15 -9
- data/spec/lib/semantic_navigation/core/base_spec.rb +0 -1
@@ -31,7 +31,7 @@ module SemanticNavigation
|
|
31
31
|
:class => merge_classes(:link, object.active, [object.link_classes,'dropdown-toggle'].flatten),
|
32
32
|
'data-toggle'=> :dropdown) do
|
33
33
|
[object.ico ? content_tag(:i,nil,:class => "icon-#{object.ico}") : '',
|
34
|
-
object
|
34
|
+
object_name(object),
|
35
35
|
content_tag(:b,nil,:class => :caret)
|
36
36
|
].sum.html_safe
|
37
37
|
end +
|
@@ -49,9 +49,9 @@ module SemanticNavigation
|
|
49
49
|
def leaf(object)
|
50
50
|
if object.ico
|
51
51
|
name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
|
52
|
-
object
|
52
|
+
object_name(object)].sum
|
53
53
|
else
|
54
|
-
name = object
|
54
|
+
name = object_name(object)
|
55
55
|
end
|
56
56
|
|
57
57
|
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
@@ -2,4 +2,157 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SemanticNavigation::Configuration do
|
4
4
|
|
5
|
+
before :each do
|
6
|
+
SemanticNavigation::Configuration.class_variable_set("@@navigations",{})
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#run" do
|
10
|
+
it 'should receive class eval if block passed' do
|
11
|
+
SemanticNavigation::Configuration.should_receive(:class_eval)
|
12
|
+
SemanticNavigation::Configuration.run do
|
13
|
+
do_something
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not receive class_eval if block not passed' do
|
18
|
+
SemanticNavigation::Configuration.run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
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
|
29
|
+
|
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"})
|
33
|
+
SemanticNavigation::Configuration.navigate :some_menu
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should pass received block to navigation class instance' do
|
37
|
+
navigation = mock
|
38
|
+
navigation.should_receive(:instance_eval)
|
39
|
+
SemanticNavigation::Core::Navigation.should_receive(:new).and_return navigation
|
40
|
+
SemanticNavigation::Configuration.navigate :some_menu do
|
41
|
+
do_something
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should merge id, i18n_name and received params and pass them to navigation instance create method' do
|
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})
|
50
|
+
SemanticNavigation::Configuration.navigate :some_menu, :some_attr => 1, :some_attr2 => 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#navigation' do
|
55
|
+
it 'should return navigation instance by name' do
|
56
|
+
nav_instance = SemanticNavigation::Configuration.navigate :some_menu
|
57
|
+
SemanticNavigation::Configuration.navigation(:some_menu).should == nav_instance
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
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
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#register_renderer' do
|
78
|
+
before :each do
|
79
|
+
class SomeRenderer; end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should register renderer by passed name and class' do
|
83
|
+
SemanticNavigation::Configuration.register_renderer :some_renderer, SomeRenderer
|
84
|
+
renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
|
85
|
+
renderers[:some_renderer].should_not be_nil
|
86
|
+
renderers[:some_renderer].should == SomeRenderer
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should register renderer by passed classes and generate the name for it' do
|
90
|
+
SemanticNavigation::Configuration.register_renderer SomeRenderer
|
91
|
+
renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
|
92
|
+
renderers[:some_renderer].should_not be_nil
|
93
|
+
renderers[:some_renderer].should == SomeRenderer
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should register a new helper method based on name of a renderer and depending on method navigation_for' do
|
97
|
+
SemanticNavigation::Configuration.register_renderer SomeRenderer
|
98
|
+
SemanticNavigation::HelperMethods.method_defined?(:some_renderer_for).should be_true
|
99
|
+
|
100
|
+
class SomeClass
|
101
|
+
include SemanticNavigation::HelperMethods
|
102
|
+
end
|
103
|
+
some_class_instance = SomeClass.new
|
104
|
+
some_class_instance.should_receive(:navigation_for).with(:some_menu, {:as => :some_renderer})
|
105
|
+
|
106
|
+
some_class_instance.some_renderer_for :some_menu
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#render' do
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
@view_object = mock
|
114
|
+
@renderer = mock
|
115
|
+
@renderer_instance = mock
|
116
|
+
@renderer.should_receive(:new).and_return @renderer_instance
|
117
|
+
@navigation = mock
|
118
|
+
|
119
|
+
SemanticNavigation::Configuration.class_variable_set "@@renderers", {:renderer => @renderer}
|
120
|
+
SemanticNavigation::Configuration.class_variable_set "@@navigations", {:some_menu => @navigation}
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should send render method to Renderer class; mark active navigation elements;' do
|
124
|
+
@navigation.should_receive(:mark_active)
|
125
|
+
@navigation.should_receive(:render).with(@renderer_instance)
|
126
|
+
@renderer_instance.should_receive(:name=).with(:renderer)
|
127
|
+
SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should send renderer options' do
|
131
|
+
@navigation.should_receive(:mark_active)
|
132
|
+
@navigation.should_receive(:render).with(@renderer_instance)
|
133
|
+
@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)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should exec default renderer styles from configuration' do
|
139
|
+
render_styles = proc{}
|
140
|
+
SemanticNavigation::Configuration.class_variable_set "@@render_styles", {:renderer => render_styles}
|
141
|
+
@renderer_instance.should_receive(:instance_eval).with(&render_styles)
|
142
|
+
@renderer_instance.should_receive(:name=).with(:renderer)
|
143
|
+
@navigation.should_receive(:mark_active)
|
144
|
+
@navigation.should_receive(:render).with(@renderer_instance)
|
145
|
+
SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should set @@view_object in configuration class' do
|
149
|
+
@navigation.should_receive(:mark_active)
|
150
|
+
@navigation.should_receive(:render).with(@renderer_instance)
|
151
|
+
@renderer_instance.should_receive(:name=).with(:renderer)
|
152
|
+
SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
|
153
|
+
SemanticNavigation::Configuration.view_object.should == @view_object
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
5
158
|
end
|
@@ -8,16 +8,66 @@ describe SemanticNavigation::Core::Leaf do
|
|
8
8
|
leaf.name.should == 'first'
|
9
9
|
end
|
10
10
|
|
11
|
+
it 'should return basic name even if renderer name sended' do
|
12
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :name => 'first'},1)
|
13
|
+
leaf.name(:renderer_name).should == 'first'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the name for renderer' do
|
17
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first,
|
18
|
+
:name => {:some_renderer => 'some_renderer_name'}},
|
19
|
+
1)
|
20
|
+
leaf.name(:some_renderer).should == 'some_renderer_name'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return default name for unexpected renderer' do
|
24
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first,
|
25
|
+
:name => {:default => 'default_name',
|
26
|
+
:some_renderer => 'some_renderer_name'}},
|
27
|
+
1)
|
28
|
+
leaf.name(:unexpected_renderer).should == 'default_name'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return nil if no name defined' do
|
32
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first}, 1)
|
33
|
+
leaf.name.should == ''
|
34
|
+
end
|
35
|
+
|
11
36
|
it 'should return i18n name if @name is nil' do
|
12
37
|
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
|
13
38
|
I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return 'first'
|
14
39
|
leaf.name.should == 'first'
|
15
40
|
end
|
16
41
|
|
42
|
+
it 'should return i18n_name if @name is even if renderer name is sended' do
|
43
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
|
44
|
+
I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return 'first'
|
45
|
+
leaf.name(:renderer_name).should == 'first'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return i18n_name for requested renderer' do
|
49
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
|
50
|
+
I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:requested_renderer => 'requested_renderer_name'})
|
51
|
+
leaf.name(:requested_renderer).should == 'requested_renderer_name'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return default i18n_name for unexpected renderer' do
|
55
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
|
56
|
+
I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:default => 'default_name', :requested_renderer => 'requested_renderer_name'})
|
57
|
+
leaf.name(:unexpected_renderer).should == 'default_name'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return empty string if default i18n_name was not defined' do
|
61
|
+
leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
|
62
|
+
I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:requested_renderer => 'requested_renderer_name'})
|
63
|
+
leaf.name(:unexpected_renderer).should == ''
|
64
|
+
end
|
65
|
+
|
17
66
|
it 'should return result of proc block if name is_a? proc' do
|
18
67
|
leaf = SemanticNavigation::Core::Leaf.new({:name => proc{["first", "item"].join(' ')}},1)
|
19
68
|
leaf.name.should == "first item"
|
20
69
|
end
|
70
|
+
|
21
71
|
end
|
22
72
|
|
23
73
|
describe '#url' do
|
@@ -51,6 +51,34 @@ describe SemanticNavigation::Core::Navigation do
|
|
51
51
|
:symbolic_name,
|
52
52
|
['array','like','url']]
|
53
53
|
end
|
54
|
+
|
55
|
+
it "should receive item with Proc url and decode it to normal url (leaf)" do
|
56
|
+
@navigation.item :leaf_id, proc{'some' + 'func'}
|
57
|
+
@navigation.sub_elements.first.url.should == 'somefunc'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should receive item with array of urls one of each is a Proc (leaf)' do
|
61
|
+
@navigation.item :leaf_id, ['string_url',proc{'some' + 'func'}]
|
62
|
+
urls = @navigation.sub_elements.first.send :urls
|
63
|
+
urls.should == ['string_url', 'somefunc']
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should receive item with Proc url and decode it to normal url (node)" do
|
67
|
+
@navigation.item :leaf_id, proc{'some' + 'func'} do
|
68
|
+
item :first_value, '#'
|
69
|
+
item :second_value, '#'
|
70
|
+
end
|
71
|
+
@navigation.sub_elements.first.url.should == 'somefunc'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should receive item with array of urls one of each is a Proc (node)' do
|
75
|
+
@navigation.item :leaf_id, ['string_url',proc{'some' + 'func'}] do
|
76
|
+
item :first_value, '#'
|
77
|
+
item :second_value, '#'
|
78
|
+
end
|
79
|
+
urls = @navigation.sub_elements.first.send :urls
|
80
|
+
urls.should == ['string_url', 'somefunc']
|
81
|
+
end
|
54
82
|
end
|
55
83
|
|
56
84
|
describe '#header' do
|
@@ -117,6 +145,13 @@ describe SemanticNavigation::Core::Navigation do
|
|
117
145
|
navigation = SemanticNavigation::Core::Navigation.new({:render_if => proc{false}})
|
118
146
|
navigation.render_if.should be_false
|
119
147
|
end
|
148
|
+
|
149
|
+
it 'should pass self to passed proc' do
|
150
|
+
navigation = SemanticNavigation::Core::Navigation.new({:id => :some_id, :render_if => proc{|o| o.id == :some_id}})
|
151
|
+
navigation.render_if.should be_true
|
152
|
+
navigation = SemanticNavigation::Core::Navigation.new({:id => :another_id, :render_if => proc{|o| o.id == :some_id}})
|
153
|
+
navigation.render_if.should be_false
|
154
|
+
end
|
120
155
|
end
|
121
156
|
|
122
157
|
describe '#render' do
|
@@ -4,6 +4,31 @@ describe SemanticNavigation::Core::Node do
|
|
4
4
|
|
5
5
|
describe '#name' do
|
6
6
|
|
7
|
+
it 'should return basic name even if renderer name sended' do
|
8
|
+
node = SemanticNavigation::Core::Node.new({:id => :first, :name => 'first'},1)
|
9
|
+
node.name(:renderer_name).should == 'first'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return the name for renderer' do
|
13
|
+
node = SemanticNavigation::Core::Node.new({:id => :first,
|
14
|
+
:name => {:some_renderer => 'some_renderer_name'}},
|
15
|
+
1)
|
16
|
+
node.name(:some_renderer).should == 'some_renderer_name'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return default name for unexpected renderer' do
|
20
|
+
node = SemanticNavigation::Core::Node.new({:id => :first,
|
21
|
+
:name => {:default => 'default_name',
|
22
|
+
:some_renderer => 'some_renderer_name'}},
|
23
|
+
1)
|
24
|
+
node.name(:unexpected_renderer).should == 'default_name'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return nil if no name defined' do
|
28
|
+
node = SemanticNavigation::Core::Node.new({:id => :first}, 1)
|
29
|
+
node.name.should == ''
|
30
|
+
end
|
31
|
+
|
7
32
|
it 'should return passed name while creating node' do
|
8
33
|
node = SemanticNavigation::Core::Node.new({:name => 'some name'}, 1)
|
9
34
|
node.name.should == 'some name'
|
@@ -1 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
|
3
|
+
describe SemanticNavigation::HelperMethods do
|
4
|
+
before :each do
|
5
|
+
class ViewObject
|
6
|
+
include SemanticNavigation::HelperMethods
|
7
|
+
end
|
8
|
+
@view_instance = ViewObject.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#navigation_for" do
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
SemanticNavigation::Configuration.stub!(:new).and_return (@config_instance = mock)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'default renderer should be :list' do
|
18
|
+
@config_instance.should_receive(:render).with(:some_menu, :list, {}, @view_instance)
|
19
|
+
@view_instance.navigation_for :some_menu
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should send defined renderer name' do
|
23
|
+
@config_instance.should_receive(:render).with(:some_menu, :some_renderer, {}, @view_instance)
|
24
|
+
@view_instance.navigation_for :some_menu, :as => :some_renderer
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should send received properties' do
|
28
|
+
@config_instance.should_receive(:render).with(:some_menu, :some_renderer, {:level => 1, :except_for => :some_id}, @view_instance)
|
29
|
+
@view_instance.navigation_for :some_menu, :as => :some_renderer, :level => 1, :except_for => :some_id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#active_item_for" do
|
34
|
+
|
35
|
+
it 'should return empty string if navigation is empty from items' do
|
36
|
+
SemanticNavigation::Configuration.navigate :some_menu do
|
37
|
+
end
|
38
|
+
result = @view_instance.active_item_for :some_menu
|
39
|
+
result.should be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return name for an active item' do
|
43
|
+
SemanticNavigation::Configuration.navigate :some_menu do
|
44
|
+
item :first, '/first', :name => 'First'
|
45
|
+
item :second, '/second', :name => 'Second'
|
46
|
+
end
|
47
|
+
@view_instance.should_receive(:current_page?).with('/first').and_return false
|
48
|
+
@view_instance.should_receive(:current_page?).with('/second').and_return true
|
49
|
+
result = @view_instance.active_item_for :some_menu
|
50
|
+
result.should == 'Second'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should return name for a last level' do
|
54
|
+
SemanticNavigation::Configuration.navigate :some_menu do
|
55
|
+
item :first_node, '/first_node', :name => 'First node' do
|
56
|
+
item :first, '/first', :name => 'First'
|
57
|
+
end
|
58
|
+
item :second_node, 'second_node', :name => 'Second node' do
|
59
|
+
item :second, '/second', :name => 'Second'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
@view_instance.should_receive(:current_page?).exactly(4).times.and_return(false, false,true,false) # First, First node, Second, Second node
|
63
|
+
result = @view_instance.active_item_for :some_menu
|
64
|
+
result.should == 'Second'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return name for a requested level' do
|
68
|
+
SemanticNavigation::Configuration.navigate :some_menu do
|
69
|
+
item :first_node, '/first_node', :name => 'First node' do
|
70
|
+
item :first, '/first', :name => 'First'
|
71
|
+
end
|
72
|
+
item :second_node, 'second_node', :name => 'Second node' do
|
73
|
+
item :second, '/second', :name => 'Second'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@view_instance.should_receive(:current_page?).exactly(4).times.and_return(false, false,true,false) # First, First node, Second, Second node
|
77
|
+
result = @view_instance.active_item_for :some_menu, 1
|
78
|
+
result.should == 'Second node'
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SemanticNavigation::Renderers::BreadCrumb do
|
4
|
+
before :each do
|
5
|
+
class ViewObject
|
6
|
+
attr_accessor :output_buffer
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
include SemanticNavigation::HelperMethods
|
9
|
+
include ActionView::Helpers::UrlHelper
|
10
|
+
end
|
11
|
+
@configuration = SemanticNavigation::Configuration
|
12
|
+
@configuration.register_renderer :breadcrumb, SemanticNavigation::Renderers::BreadCrumb
|
13
|
+
@view_object = ViewObject.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should render empty ul tag for empty navigation' do
|
17
|
+
|
18
|
+
@configuration.run do
|
19
|
+
navigate :menu do
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
result = @view_object.navigation_for :menu, :as => :breadcrumb
|
24
|
+
result.should == "<ul class=\"breadcrumb\" id=\"menu\"></ul>"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should render one level navigation breadcrumb' do
|
28
|
+
@configuration.run do
|
29
|
+
navigate :menu do
|
30
|
+
item :url1, 'url1', :name => 'url1'
|
31
|
+
item :url2, 'url2', :name => 'url2'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@view_object.should_receive(:current_page?).and_return(false,true)
|
36
|
+
|
37
|
+
result = @view_object.navigation_for :menu, :as => :breadcrumb
|
38
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
39
|
+
"<li id=\"url2\">",
|
40
|
+
"url2",
|
41
|
+
"</li>",
|
42
|
+
"</ul>"].join
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should render one multilevel navigation breadcrumb' do
|
46
|
+
@configuration.run do
|
47
|
+
navigate :menu do
|
48
|
+
item :url1, 'url1', :name => 'url1' do
|
49
|
+
item :suburl1, 'suburl1', :name => 'suburl1'
|
50
|
+
end
|
51
|
+
item :url2, 'url2', :name => 'url2' do
|
52
|
+
item :suburl2, 'suburl2', :name => 'suburl2'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
@view_object.should_receive(:current_page?).and_return(true,false,false,false)
|
58
|
+
|
59
|
+
result = @view_object.navigation_for :menu, :as => :breadcrumb
|
60
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
61
|
+
"<li id=\"url1\">",
|
62
|
+
"<a href=\"url1\" id=\"url1\">",
|
63
|
+
"url1",
|
64
|
+
"</a>",
|
65
|
+
"</li>",
|
66
|
+
"<li>/",
|
67
|
+
"</li>",
|
68
|
+
"<li id=\"suburl1\">",
|
69
|
+
"suburl1",
|
70
|
+
"</li>",
|
71
|
+
"</ul>"].join
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should render last item as link if :last_as_link => true' do
|
75
|
+
@configuration.run do
|
76
|
+
navigate :menu do
|
77
|
+
item :url1, 'url1', :name => 'url1' do
|
78
|
+
item :suburl1, 'suburl1', :name => 'suburl1'
|
79
|
+
end
|
80
|
+
item :url2, 'url2', :name => 'url2' do
|
81
|
+
item :suburl2, 'suburl2', :name => 'suburl2'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
@view_object.should_receive(:current_page?).and_return(true,false,false,false)
|
87
|
+
|
88
|
+
result = @view_object.navigation_for :menu, :as => :breadcrumb, :last_as_link => true
|
89
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
90
|
+
"<li id=\"url1\">",
|
91
|
+
"<a href=\"url1\" id=\"url1\">",
|
92
|
+
"url1",
|
93
|
+
"</a>",
|
94
|
+
"</li>",
|
95
|
+
"<li>",
|
96
|
+
"/",
|
97
|
+
"</li>",
|
98
|
+
"<li id=\"suburl1\">",
|
99
|
+
"<a href=\"suburl1\" id=\"suburl1\">",
|
100
|
+
"suburl1",
|
101
|
+
"</a>",
|
102
|
+
"</li>",
|
103
|
+
"</ul>"].join
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should render only root level' do
|
107
|
+
@configuration.run do
|
108
|
+
navigate :menu do
|
109
|
+
item :url1, 'url1', :name => 'url1' do
|
110
|
+
item :suburl1, 'suburl1', :name => 'suburl1'
|
111
|
+
end
|
112
|
+
item :url2, 'url2', :name => 'url2' do
|
113
|
+
item :suburl2, 'suburl2', :name => 'suburl2'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
@view_object.should_receive(:current_page?).and_return(true,false,false,false)
|
119
|
+
|
120
|
+
result = @view_object.navigation_for :menu, :level => 0, :as => :breadcrumb
|
121
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
122
|
+
"<li id=\"url1\">",
|
123
|
+
"url1",
|
124
|
+
"</li>",
|
125
|
+
"</ul>"].join
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should render second level' do
|
129
|
+
@configuration.run do
|
130
|
+
navigate :menu do
|
131
|
+
item :url1, 'url1', :name => 'url1' do
|
132
|
+
item :suburl1, 'suburl1', :name => 'suburl1'
|
133
|
+
end
|
134
|
+
item :url2, 'url2', :name => 'url2' do
|
135
|
+
item :suburl2, 'suburl2', :name => 'suburl2'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
@view_object.should_receive(:current_page?).and_return(true, false, false, false)
|
141
|
+
|
142
|
+
result = @view_object.navigation_for :menu, :level => 1, :as => :breadcrumb
|
143
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
144
|
+
"<li id=\"suburl1\">",
|
145
|
+
"suburl1",
|
146
|
+
"</li>",
|
147
|
+
"</ul>"].join
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should render the exact levels' do
|
151
|
+
@configuration.run do
|
152
|
+
navigate :menu do
|
153
|
+
item :url1, 'url1', :name => 'url1' do
|
154
|
+
item :suburl1, 'suburl1', :name => 'suburl1' do
|
155
|
+
item :subsub1, 'subsub1', :name => 'subsub1'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
item :url2, 'url2', :name => 'url2' do
|
159
|
+
item :suburl2, 'suburl2', :name => 'suburl2' do
|
160
|
+
item :subsub2, 'subsub2', :name => 'subsub2'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
@view_object.should_receive(:current_page?).and_return(true, false, false, false, false, false)
|
167
|
+
|
168
|
+
result = @view_object.navigation_for :menu, :levels => 0..1, :as => :breadcrumb
|
169
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
170
|
+
"<li id=\"url1\">",
|
171
|
+
"<a href=\"url1\" id=\"url1\">",
|
172
|
+
"url1",
|
173
|
+
"</a>",
|
174
|
+
"</li>",
|
175
|
+
"<li>/",
|
176
|
+
"</li>",
|
177
|
+
"<li id=\"suburl1\">",
|
178
|
+
"suburl1",
|
179
|
+
"</li>",
|
180
|
+
"</ul>"].join
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should render navigation except some item' do
|
184
|
+
@configuration.run do
|
185
|
+
navigate :menu do
|
186
|
+
item :url1, 'url1', :name => 'url1' do
|
187
|
+
item :suburl1, 'suburl1', :name => 'suburl1'
|
188
|
+
end
|
189
|
+
item :url2, 'url2', :name => 'url2' do
|
190
|
+
item :suburl2, 'suburl2', :name => 'suburl2'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
@view_object.should_receive(:current_page?).and_return(true, false, false, false)
|
196
|
+
result = @view_object.navigation_for :menu, :except_for => [:suburl1], :as => :breadcrumb
|
197
|
+
result.should == ["<ul class=\"breadcrumb\" id=\"menu\">",
|
198
|
+
"<li id=\"url1\">",
|
199
|
+
"url1",
|
200
|
+
"</li>",
|
201
|
+
"</ul>"].join
|
202
|
+
end
|
203
|
+
end
|