simple-navigation 2.5.4 → 2.6.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.
- data/CHANGELOG +7 -0
- data/VERSION.yml +2 -2
- data/generators/navigation_config/templates/config/navigation.rb +1 -0
- data/lib/simple_navigation/configuration.rb +3 -3
- data/lib/simple_navigation/controller_methods.rb +1 -1
- data/lib/simple_navigation/helpers.rb +2 -1
- data/lib/simple_navigation/item.rb +3 -5
- data/lib/simple_navigation/item_container.rb +15 -1
- data/lib/simple_navigation/renderer/base.rb +5 -1
- data/lib/simple_navigation/renderer/breadcrumbs.rb +38 -0
- data/lib/simple_navigation/renderer/list.rb +5 -1
- data/lib/simple_navigation.rb +25 -2
- data/spec/lib/simple_navigation/item_container_spec.rb +54 -20
- data/spec/lib/simple_navigation/renderer/base_spec.rb +23 -0
- data/spec/lib/simple_navigation/renderer/breadcrumbs_spec.rb +100 -0
- data/spec/lib/simple_navigation/renderer/list_spec.rb +41 -1
- data/spec/lib/simple_navigation_spec.rb +17 -0
- data/spec/spec_helper.rb +8 -1
- metadata +7 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
*2.6.0
|
2
|
+
|
3
|
+
* added rendering option 'skip_if_empty' to Renderer::List to avoid rendering of empty ul-tags
|
4
|
+
* added breadcrumbs renderer incl. specs. A big thanks to Markus Schirp.
|
5
|
+
* added ability to register a renderer / specify your renderer as symbol in render_navigation
|
6
|
+
* renderer can be specified in render_navigation. Credits to Andi Badi from Galaxy Cats.
|
7
|
+
|
1
8
|
*2.5.4
|
2
9
|
|
3
10
|
* bugfix: SimpleNavigation.config_file? without params does not check for _navigation.rb file anymore. Credits to Markus Schirp.
|
data/VERSION.yml
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
SimpleNavigation::Configuration.run do |navigation|
|
3
3
|
# Specify a custom renderer if needed.
|
4
4
|
# The default renderer is SimpleNavigation::Renderer::List which renders HTML lists.
|
5
|
+
# The renderer can also be specified as option in the render_navigation call.
|
5
6
|
# navigation.renderer = Your::Custom::Renderer
|
6
7
|
|
7
8
|
# Specify the class that will be applied to active navigation items. Defaults to 'selected'
|
@@ -7,8 +7,7 @@ module SimpleNavigation
|
|
7
7
|
include Singleton
|
8
8
|
|
9
9
|
attr_accessor :renderer, :selected_class, :autogenerate_item_ids, :id_generator, :auto_highlight
|
10
|
-
attr_reader :render_all_levels
|
11
|
-
attr_reader :primary_navigation
|
10
|
+
attr_reader :render_all_levels, :primary_navigation
|
12
11
|
|
13
12
|
class << self
|
14
13
|
|
@@ -52,6 +51,7 @@ module SimpleNavigation
|
|
52
51
|
# end
|
53
52
|
#
|
54
53
|
# ==== To consider when directly providing items
|
54
|
+
# items_provider should be:
|
55
55
|
# * a methodname (as symbol) that returns your items. The method needs to be available in the view (i.e. a helper method)
|
56
56
|
# * an object that responds to :items
|
57
57
|
# * an enumerable containing your items
|
@@ -75,7 +75,7 @@ module SimpleNavigation
|
|
75
75
|
def context_for_eval
|
76
76
|
self.class.context_for_eval
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
end
|
80
80
|
|
81
81
|
end
|
@@ -30,6 +30,7 @@ module SimpleNavigation
|
|
30
30
|
# If you specify a context then the plugin tries to load the configuration file for that context, e.g. if you call <tt>render_navigation(:context => :admin)</tt> the file config/admin_navigation.rb
|
31
31
|
# will be loaded and used for rendering the navigation.
|
32
32
|
# * <tt>:items</tt> - you can specify the items directly (e.g. if items are dynamically generated from database). See SimpleNavigation::ItemsProvider for documentation on what to provide as items.
|
33
|
+
# * <tt>:renderer</tt> - specify the renderer to be used for rendering the navigation. Either provide the Class or a symbol matching a registered renderer. Defaults to :list (html list renderer).
|
33
34
|
def render_navigation(*args)
|
34
35
|
args = [Hash.new] if args.empty?
|
35
36
|
options = extract_backwards_compatible_options(*args)
|
@@ -94,4 +95,4 @@ module SimpleNavigation
|
|
94
95
|
end
|
95
96
|
|
96
97
|
end
|
97
|
-
end
|
98
|
+
end
|
@@ -75,19 +75,17 @@ module SimpleNavigation
|
|
75
75
|
url == '/' && SimpleNavigation.controller.request.path == '/'
|
76
76
|
end
|
77
77
|
|
78
|
-
#
|
79
|
-
# def hash_for_url(url) #:nodoc:
|
80
|
-
# ActionController::Routing::Routes.recognize_path(url, {:method => (method || :get)})
|
81
|
-
# end
|
82
|
-
|
78
|
+
# Returns true if the item's id should be added to the rendered output.
|
83
79
|
def autogenerate_item_ids?
|
84
80
|
SimpleNavigation.config.autogenerate_item_ids
|
85
81
|
end
|
86
82
|
|
83
|
+
# Returns the item's id which is added to the rendered output.
|
87
84
|
def autogenerated_item_id
|
88
85
|
SimpleNavigation.config.id_generator.call(key)
|
89
86
|
end
|
90
87
|
|
88
|
+
# Return true if auto_highlight is on for this item.
|
91
89
|
def auto_highlight?
|
92
90
|
SimpleNavigation.config.auto_highlight && @container.auto_highlight
|
93
91
|
end
|
@@ -68,7 +68,16 @@ module SimpleNavigation
|
|
68
68
|
#
|
69
69
|
# The options are the same as in the view's render_navigation call (they get passed on)
|
70
70
|
def render(options={})
|
71
|
-
|
71
|
+
renderer_class = if options[:renderer]
|
72
|
+
if options[:renderer].instance_of?(Symbol) && SimpleNavigation.registered_renderers.key?(options[:renderer])
|
73
|
+
SimpleNavigation.registered_renderers[options[:renderer]].new(options)
|
74
|
+
else
|
75
|
+
options[:renderer].new(options)
|
76
|
+
end
|
77
|
+
else
|
78
|
+
self.renderer.new(options)
|
79
|
+
end
|
80
|
+
renderer_class.render(self)
|
72
81
|
end
|
73
82
|
|
74
83
|
# Returns true if any of this container's items is selected.
|
@@ -99,6 +108,11 @@ module SimpleNavigation
|
|
99
108
|
return selected_item.sub_navigation.active_item_container_for(desired_level)
|
100
109
|
end
|
101
110
|
|
111
|
+
# Returns true if there are no items defined for this container.
|
112
|
+
def empty?
|
113
|
+
items.empty?
|
114
|
+
end
|
115
|
+
|
102
116
|
private
|
103
117
|
|
104
118
|
def selected_sub_navigation?
|
@@ -34,6 +34,10 @@ module SimpleNavigation
|
|
34
34
|
|
35
35
|
def level
|
36
36
|
options[:level] || :all
|
37
|
+
end
|
38
|
+
|
39
|
+
def skip_if_empty?
|
40
|
+
!!options[:skip_if_empty]
|
37
41
|
end
|
38
42
|
|
39
43
|
def include_sub_navigation?(item)
|
@@ -81,4 +85,4 @@ module SimpleNavigation
|
|
81
85
|
|
82
86
|
end
|
83
87
|
end
|
84
|
-
end
|
88
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SimpleNavigation
|
2
|
+
module Renderer
|
3
|
+
|
4
|
+
# Renders an ItemContainer as a <div> element and its containing items as <a> elements.
|
5
|
+
# It only renders 'selected' elements.
|
6
|
+
#
|
7
|
+
# By default, the renderer sets the item's key as dom_id for the rendered <a> element unless the config option <tt>autogenerate_item_ids</tt> is set to false.
|
8
|
+
# The id can also be explicitely specified by setting the id in the html-options of the 'item' method in the config/navigation.rb file.
|
9
|
+
# The ItemContainer's dom_class and dom_id are applied to the surrounding <div> element.
|
10
|
+
#
|
11
|
+
class Breadcrumbs < SimpleNavigation::Renderer::Base
|
12
|
+
|
13
|
+
def render(item_container)
|
14
|
+
a_tags = a_tags(item_container)
|
15
|
+
content_tag(:div, html_safe(a_tags(item_container).join(join_with)), {:id => item_container.dom_id, :class => item_container.dom_class})
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def a_tags(item_container)
|
21
|
+
item_container.items.inject([]) do |list, item|
|
22
|
+
if item.selected?
|
23
|
+
list << link_to(html_safe(item.name), item.url, {:method => item.method}.merge(item.html_options.except(:class,:id))) if item.selected?
|
24
|
+
if include_sub_navigation?(item)
|
25
|
+
list.concat a_tags(item.sub_navigation)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
list
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def join_with
|
33
|
+
@join_with ||= options[:join_with] || " "
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -19,7 +19,11 @@ module SimpleNavigation
|
|
19
19
|
end
|
20
20
|
list << content_tag(:li, li_content, html_options)
|
21
21
|
end.join
|
22
|
-
|
22
|
+
if skip_if_empty? && item_container.empty?
|
23
|
+
''
|
24
|
+
else
|
25
|
+
content_tag(:ul, html_safe(list_content), {:id => item_container.dom_id, :class => item_container.dom_class})
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
data/lib/simple_navigation.rb
CHANGED
@@ -9,18 +9,26 @@ require 'simple_navigation/items_provider'
|
|
9
9
|
require 'simple_navigation/renderer/base'
|
10
10
|
require 'simple_navigation/renderer/list'
|
11
11
|
require 'simple_navigation/renderer/links'
|
12
|
+
require 'simple_navigation/renderer/breadcrumbs'
|
12
13
|
require 'simple_navigation/initializer'
|
13
14
|
require 'simple_navigation/railtie' if Rails::VERSION::MAJOR == 3
|
14
15
|
|
15
16
|
# A plugin for generating a simple navigation. See README for resources on usage instructions.
|
16
17
|
module SimpleNavigation
|
17
18
|
|
18
|
-
mattr_accessor :config_files, :config_file_path, :default_renderer, :controller, :template, :explicit_current_navigation, :rails_env, :rails_root
|
19
|
+
mattr_accessor :config_files, :config_file_path, :default_renderer, :controller, :template, :explicit_current_navigation, :rails_env, :rails_root, :registered_renderers
|
19
20
|
|
20
21
|
self.config_files = {}
|
22
|
+
self.registered_renderers = {
|
23
|
+
:list => SimpleNavigation::Renderer::List,
|
24
|
+
:links => SimpleNavigation::Renderer::Links,
|
25
|
+
:breadcrumbs => SimpleNavigation::Renderer::Breadcrumbs
|
26
|
+
}
|
27
|
+
|
21
28
|
|
22
29
|
class << self
|
23
30
|
|
31
|
+
# Sets the config file path and installs the ControllerMethods in ActionController::Base.
|
24
32
|
def init_rails
|
25
33
|
SimpleNavigation.config_file_path = SimpleNavigation.default_config_file_path unless SimpleNavigation.config_file_path
|
26
34
|
ActionController::Base.send(:include, SimpleNavigation::ControllerMethods)
|
@@ -30,6 +38,7 @@ module SimpleNavigation
|
|
30
38
|
File.join(SimpleNavigation.rails_root, 'config')
|
31
39
|
end
|
32
40
|
|
41
|
+
# Returns true if the config_file for specified context does exist.
|
33
42
|
def config_file?(navigation_context = :default)
|
34
43
|
File.exists?(config_file_name(navigation_context))
|
35
44
|
end
|
@@ -124,6 +133,21 @@ module SimpleNavigation
|
|
124
133
|
context
|
125
134
|
end
|
126
135
|
end
|
136
|
+
|
137
|
+
# Registers a renderer.
|
138
|
+
#
|
139
|
+
# === Example
|
140
|
+
# To register your own renderer:
|
141
|
+
#
|
142
|
+
# SimpleNavigation.register_renderer :my_renderer => My::RendererClass
|
143
|
+
#
|
144
|
+
# Then in the view you can call:
|
145
|
+
#
|
146
|
+
# render_navigation(:renderer => :my_renderer)
|
147
|
+
#
|
148
|
+
def register_renderer(renderer_hash)
|
149
|
+
self.registered_renderers.merge!(renderer_hash)
|
150
|
+
end
|
127
151
|
|
128
152
|
private
|
129
153
|
|
@@ -158,7 +182,6 @@ module SimpleNavigation
|
|
158
182
|
end
|
159
183
|
|
160
184
|
# TODOs for the next releases:
|
161
|
-
# 0) make sn_set_navigation private in controllers
|
162
185
|
# 1) add ability to specify explicit highlighting in the config-file itself (directly with the item)
|
163
186
|
# - item.highlight_on :controller => 'users', :action => 'show' ...^
|
164
187
|
# --> with that we can get rid of the controller_methods...
|
@@ -282,13 +282,10 @@ describe SimpleNavigation::ItemContainer do
|
|
282
282
|
@item_container.item('key', 'name', 'url', @options)
|
283
283
|
end
|
284
284
|
end
|
285
|
-
|
285
|
+
|
286
286
|
end
|
287
|
-
|
288
287
|
end
|
289
|
-
|
290
288
|
end
|
291
|
-
|
292
289
|
end
|
293
290
|
|
294
291
|
describe '[]' do
|
@@ -309,23 +306,51 @@ describe SimpleNavigation::ItemContainer do
|
|
309
306
|
|
310
307
|
describe 'render' do
|
311
308
|
before(:each) do
|
312
|
-
@
|
313
|
-
@
|
314
|
-
@renderer.stub!(:new).and_return(@renderer_instance)
|
315
|
-
@item_container.stub!(:renderer).and_return(@renderer)
|
316
|
-
@items = stub(:items)
|
317
|
-
@item_container.stub!(:items).and_return(@items)
|
318
|
-
@options = stub(:options)
|
309
|
+
@renderer_instance = stub(:renderer, :null_object => true)
|
310
|
+
@renderer_class = stub(:renderer_class, :new => @renderer_instance)
|
319
311
|
end
|
320
|
-
|
321
|
-
|
322
|
-
|
312
|
+
context 'renderer specified as option' do
|
313
|
+
context 'renderer-class specified' do
|
314
|
+
it "should instantiate the passed renderer_class with the options" do
|
315
|
+
@renderer_class.should_receive(:new).with(:renderer => @renderer_class)
|
316
|
+
end
|
317
|
+
it "should call render on the renderer and pass self" do
|
318
|
+
@renderer_instance.should_receive(:render).with(@item_container)
|
319
|
+
end
|
320
|
+
after(:each) do
|
321
|
+
@item_container.render(:renderer => @renderer_class)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
context 'renderer-symbol specified' do
|
325
|
+
before(:each) do
|
326
|
+
SimpleNavigation.registered_renderers = {:my_renderer => @renderer_class}
|
327
|
+
end
|
328
|
+
it "should instantiate the passed renderer_class with the options" do
|
329
|
+
@renderer_class.should_receive(:new).with(:renderer => :my_renderer)
|
330
|
+
end
|
331
|
+
it "should call render on the renderer and pass self" do
|
332
|
+
@renderer_instance.should_receive(:render).with(@item_container)
|
333
|
+
end
|
334
|
+
after(:each) do
|
335
|
+
@item_container.render(:renderer => :my_renderer)
|
336
|
+
end
|
337
|
+
end
|
323
338
|
end
|
324
|
-
|
325
|
-
|
326
|
-
|
339
|
+
context 'no renderer specified' do
|
340
|
+
before(:each) do
|
341
|
+
@item_container.stub!(:renderer => @renderer_class)
|
342
|
+
@options = {}
|
343
|
+
end
|
344
|
+
it "should instantiate the container's renderer with the options" do
|
345
|
+
@renderer_class.should_receive(:new).with(@options)
|
346
|
+
end
|
347
|
+
it "should call render on the renderer and pass self" do
|
348
|
+
@renderer_instance.should_receive(:render).with(@item_container)
|
349
|
+
end
|
350
|
+
after(:each) do
|
351
|
+
@item_container.render(@options)
|
352
|
+
end
|
327
353
|
end
|
328
|
-
|
329
354
|
end
|
330
355
|
|
331
356
|
describe 'level_for_item' do
|
@@ -347,8 +372,17 @@ describe SimpleNavigation::ItemContainer do
|
|
347
372
|
it {@item_container.level_for_item(:ss1).should == 3}
|
348
373
|
it {@item_container.level_for_item(:x).should be_nil}
|
349
374
|
|
350
|
-
|
351
|
-
|
375
|
+
end
|
376
|
+
|
377
|
+
describe 'empty?' do
|
378
|
+
it "should be empty if there are no items" do
|
379
|
+
@item_container.instance_variable_set(:@items, [])
|
380
|
+
@item_container.should be_empty
|
381
|
+
end
|
382
|
+
it "should not be empty if there are some items" do
|
383
|
+
@item_container.instance_variable_set(:@items, [stub(:item)])
|
384
|
+
@item_container.should_not be_empty
|
385
|
+
end
|
352
386
|
end
|
353
387
|
|
354
388
|
end
|
@@ -97,6 +97,29 @@ describe SimpleNavigation::Renderer::Base do
|
|
97
97
|
it {@base_renderer.expand_all?.should be_false}
|
98
98
|
end
|
99
99
|
end
|
100
|
+
|
101
|
+
describe 'skip_if_empty?' do
|
102
|
+
context 'option is set' do
|
103
|
+
context 'skip_if_empty is true' do
|
104
|
+
before(:each) do
|
105
|
+
@base_renderer.stub!(:options => {:skip_if_empty => true})
|
106
|
+
end
|
107
|
+
it {@base_renderer.skip_if_empty?.should be_true}
|
108
|
+
end
|
109
|
+
context 'skip_if_empty is false' do
|
110
|
+
before(:each) do
|
111
|
+
@base_renderer.stub!(:options => {:skip_if_empty => false})
|
112
|
+
end
|
113
|
+
it {@base_renderer.skip_if_empty?.should be_false}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context 'option is not set' do
|
117
|
+
before(:each) do
|
118
|
+
@base_renderer.stub!(:options => {})
|
119
|
+
end
|
120
|
+
it {@base_renderer.skip_if_empty?.should be_false}
|
121
|
+
end
|
122
|
+
end
|
100
123
|
|
101
124
|
describe 'level' do
|
102
125
|
context 'options[level] is set' do
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
require 'html/document' unless defined? HTML::Document
|
3
|
+
|
4
|
+
describe SimpleNavigation::Renderer::Breadcrumbs do
|
5
|
+
|
6
|
+
describe 'render' do
|
7
|
+
|
8
|
+
def render(current_nav=nil, options={:level => :all})
|
9
|
+
primary_navigation = primary_container
|
10
|
+
select_item(current_nav) if current_nav
|
11
|
+
@renderer = SimpleNavigation::Renderer::Breadcrumbs.new(options)
|
12
|
+
HTML::Document.new(@renderer.render(primary_navigation)).root
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'regarding result' do
|
16
|
+
|
17
|
+
it "should render a div-tag around the items" do
|
18
|
+
HTML::Selector.new('div').select(render).should have(1).entries
|
19
|
+
end
|
20
|
+
it "the rendered div-tag should have the specified dom_id" do
|
21
|
+
HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
|
22
|
+
end
|
23
|
+
it "the rendered div-tag should have the specified class" do
|
24
|
+
HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'without current_navigation set' do
|
28
|
+
it "should not render any a-tag in the div-tag" do
|
29
|
+
HTML::Selector.new('div a').select(render).should have(0).entries
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with current_navigation set' do
|
34
|
+
before :all do
|
35
|
+
@selection = HTML::Selector.new('div a').select(render(:invoices))
|
36
|
+
end
|
37
|
+
it "should render the selected a tags" do
|
38
|
+
@selection.should have(1).entries
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not render class or id" do
|
42
|
+
@selection.each do |tag|
|
43
|
+
raise unless tag.name == "a"
|
44
|
+
tag["id"].should be_nil
|
45
|
+
tag["class"].should be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
context 'nested sub_navigation' do
|
52
|
+
it "should add an a tag for each selected item" do
|
53
|
+
HTML::Selector.new('div a').select(render(:subnav1)).should have(2).entries
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'regarding method calls' do
|
59
|
+
|
60
|
+
context 'regarding the list_content' do
|
61
|
+
before(:each) do
|
62
|
+
@primary_navigation = primary_container
|
63
|
+
@list_content = stub(:list_content)
|
64
|
+
@list_items = stub(:list_items, :join => @list_content)
|
65
|
+
@items.stub!(:inject => @list_items)
|
66
|
+
@renderer = SimpleNavigation::Renderer::Breadcrumbs.new(options)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should join the list_items" do
|
70
|
+
@list_items.should_receive(:join)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should html_saferize the list_content" do
|
74
|
+
@renderer.should_receive(:html_safe).with(@list_content)
|
75
|
+
end
|
76
|
+
|
77
|
+
after(:each) do
|
78
|
+
@renderer.render(@primary_navigation)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'regarding the items' do
|
83
|
+
before(:each) do
|
84
|
+
@primary_navigation = primary_container
|
85
|
+
select_item(:invoices)
|
86
|
+
@renderer = SimpleNavigation::Renderer::Breadcrumbs.new(options)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should call html_safe on every rendered item's name" do
|
90
|
+
@items.each do |item|
|
91
|
+
@renderer.should_receive(:html_safe).with(item.name) if item.selected?
|
92
|
+
end
|
93
|
+
@renderer.should_receive(:html_safe).with(anything).twice()
|
94
|
+
@renderer.render(@primary_navigation)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -83,6 +83,46 @@ describe SimpleNavigation::Renderer::List do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
86
|
+
|
87
|
+
context 'skip_if_empty' do
|
88
|
+
|
89
|
+
def render_container(options={})
|
90
|
+
@renderer = SimpleNavigation::Renderer::List.new(options)
|
91
|
+
HTML::Document.new(@renderer.render(@container)).root
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'container is empty' do
|
95
|
+
before(:each) do
|
96
|
+
@container = SimpleNavigation::ItemContainer.new(0)
|
97
|
+
end
|
98
|
+
context 'skip_if_empty is true' do
|
99
|
+
it "should not render a ul tag for the empty container" do
|
100
|
+
HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should be_empty
|
101
|
+
end
|
102
|
+
end
|
103
|
+
context 'skip_if_empty is false' do
|
104
|
+
it "should render a ul tag for the empty container" do
|
105
|
+
HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'container is not empty' do
|
111
|
+
before(:each) do
|
112
|
+
@container = primary_container
|
113
|
+
end
|
114
|
+
context 'skip_if_empty is true' do
|
115
|
+
it "should render a ul tag for the container" do
|
116
|
+
HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should have(1).entry
|
117
|
+
end
|
118
|
+
end
|
119
|
+
context 'skip_if_empty is false' do
|
120
|
+
it "should render a ul tag for the container" do
|
121
|
+
HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
86
126
|
end
|
87
127
|
|
88
128
|
context 'regarding method calls' do
|
@@ -127,4 +167,4 @@ describe SimpleNavigation::Renderer::List do
|
|
127
167
|
end
|
128
168
|
|
129
169
|
end
|
130
|
-
end
|
170
|
+
end
|
@@ -204,6 +204,23 @@ describe SimpleNavigation do
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
207
|
+
|
208
|
+
describe 'regarding renderers' do
|
209
|
+
it "should have registered the builtin renderers by default" do
|
210
|
+
SimpleNavigation.registered_renderers.should_not be_empty
|
211
|
+
end
|
212
|
+
|
213
|
+
describe 'register_renderer' do
|
214
|
+
before(:each) do
|
215
|
+
@renderer = stub(:renderer)
|
216
|
+
end
|
217
|
+
it "should add the specified renderer to the list of renderers" do
|
218
|
+
SimpleNavigation.register_renderer(:my_renderer => @renderer)
|
219
|
+
SimpleNavigation.registered_renderers[:my_renderer].should == @renderer
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
207
224
|
|
208
225
|
|
209
226
|
describe 'load_config' do
|
data/spec/spec_helper.rb
CHANGED
@@ -53,7 +53,14 @@ def primary_item(key)
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def select_item(key)
|
56
|
-
|
56
|
+
if(key == :subnav1)
|
57
|
+
select_item(:invoices)
|
58
|
+
primary_item(:invoices) do |item|
|
59
|
+
item.instance_variable_get(:@sub_navigation).items.find { |i| i.key == key}.stub!(:selected? => true)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
primary_item(key) {|item| item.stub!(:selected? => true) unless item.frozen?}
|
57
64
|
end
|
58
65
|
|
59
66
|
def subnav_container
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 2.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 2.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andi Schacke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-19 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/simple_navigation/items_provider.rb
|
61
61
|
- lib/simple_navigation/railtie.rb
|
62
62
|
- lib/simple_navigation/renderer/base.rb
|
63
|
+
- lib/simple_navigation/renderer/breadcrumbs.rb
|
63
64
|
- lib/simple_navigation/renderer/links.rb
|
64
65
|
- lib/simple_navigation/renderer/list.rb
|
65
66
|
- rails/init.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- spec/lib/simple_navigation/item_spec.rb
|
72
73
|
- spec/lib/simple_navigation/items_provider_spec.rb
|
73
74
|
- spec/lib/simple_navigation/renderer/base_spec.rb
|
75
|
+
- spec/lib/simple_navigation/renderer/breadcrumbs_spec.rb
|
74
76
|
- spec/lib/simple_navigation/renderer/links_spec.rb
|
75
77
|
- spec/lib/simple_navigation/renderer/list_spec.rb
|
76
78
|
- spec/lib/simple_navigation_spec.rb
|
@@ -115,6 +117,7 @@ test_files:
|
|
115
117
|
- spec/lib/simple_navigation/item_spec.rb
|
116
118
|
- spec/lib/simple_navigation/items_provider_spec.rb
|
117
119
|
- spec/lib/simple_navigation/renderer/base_spec.rb
|
120
|
+
- spec/lib/simple_navigation/renderer/breadcrumbs_spec.rb
|
118
121
|
- spec/lib/simple_navigation/renderer/links_spec.rb
|
119
122
|
- spec/lib/simple_navigation/renderer/list_spec.rb
|
120
123
|
- spec/lib/simple_navigation_spec.rb
|