semantic_navigation 0.1.1 → 0.1.3

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 (59) hide show
  1. data/.editorconfig +14 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +10 -2
  4. data/Appraisals +7 -0
  5. data/Gemfile +1 -1
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +31 -20
  8. data/Rakefile +2 -1
  9. data/TODO +14 -0
  10. data/gemfiles/3.2.gemfile +7 -0
  11. data/gemfiles/3.2.gemfile.lock +112 -0
  12. data/gemfiles/4.0.gemfile +7 -0
  13. data/gemfiles/4.0.gemfile.lock +107 -0
  14. data/lib/generators/semantic_navigation/breadcrumb_renderer/templates/breadcrumb_renderer.rb +5 -5
  15. data/lib/generators/semantic_navigation/list_renderer/list_renderer_generator.rb +0 -1
  16. data/lib/generators/semantic_navigation/list_renderer/templates/list_renderer.rb +4 -4
  17. data/lib/semantic_navigation.rb +30 -0
  18. data/lib/semantic_navigation/configuration.rb +8 -9
  19. data/lib/semantic_navigation/core.rb +8 -6
  20. data/lib/semantic_navigation/core/leaf.rb +2 -2
  21. data/lib/semantic_navigation/core/mix_in/name_methods.rb +24 -0
  22. data/lib/semantic_navigation/core/mix_in/url_methods.rb +25 -0
  23. data/lib/semantic_navigation/core/navigation.rb +8 -2
  24. data/lib/semantic_navigation/core/node.rb +2 -2
  25. data/lib/semantic_navigation/deprecations/renderers/acts_as_breadcrumb.rb +14 -0
  26. data/lib/semantic_navigation/deprecations/renderers/acts_as_list.rb +12 -0
  27. data/lib/semantic_navigation/deprecations/renderers/render_helpers.rb +14 -0
  28. data/lib/semantic_navigation/helper_methods.rb +8 -4
  29. data/lib/semantic_navigation/railtie.rb +9 -19
  30. data/lib/semantic_navigation/renderers.rb +15 -8
  31. data/lib/semantic_navigation/renderers/bread_crumb.rb +6 -6
  32. data/lib/semantic_navigation/renderers/list.rb +6 -6
  33. data/lib/semantic_navigation/renderers/mix_in/acts_as_breadcrumb.rb +43 -0
  34. data/lib/semantic_navigation/renderers/mix_in/acts_as_list.rb +49 -0
  35. data/lib/semantic_navigation/renderers/mix_in/render_helpers.rb +110 -0
  36. data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +5 -5
  37. data/lib/semantic_navigation/twitter_bootstrap/list.rb +2 -2
  38. data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +2 -2
  39. data/lib/semantic_navigation/version.rb +1 -1
  40. data/semantic_navigation.gemspec +3 -2
  41. data/spec/lib/semantic_navigation/configuration_spec.rb +29 -24
  42. data/spec/lib/semantic_navigation/core/leaf_spec.rb +121 -114
  43. data/spec/lib/semantic_navigation/core/navigation_spec.rb +81 -76
  44. data/spec/lib/semantic_navigation/core/node_spec.rb +52 -49
  45. data/spec/lib/semantic_navigation/helper_methods_spec.rb +47 -42
  46. data/spec/lib/semantic_navigation/renderers/bread_crumb_spec.rb +191 -187
  47. data/spec/lib/semantic_navigation/renderers/deprecations_spec.rb +67 -0
  48. data/spec/lib/semantic_navigation/renderers/list_spec.rb +260 -258
  49. data/spec/lib/semantic_navigation/twitter_bootstrap/breadcrumb_spec.rb +163 -159
  50. data/spec/lib/semantic_navigation/twitter_bootstrap/list_spec.rb +263 -262
  51. data/spec/lib/semantic_navigation/twitter_bootstrap/tabs_spec.rb +269 -266
  52. data/spec/spec_helper.rb +6 -0
  53. metadata +41 -13
  54. data/gemfiles/rails3 +0 -7
  55. data/lib/semantic_navigation/core/name_methods.rb +0 -24
  56. data/lib/semantic_navigation/core/url_methods.rb +0 -24
  57. data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +0 -42
  58. data/lib/semantic_navigation/renderers/acts_as_list.rb +0 -48
  59. data/lib/semantic_navigation/renderers/render_helpers.rb +0 -109
@@ -0,0 +1,49 @@
1
+ module SemanticNavigation
2
+ module Renderers
3
+ module MixIn
4
+ module ActsAsList
5
+
6
+ def render_navigation(object)
7
+ return '' unless object.render_if
8
+ navigation(object) do
9
+ while !object.class.in?([SemanticNavigation::Core::Leaf, NilClass]) &&
10
+ from_level.to_i > object.level
11
+ object = object.sub_elements.find{|e| e.active}
12
+ end
13
+ show = !until_level.nil? && !object.nil? ? object.level <= until_level : true
14
+ if !object.class.in?([SemanticNavigation::Core::Leaf, NilClass]) && show
15
+ object.sub_elements.map{|element| element.render(self)}.compact.sum
16
+ end
17
+ end
18
+ end
19
+
20
+ def render_node(object)
21
+ if !object.id.in?([except_for].flatten) && object.render_if
22
+ content = render_node_content(object)
23
+ if content
24
+ node(object) do
25
+ content
26
+ end
27
+ else
28
+ render_leaf(object)
29
+ end
30
+ end
31
+ end
32
+
33
+ def render_node_content(object)
34
+ if (!until_level.nil? && until_level >= object.level) || until_level.nil?
35
+ node_content(object) do
36
+ object.sub_elements.map{|element| element.render(self)}.compact.sum
37
+ end
38
+ end
39
+ end
40
+
41
+ def render_leaf(object)
42
+ if !object.id.in?([except_for].flatten) && object.render_if
43
+ leaf(object)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,110 @@
1
+ module SemanticNavigation
2
+ module Renderers
3
+ module MixIn
4
+ module RenderHelpers
5
+
6
+ def self.included(base)
7
+ base.send :include, InstanceMethods
8
+ base.extend(ClassMethods)
9
+ base.class_eval do
10
+ [:navigation, :node, :leaf, :link].each do |e|
11
+ style_accessor :"#{e}_active_class" => [:active],
12
+ :"show_#{e}_active_class" => true,
13
+ :"show_#{e}_id" => true,
14
+ :"#{e}_default_classes" => []
15
+ end
16
+ style_accessor menu_tag: :ul
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+
22
+ def style_accessor(hash)
23
+ hash.keys.each do |key|
24
+ class_eval "
25
+ @@#{key} = nil
26
+ @#{key} = nil
27
+
28
+ def self.#{key}(value)
29
+ @@#{key}= value
30
+ end
31
+
32
+ def #{key}(value = nil)
33
+ @#{key} = value unless value.nil?
34
+ @#{key}.nil? ? @@#{key} : @#{key}
35
+ end
36
+
37
+ def #{key}=(value)
38
+ @#{key} = value
39
+ end
40
+ "
41
+ send key, hash[key]
42
+ end
43
+ end
44
+
45
+ def property_for(class_name,name)
46
+ class_object = "semantic_navigation/core/#{class_name}".classify.constantize
47
+ class_object.class_eval "
48
+ unless defined?(#{name})
49
+ def #{name}
50
+ @#{name}
51
+ end
52
+ end
53
+ "
54
+ end
55
+ end
56
+
57
+ module InstanceMethods
58
+ attr_accessor :from_level, :until_level, :except_for, :name
59
+
60
+ def level=(level)
61
+ @from_level = level
62
+ @until_level = level
63
+ end
64
+
65
+ def levels=(level_range)
66
+ @from_level = level_range.first
67
+ @until_level = level_range.last
68
+ end
69
+
70
+ def initialize
71
+ @view_object = SemanticNavigation::Configuration.view_object
72
+ end
73
+
74
+ private
75
+
76
+ def content_tag(tag_name, content = nil, options={}, &block)
77
+ @view_object.content_tag(tag_name, content, options) {yield if block_given?}
78
+ end
79
+
80
+ def link_to(link_name, url, options={})
81
+ @view_object.link_to(link_name, url, options)
82
+ end
83
+
84
+ def merge_classes(name, active, object_classes = [])
85
+ default_classes = send("#{name}_default_classes")
86
+ active_classes = active && send("show_#{name}_active_class") ? send("#{name}_active_class") : nil
87
+
88
+ classes = [*default_classes, *active_classes, *object_classes]
89
+ !classes.empty? ? classes : nil
90
+ end
91
+
92
+ def show_id(name, id)
93
+ id if send("show_#{name}_id")
94
+ end
95
+
96
+ def object_name(object)
97
+ object.name(self.name)
98
+ end
99
+
100
+ def content_menu_tag(parameters)
101
+ content_tag menu_tag, nil, parameters do
102
+ yield
103
+ end
104
+ end
105
+
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,8 +1,8 @@
1
1
  module SemanticNavigation
2
2
  module TwitterBootstrap
3
3
  class Breadcrumb
4
- include SemanticNavigation::Renderers::RenderHelpers
5
- include SemanticNavigation::Renderers::ActsAsBreadcrumb
4
+ include SemanticNavigation::Renderers::MixIn::RenderHelpers
5
+ include SemanticNavigation::Renderers::MixIn::ActsAsBreadcrumb
6
6
 
7
7
  style_accessor last_as_link: false,
8
8
  breadcrumb_separator: '/'
@@ -36,7 +36,7 @@ module SemanticNavigation
36
36
  }.merge(object.html)) do
37
37
  [object.ico ? content_tag(:i, nil, class: "icon-#{object.ico}") : ''.html_safe,
38
38
  link_to(object_name(object),
39
- object.url,
39
+ object.url,
40
40
  {id: show_id(:link, object.id),
41
41
  class: merge_classes(:link, object.active, object.link_classes)
42
42
  }.merge(object.link_html)),
@@ -51,8 +51,8 @@ module SemanticNavigation
51
51
  }.merge(object.html) do
52
52
  [object.ico ? content_tag(:i, nil, class: "icon-#{object.ico}") : ''.html_safe,
53
53
  if last_as_link
54
- link_to(object_name(object),
55
- object.url,
54
+ link_to(object_name(object),
55
+ object.url,
56
56
  {id: show_id(:link, object.id),
57
57
  class: merge_classes(:link, object.active, object.link_classes)
58
58
  }.merge(object.link_html))
@@ -1,8 +1,8 @@
1
1
  module SemanticNavigation
2
2
  module TwitterBootstrap
3
3
  class List
4
- include SemanticNavigation::Renderers::RenderHelpers
5
- include SemanticNavigation::Renderers::ActsAsList
4
+ include SemanticNavigation::Renderers::MixIn::RenderHelpers
5
+ include SemanticNavigation::Renderers::MixIn::ActsAsList
6
6
 
7
7
  navigation_default_classes [:nav, 'nav-list']
8
8
  show_navigation_id false
@@ -1,8 +1,8 @@
1
1
  module SemanticNavigation
2
2
  module TwitterBootstrap
3
3
  class Tabs
4
- include SemanticNavigation::Renderers::RenderHelpers
5
- include SemanticNavigation::Renderers::ActsAsList
4
+ include SemanticNavigation::Renderers::MixIn::RenderHelpers
5
+ include SemanticNavigation::Renderers::MixIn::ActsAsList
6
6
 
7
7
  style_accessor direction: 'left'
8
8
 
@@ -1,3 +1,3 @@
1
1
  module SemanticNavigation
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  # specify any dependencies here; for example:
23
- s.add_development_dependency "rspec", ">=2.0.1"
23
+ s.add_development_dependency "rspec", ">= 2.0.1"
24
24
  s.add_development_dependency "simplecov"
25
- s.add_runtime_dependency "rails", ">=3.0.0"
25
+ s.add_development_dependency "appraisal"
26
+ s.add_runtime_dependency "rails", ">= 3.2.0"
26
27
  end
@@ -7,33 +7,38 @@ describe SemanticNavigation::Configuration do
7
7
  end
8
8
 
9
9
  describe "#run" do
10
- it 'should receive class eval if block passed' do
10
+ it 'receives class eval if block passed' do
11
11
  SemanticNavigation::Configuration.should_receive(:class_eval)
12
12
  SemanticNavigation::Configuration.run do
13
13
  do_something
14
14
  end
15
15
  end
16
16
 
17
- it 'should not receive class_eval if block not passed' do
17
+ it 'doesnt receive class_eval if block not passed' do
18
18
  SemanticNavigation::Configuration.run
19
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
29
23
 
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
24
+ context :receives do
25
+
26
+ it 'at least only id and save navigation instance in class variables' do
27
+ nav_instance = SemanticNavigation::Configuration.navigate :some_menu
28
+ navigations = SemanticNavigation::Configuration.class_variable_get("@@navigations")
29
+ navigations.keys.should == [:some_menu]
30
+ navigations[:some_menu].should == nav_instance
31
+ end
32
+
33
+ it 'id and pass to Navigation instance create options hash' do
34
+ SemanticNavigation::Core::Navigation.should_receive(:new).with({:id=>:some_menu,
35
+ :i18n_name=>"semantic_navigation.some_menu"})
36
+ SemanticNavigation::Configuration.navigate :some_menu
37
+ end
38
+
34
39
  end
35
40
 
36
- it 'should pass received block to navigation class instance' do
41
+ it 'passes received block to navigation class instance' do
37
42
  navigation = mock
38
43
  navigation.should_receive(:instance_eval)
39
44
  SemanticNavigation::Core::Navigation.should_receive(:new).and_return navigation
@@ -42,7 +47,7 @@ describe SemanticNavigation::Configuration do
42
47
  end
43
48
  end
44
49
 
45
- it 'should merge id, i18n_name and received params and pass them to navigation instance create method' do
50
+ it 'merges id, i18n_name and received params and pass them to navigation instance create method' do
46
51
  SemanticNavigation::Core::Navigation.should_receive(:new).with({:id => :some_menu,
47
52
  :i18n_name=>"semantic_navigation.some_menu",
48
53
  :some_attr => 1,
@@ -52,14 +57,14 @@ describe SemanticNavigation::Configuration do
52
57
  end
53
58
 
54
59
  describe '#navigation' do
55
- it 'should return navigation instance by name' do
60
+ it 'returns navigation instance by name' do
56
61
  nav_instance = SemanticNavigation::Configuration.navigate :some_menu
57
62
  SemanticNavigation::Configuration.navigation(:some_menu).should == nav_instance
58
63
  end
59
64
  end
60
65
 
61
66
  describe '#styles_for' do
62
- it 'should save styles block as a proc' do
67
+ it 'saves styles block as a proc' do
63
68
  proc_object = SemanticNavigation::Configuration.styles_for :some_renderer do
64
69
  do_something1 true
65
70
  do_something2 'some_attr'
@@ -79,21 +84,21 @@ describe SemanticNavigation::Configuration do
79
84
  class SomeRenderer; end
80
85
  end
81
86
 
82
- it 'should register renderer by passed name and class' do
87
+ it 'registers renderer by passed name and class' do
83
88
  SemanticNavigation::Configuration.register_renderer :some_renderer, SomeRenderer
84
89
  renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
85
90
  renderers[:some_renderer].should_not be_nil
86
91
  renderers[:some_renderer].should == SomeRenderer
87
92
  end
88
93
 
89
- it 'should register renderer by passed classes and generate the name for it' do
94
+ it 'registers renderer by passed classes and generate the name for it' do
90
95
  SemanticNavigation::Configuration.register_renderer SomeRenderer
91
96
  renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
92
97
  renderers[:some_renderer].should_not be_nil
93
98
  renderers[:some_renderer].should == SomeRenderer
94
99
  end
95
100
 
96
- it 'should reregister the renderer class regigstered before' do
101
+ it 'registers the renderer class regigstered before' do
97
102
  SemanticNavigation::Configuration.register_renderer SomeRenderer
98
103
  SemanticNavigation::Configuration.register_renderer :another_name, :some_renderer
99
104
  renderers = SemanticNavigation::Configuration.class_variable_get("@@renderers")
@@ -101,7 +106,7 @@ describe SemanticNavigation::Configuration do
101
106
  renderers[:another_name].should == SomeRenderer
102
107
  end
103
108
 
104
- it 'should register a new helper method based on name of a renderer and depending on method navigation_for' do
109
+ it 'registers a new helper method based on name of a renderer and depending on method navigation_for' do
105
110
  SemanticNavigation::Configuration.register_renderer SomeRenderer
106
111
  SemanticNavigation::HelperMethods.method_defined?(:some_renderer_for).should be_true
107
112
 
@@ -128,14 +133,14 @@ describe SemanticNavigation::Configuration do
128
133
  SemanticNavigation::Configuration.class_variable_set "@@navigations", {:some_menu => @navigation}
129
134
  end
130
135
 
131
- it 'should send render method to Renderer class; mark active navigation elements;' do
136
+ it 'sends render method to Renderer class; mark active navigation elements;' do
132
137
  @navigation.should_receive(:mark_active)
133
138
  @navigation.should_receive(:render).with(@renderer_instance)
134
139
  @renderer_instance.should_receive(:name=).with(:renderer)
135
140
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
136
141
  end
137
142
 
138
- it 'should send renderer options' do
143
+ it 'sends renderer options' do
139
144
  @navigation.should_receive(:mark_active)
140
145
  @navigation.should_receive(:render).with(@renderer_instance)
141
146
  @renderer_instance.should_receive(:level=).with(1)
@@ -143,7 +148,7 @@ describe SemanticNavigation::Configuration do
143
148
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {:level => 1}, @view_object)
144
149
  end
145
150
 
146
- it 'should exec default renderer styles from configuration' do
151
+ it 'execs default renderer styles from configuration' do
147
152
  render_styles = proc{}
148
153
  SemanticNavigation::Configuration.class_variable_set "@@render_styles", {:renderer => render_styles}
149
154
  @renderer_instance.should_receive(:instance_eval).with(&render_styles)
@@ -153,7 +158,7 @@ describe SemanticNavigation::Configuration do
153
158
  SemanticNavigation::Configuration.new.render(:some_menu, :renderer, {}, @view_object)
154
159
  end
155
160
 
156
- it 'should set @@view_object in configuration class' do
161
+ it 'sets @@view_object in configuration class' do
157
162
  @navigation.should_receive(:mark_active)
158
163
  @navigation.should_receive(:render).with(@renderer_instance)
159
164
  @renderer_instance.should_receive(:name=).with(:renderer)
@@ -2,81 +2,84 @@ require 'spec_helper'
2
2
 
3
3
  describe SemanticNavigation::Core::Leaf do
4
4
  describe '#name' do
5
-
6
- it 'should return saved name' do
7
- leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :name => 'first'},1)
8
- leaf.name.should == 'first'
9
- end
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
5
 
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
-
36
- it 'should return i18n name if @name is nil' do
37
- leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
38
- I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return 'first'
39
- leaf.name.should == 'first'
40
- end
6
+ context :returns do
7
+
8
+ it 'saved name' do
9
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :name => 'first'},1)
10
+ leaf.name.should == 'first'
11
+ end
12
+
13
+ it 'basic name even if renderer name sended' do
14
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :name => 'first'},1)
15
+ leaf.name(:renderer_name).should == 'first'
16
+ end
17
+
18
+ it 'the name for renderer' do
19
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first,
20
+ :name => {:some_renderer => 'some_renderer_name'}},
21
+ 1)
22
+ leaf.name(:some_renderer).should == 'some_renderer_name'
23
+ end
24
+
25
+ it 'default name for unexpected renderer' do
26
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first,
27
+ :name => {:default => 'default_name',
28
+ :some_renderer => 'some_renderer_name'}},
29
+ 1)
30
+ leaf.name(:unexpected_renderer).should == 'default_name'
31
+ end
32
+
33
+ it 'nil if no name defined' do
34
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first}, 1)
35
+ leaf.name.should == ''
36
+ end
37
+
38
+ it 'i18n name if @name is nil' do
39
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
40
+ I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return 'first'
41
+ leaf.name.should == 'first'
42
+ end
43
+
44
+ it 'i18n_name if @name is even if renderer name is sended' do
45
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
46
+ I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return 'first'
47
+ leaf.name(:renderer_name).should == 'first'
48
+ end
49
+
50
+ it 'i18n_name for requested renderer' do
51
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
52
+ I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:requested_renderer => 'requested_renderer_name'})
53
+ leaf.name(:requested_renderer).should == 'requested_renderer_name'
54
+ end
55
+
56
+ it 'default i18n_name for unexpected renderer' do
57
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
58
+ I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:default => 'default_name', :requested_renderer => 'requested_renderer_name'})
59
+ leaf.name(:unexpected_renderer).should == 'default_name'
60
+ end
61
+
62
+ it 'empty string if default i18n_name was not defined' do
63
+ leaf = SemanticNavigation::Core::Leaf.new({:id => :first, :i18n_name => 'some_navigation'},1)
64
+ I18n.should_receive(:t).with("some_navigation.first", {:default => ""}).and_return({:requested_renderer => 'requested_renderer_name'})
65
+ leaf.name(:unexpected_renderer).should == ''
66
+ end
67
+
68
+ it 'result of proc block if name is_a? proc' do
69
+ leaf = SemanticNavigation::Core::Leaf.new({:name => proc{["first", "item"].join(' ')}},1)
70
+ leaf.name.should == "first item"
71
+ end
41
72
 
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
73
  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
-
66
- it 'should return result of proc block if name is_a? proc' do
67
- leaf = SemanticNavigation::Core::Leaf.new({:name => proc{["first", "item"].join(' ')}},1)
68
- leaf.name.should == "first item"
69
- end
70
-
71
74
  end
72
75
 
73
- describe '#url' do
74
- it 'should return passed url' do
76
+ describe '#url' do
77
+ it 'returns passed url' do
75
78
  leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => 'controller', :action => 'action'}},1)
76
79
  leaf.url.should == {:controller => 'controller', :action => 'action'}
77
80
  end
78
81
 
79
- it 'should return first url if passed array of urls' do
82
+ it 'returns first url if passed array of urls' do
80
83
  leaf = SemanticNavigation::Core::Leaf.new({:url => [{:controller => 'controller1', :action => 'action'},
81
84
  {:controller => 'controller2', :action => 'action'}]},1)
82
85
  leaf.url.should == {:controller => 'controller1', :action => 'action'}
@@ -85,54 +88,58 @@ describe SemanticNavigation::Core::Leaf do
85
88
 
86
89
  describe '#mark_active' do
87
90
 
88
- before :each do
89
- @view_object = mock
90
- SemanticNavigation::Configuration.stub!(:view_object).and_return @view_object
91
- end
92
-
93
- it 'should set as active if have active url with symbol names' do
94
- leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => :first, :action => :index}}, 1)
95
- @view_object.stub(:params).and_return({:controller => 'first', :action => 'index'})
96
- leaf.mark_active.should be_true
97
- leaf.active.should be_true
98
- end
99
-
100
- it 'should set as active if have active url with string names' do
101
- leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => "first", :action => "index"}}, 1)
102
- @view_object.stub(:params).and_return({:controller => 'first', :action => 'index'})
103
- leaf.mark_active.should be_true
104
- leaf.active.should be_true
105
- end
106
-
107
- it 'should set as inactive if have inactive url with symbol names' do
108
- leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => :first, :action => :index}}, 1)
109
- @view_object.stub(:params).and_return({controller: "second", action: 'index'})
110
- leaf.mark_active.should be_false
111
- leaf.active.should be_false
112
- end
113
-
114
- it 'should set as inactive if have inactive url with string names' do
115
- leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => "first", :action => "index"}}, 1)
116
- @view_object.stub(:params).and_return({controller: "second", action: 'index'})
117
- leaf.mark_active.should be_false
118
- leaf.active.should be_false
119
- end
120
-
121
- it 'should set as inactive if have nil url' do
122
- leaf = SemanticNavigation::Core::Leaf.new({},1)
123
- leaf.mark_active.should be_false
124
- leaf.active.should be_false
125
- end
126
-
127
- it 'should be active if at least one url in passed array is active' do
128
- leaf = SemanticNavigation::Core::Leaf.new({:url => [{:controller => :leaf_controller1, :action => :action},
129
- {:controller => :leaf_controller2, :action => :action}]},1)
130
- @view_object.stub(:params).and_return(:controller => 'leaf_controller2', :action => 'action')
131
- leaf.mark_active
132
- leaf.active.should be_true
91
+ before :each do
92
+ @view_object = mock
93
+ SemanticNavigation::Configuration.stub!(:view_object).and_return @view_object
133
94
  end
134
95
 
135
- it 'should accept array like urls with other urls' do
96
+ context :marked do
97
+
98
+ it 'as active if have active url with symbol names' do
99
+ leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => :first, :action => :index}}, 1)
100
+ @view_object.stub(:params).and_return({:controller => 'first', :action => 'index'})
101
+ leaf.mark_active.should be_true
102
+ leaf.active.should be_true
103
+ end
104
+
105
+ it 'as active if have active url with string names' do
106
+ leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => "first", :action => "index"}}, 1)
107
+ @view_object.stub(:params).and_return({:controller => 'first', :action => 'index'})
108
+ leaf.mark_active.should be_true
109
+ leaf.active.should be_true
110
+ end
111
+
112
+ it 'as inactive if have inactive url with symbol names' do
113
+ leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => :first, :action => :index}}, 1)
114
+ @view_object.stub(:params).and_return({controller: "second", action: 'index'})
115
+ leaf.mark_active.should be_false
116
+ leaf.active.should be_false
117
+ end
118
+
119
+ it 'as inactive if have inactive url with string names' do
120
+ leaf = SemanticNavigation::Core::Leaf.new({:url => {:controller => "first", :action => "index"}}, 1)
121
+ @view_object.stub(:params).and_return({controller: "second", action: 'index'})
122
+ leaf.mark_active.should be_false
123
+ leaf.active.should be_false
124
+ end
125
+
126
+ it 'as inactive if have nil url' do
127
+ leaf = SemanticNavigation::Core::Leaf.new({},1)
128
+ leaf.mark_active.should be_false
129
+ leaf.active.should be_false
130
+ end
131
+
132
+ it 'as active if at least one url in passed array is active' do
133
+ leaf = SemanticNavigation::Core::Leaf.new({:url => [{:controller => :leaf_controller1, :action => :action},
134
+ {:controller => :leaf_controller2, :action => :action}]},1)
135
+ @view_object.stub(:params).and_return(:controller => 'leaf_controller2', :action => 'action')
136
+ leaf.mark_active
137
+ leaf.active.should be_true
138
+ end
139
+
140
+ end
141
+
142
+ it 'accepts array like urls with other urls' do
136
143
  leaf = SemanticNavigation::Core::Leaf.new({:url => [['url','with','id'],
137
144
  :symbol_url_name,
138
145
  {:controller => 'hash', :action => 'url'},
@@ -142,7 +149,7 @@ describe SemanticNavigation::Core::Leaf do
142
149
  leaf.should_receive(:current_page?).with({:controller => 'hash', :action => 'url'})
143
150
  leaf.should_receive(:current_page?).with("string_url")
144
151
  leaf.mark_active
145
- end
152
+ end
146
153
 
147
154
  end
148
- end
155
+ end