simple-navigation 3.12.0 → 3.12.1
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 +4 -0
- data/generators/navigation_config/navigation_config_generator.rb +3 -3
- data/generators/navigation_config/templates/config/navigation.rb +9 -10
- data/init.rb +1 -1
- data/lib/generators/navigation_config/navigation_config_generator.rb +11 -6
- data/lib/simple-navigation.rb +1 -1
- data/lib/simple_navigation.rb +93 -65
- data/lib/simple_navigation/adapters/base.rb +16 -16
- data/lib/simple_navigation/adapters/nanoc.rb +7 -6
- data/lib/simple_navigation/adapters/padrino.rb +5 -7
- data/lib/simple_navigation/adapters/rails.rb +52 -39
- data/lib/simple_navigation/adapters/sinatra.rb +14 -17
- data/lib/simple_navigation/core/configuration.rb +73 -34
- data/lib/simple_navigation/core/item.rb +110 -54
- data/lib/simple_navigation/core/item_adapter.rb +18 -13
- data/lib/simple_navigation/core/item_container.rb +93 -66
- data/lib/simple_navigation/core/items_provider.rb +12 -10
- data/lib/simple_navigation/rails_controller_methods.rb +98 -78
- data/lib/simple_navigation/rendering/helpers.rb +130 -68
- data/lib/simple_navigation/rendering/renderer/base.rb +30 -25
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +26 -19
- data/lib/simple_navigation/rendering/renderer/json.rb +11 -13
- data/lib/simple_navigation/rendering/renderer/links.rb +18 -13
- data/lib/simple_navigation/rendering/renderer/list.rb +28 -15
- data/lib/simple_navigation/rendering/renderer/text.rb +7 -12
- data/lib/simple_navigation/version.rb +1 -1
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +1 -1
- data/spec/lib/simple_navigation/core/item_container_spec.rb +118 -68
- data/spec/lib/simple_navigation_spec.rb +16 -5
- metadata +2 -2
@@ -1,20 +1,18 @@
|
|
1
1
|
module SimpleNavigation
|
2
2
|
module Adapters
|
3
3
|
class Padrino < Sinatra
|
4
|
-
|
5
4
|
def self.register
|
6
5
|
SimpleNavigation.set_env(PADRINO_ROOT, PADRINO_ENV)
|
7
6
|
::Padrino::Application.send(:helpers, SimpleNavigation::Helpers)
|
8
7
|
end
|
9
|
-
|
10
|
-
def link_to(name, url, options={})
|
8
|
+
|
9
|
+
def link_to(name, url, options = {})
|
11
10
|
context.link_to(name, url, options)
|
12
11
|
end
|
13
|
-
|
14
|
-
def content_tag(type, content, options={})
|
12
|
+
|
13
|
+
def content_tag(type, content, options = {})
|
15
14
|
context.content_tag(type, content.html_safe, options)
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
20
|
-
end
|
18
|
+
end
|
@@ -1,97 +1,110 @@
|
|
1
1
|
module SimpleNavigation
|
2
2
|
module Adapters
|
3
3
|
class Rails < Base
|
4
|
-
|
5
4
|
attr_reader :controller, :template
|
6
5
|
|
7
6
|
def self.register
|
8
|
-
SimpleNavigation.set_env(rails_root, rails_env)
|
7
|
+
SimpleNavigation.set_env(rails_root, rails_env)
|
9
8
|
ActionController::Base.send(:include, SimpleNavigation::Helpers)
|
10
9
|
SimpleNavigation::Helpers.instance_methods.each do |m|
|
11
10
|
ActionController::Base.send(:helper_method, m.to_sym)
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
def initialize(context)
|
16
15
|
@controller = extract_controller_from context
|
17
16
|
@template = template_from @controller
|
18
17
|
@request = @template.request if @template
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
def request_uri
|
22
21
|
return '' unless request
|
23
|
-
|
24
|
-
request.
|
22
|
+
|
23
|
+
if request.respond_to?(:fullpath)
|
24
|
+
request.fullpath
|
25
|
+
else
|
26
|
+
request.request_uri
|
27
|
+
end
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
def request_path
|
28
|
-
|
29
|
-
request.path
|
31
|
+
request ? request.path : ''
|
30
32
|
end
|
31
|
-
|
33
|
+
|
32
34
|
def context_for_eval
|
33
|
-
|
34
|
-
|
35
|
+
template ||
|
36
|
+
controller ||
|
37
|
+
fail('no context set for evaluation the config file')
|
35
38
|
end
|
36
|
-
|
39
|
+
|
37
40
|
def current_page?(url)
|
38
|
-
template.current_page?(url)
|
41
|
+
template && template.current_page?(url)
|
39
42
|
end
|
40
|
-
|
41
|
-
def link_to(name, url, options={})
|
42
|
-
template.link_to(link_title(name), url, options)
|
43
|
+
|
44
|
+
def link_to(name, url, options = {})
|
45
|
+
template && template.link_to(link_title(name), url, options)
|
43
46
|
end
|
44
|
-
|
45
|
-
def content_tag(type, content, options={})
|
46
|
-
template.content_tag(type, html_safe(content), options)
|
47
|
+
|
48
|
+
def content_tag(type, content, options = {})
|
49
|
+
template && template.content_tag(type, html_safe(content), options)
|
47
50
|
end
|
48
|
-
|
51
|
+
|
49
52
|
protected
|
50
|
-
|
53
|
+
|
51
54
|
def self.rails_root
|
52
55
|
gte_rails3? ? ::Rails.root : ::RAILS_ROOT
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
def self.rails_env
|
56
59
|
gte_rails3? ? ::Rails.env : ::RAILS_ENV
|
57
60
|
end
|
58
|
-
|
61
|
+
|
59
62
|
def self.gte_rails3?
|
60
63
|
::Rails::VERSION::MAJOR >= 3
|
61
64
|
end
|
62
|
-
|
65
|
+
|
63
66
|
def template_from(controller)
|
64
|
-
controller.respond_to?(:view_context)
|
67
|
+
if controller.respond_to?(:view_context)
|
68
|
+
controller.view_context
|
69
|
+
else
|
70
|
+
controller.instance_variable_get(:@template)
|
71
|
+
end
|
65
72
|
end
|
66
|
-
|
67
|
-
# Marks the specified input as html_safe (for Rails3).
|
73
|
+
|
74
|
+
# Marks the specified input as html_safe (for Rails3).
|
75
|
+
# Does nothing if html_safe is not defined on input.
|
68
76
|
#
|
69
77
|
def html_safe(input)
|
70
78
|
input.respond_to?(:html_safe) ? input.html_safe : input
|
71
79
|
end
|
72
|
-
|
80
|
+
|
73
81
|
# Extracts a controller from the context.
|
74
82
|
def extract_controller_from(context)
|
75
|
-
context.respond_to?(:controller)
|
76
|
-
context.controller || context
|
83
|
+
if context.respond_to?(:controller)
|
84
|
+
context.controller || context
|
85
|
+
else
|
77
86
|
context
|
87
|
+
end
|
78
88
|
end
|
79
89
|
|
80
|
-
def link_title
|
81
|
-
SimpleNavigation.config.consider_item_names_as_safe
|
90
|
+
def link_title(name)
|
91
|
+
if SimpleNavigation.config.consider_item_names_as_safe
|
92
|
+
html_safe(name)
|
93
|
+
else
|
94
|
+
name
|
95
|
+
end
|
82
96
|
end
|
83
|
-
|
84
97
|
end
|
85
98
|
end
|
86
99
|
end
|
87
100
|
|
88
101
|
# Initializer for Rails3
|
89
102
|
if defined?(Rails) && SimpleNavigation::Adapters::Rails.gte_rails3?
|
90
|
-
module SimpleNavigation
|
91
|
-
class Railtie < Rails::Railtie
|
92
|
-
initializer
|
103
|
+
module SimpleNavigation
|
104
|
+
class Railtie < Rails::Railtie
|
105
|
+
initializer 'simple_navigation.register' do |app|
|
93
106
|
SimpleNavigation.register
|
94
|
-
end
|
95
|
-
end
|
107
|
+
end
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
@@ -3,7 +3,6 @@ require 'cgi'
|
|
3
3
|
module SimpleNavigation
|
4
4
|
module Adapters
|
5
5
|
class Sinatra < Base
|
6
|
-
|
7
6
|
def self.register
|
8
7
|
SimpleNavigation.set_env(sinatra_root, sinatra_environment)
|
9
8
|
::Sinatra::Application.send(:helpers, SimpleNavigation::Helpers)
|
@@ -15,8 +14,7 @@ module SimpleNavigation
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def context_for_eval
|
18
|
-
|
19
|
-
context
|
17
|
+
context || fail('no context set for evaluation the config file')
|
20
18
|
end
|
21
19
|
|
22
20
|
def request_uri
|
@@ -29,24 +27,24 @@ module SimpleNavigation
|
|
29
27
|
|
30
28
|
def current_page?(url)
|
31
29
|
url_string = CGI.unescape(url)
|
32
|
-
if url_string.index(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if url_string =~
|
39
|
-
|
40
|
-
else
|
41
|
-
url_string == uri
|
30
|
+
uri = if url_string.index('?')
|
31
|
+
request_uri
|
32
|
+
else
|
33
|
+
request_uri.split('?').first
|
34
|
+
end
|
35
|
+
|
36
|
+
if url_string =~ %r(^\w+://)
|
37
|
+
uri = "#{request.scheme}://#{request.host_with_port}#{uri}"
|
42
38
|
end
|
39
|
+
|
40
|
+
url_string == CGI.unescape(uri)
|
43
41
|
end
|
44
42
|
|
45
|
-
def link_to(name, url, options={})
|
43
|
+
def link_to(name, url, options = {})
|
46
44
|
"<a href='#{url}'#{to_attributes(options)}>#{name}</a>"
|
47
45
|
end
|
48
46
|
|
49
|
-
def content_tag(type, content, options={})
|
47
|
+
def content_tag(type, content, options = {})
|
50
48
|
"<#{type}#{to_attributes(options)}>#{content}</#{type}>"
|
51
49
|
end
|
52
50
|
|
@@ -61,9 +59,8 @@ module SimpleNavigation
|
|
61
59
|
end
|
62
60
|
|
63
61
|
def to_attributes(options)
|
64
|
-
options.map {|k, v| v.nil? ? '' : " #{k}='#{v}'"}.join
|
62
|
+
options.map { |k, v| v.nil? ? '' : " #{k}='#{v}'" }.join
|
65
63
|
end
|
66
|
-
|
67
64
|
end
|
68
65
|
end
|
69
66
|
end
|
@@ -1,47 +1,65 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
|
3
3
|
module SimpleNavigation
|
4
|
-
|
5
4
|
# Responsible for evaluating and handling the config/navigation.rb file.
|
6
5
|
class Configuration
|
7
6
|
include Singleton
|
8
7
|
|
9
|
-
attr_accessor :
|
10
|
-
|
8
|
+
attr_accessor :autogenerate_item_ids,
|
9
|
+
:auto_highlight,
|
10
|
+
:consider_item_names_as_safe
|
11
11
|
|
12
|
-
|
12
|
+
attr_reader :primary_navigation
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
attr_writer :active_leaf_class,
|
15
|
+
:id_generator,
|
16
|
+
:name_generator,
|
17
|
+
:renderer,
|
18
|
+
:selected_class
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
# Evals the config_file for the given navigation_context
|
21
|
+
def self.eval_config(navigation_context = :default)
|
22
|
+
context = SimpleNavigation.config_files[navigation_context]
|
23
|
+
SimpleNavigation.context_for_eval.instance_eval(context)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
26
|
+
# Starts processing the configuration
|
27
|
+
def self.run(&block)
|
28
|
+
block.call Configuration.instance
|
29
|
+
end
|
25
30
|
|
26
31
|
# Sets the config's default-settings
|
27
32
|
def initialize
|
28
|
-
@renderer = SimpleNavigation.default_renderer || SimpleNavigation::Renderer::List
|
29
|
-
@selected_class = 'selected'
|
30
|
-
@active_leaf_class = 'simple-navigation-active-leaf'
|
31
33
|
@autogenerate_item_ids = true
|
32
|
-
@id_generator = Proc.new {|id| id.to_s }
|
33
|
-
@name_generator = Proc.new {|name| name}
|
34
34
|
@auto_highlight = true
|
35
35
|
@consider_item_names_as_safe = true
|
36
|
+
|
36
37
|
if defined?(ActiveSupport::Deprecation)
|
37
|
-
ActiveSupport::Deprecation.warn
|
38
|
+
ActiveSupport::Deprecation.warn 'simple-navigation: ' \
|
39
|
+
'consider_item_names_as_safe will be set to false ' \
|
40
|
+
'by default in 3.13.0 release, hence item names ' \
|
41
|
+
'will be considered unsafe by default. ' \
|
42
|
+
'See https://github.com/codeplant/simple-navigation/wiki',
|
43
|
+
caller
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
|
-
|
47
|
+
def active_leaf_class
|
48
|
+
@active_leaf_class ||= 'simple-navigation-active-leaf'
|
49
|
+
end
|
50
|
+
|
51
|
+
def id_generator
|
52
|
+
@id_generator ||= :to_s.to_proc
|
53
|
+
end
|
54
|
+
|
55
|
+
# This is the main method for specifying the navigation items.
|
56
|
+
# It can be used in two ways:
|
42
57
|
#
|
43
|
-
# 1. Declaratively specify your items in the config/navigation.rb file
|
44
|
-
#
|
58
|
+
# 1. Declaratively specify your items in the config/navigation.rb file
|
59
|
+
# using a block. It then yields an SimpleNavigation::ItemContainer
|
60
|
+
# for adding navigation items.
|
61
|
+
# 2. Directly provide your items to the method (e.g. when loading your
|
62
|
+
# items from the database).
|
45
63
|
#
|
46
64
|
# ==== Example for block style (configuration file)
|
47
65
|
# config.items do |primary|
|
@@ -51,26 +69,47 @@ module SimpleNavigation
|
|
51
69
|
#
|
52
70
|
# ==== To consider when directly providing items
|
53
71
|
# items_provider should be:
|
54
|
-
# * a methodname (as symbol) that returns your items. The method needs to
|
72
|
+
# * a methodname (as symbol) that returns your items. The method needs to
|
73
|
+
# be available in the view (i.e. a helper method)
|
55
74
|
# * an object that responds to :items
|
56
75
|
# * an enumerable containing your items
|
57
|
-
# The items you specify have to fullfill certain requirements.
|
76
|
+
# The items you specify have to fullfill certain requirements.
|
77
|
+
# See SimpleNavigation::ItemAdapter for more details.
|
58
78
|
#
|
59
|
-
def items(items_provider=nil, &block)
|
60
|
-
|
61
|
-
|
79
|
+
def items(items_provider = nil, &block)
|
80
|
+
if (items_provider && block) || (items_provider.nil? && block.nil?)
|
81
|
+
fail('please specify either items_provider or block, but not both')
|
82
|
+
end
|
83
|
+
|
84
|
+
self.primary_navigation = ItemContainer.new
|
85
|
+
|
62
86
|
if block
|
63
|
-
block.call
|
87
|
+
block.call primary_navigation
|
64
88
|
else
|
65
|
-
|
89
|
+
primary_navigation.items = ItemsProvider.new(items_provider).items
|
66
90
|
end
|
67
91
|
end
|
68
92
|
|
69
93
|
# Returns true if the config_file has already been evaluated.
|
70
94
|
def loaded?
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
|
95
|
+
!primary_navigation.nil?
|
96
|
+
end
|
97
|
+
|
98
|
+
def name_generator
|
99
|
+
@name_generator ||= proc { |name| name }
|
100
|
+
end
|
101
|
+
|
102
|
+
def renderer
|
103
|
+
@renderer ||= SimpleNavigation.default_renderer ||
|
104
|
+
SimpleNavigation::Renderer::List
|
105
|
+
end
|
106
|
+
|
107
|
+
def selected_class
|
108
|
+
@selected_class ||= 'selected'
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
attr_writer :primary_navigation
|
114
|
+
end
|
76
115
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
module SimpleNavigation
|
2
|
-
|
3
|
-
#
|
2
|
+
# Represents an item in your navigation.
|
3
|
+
# Gets generated by the item method in the config-file.
|
4
4
|
class Item
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :highlights_on,
|
6
|
+
:key,
|
7
|
+
:method,
|
8
|
+
:sub_navigation,
|
9
|
+
:url
|
10
|
+
|
6
11
|
attr_writer :html_options
|
7
12
|
|
8
13
|
# see ItemContainer#item
|
9
14
|
#
|
10
|
-
# The subnavigation (if any) is either provided by a block or
|
11
|
-
|
12
|
-
|
15
|
+
# The subnavigation (if any) is either provided by a block or
|
16
|
+
# passed in directly as <tt>items</tt>
|
17
|
+
def initialize(container, key, name, url_or_options = {}, options_or_nil = {}, items = nil, &sub_nav_block)
|
13
18
|
options = setup_url_and_options(url_or_options, options_or_nil)
|
14
|
-
|
15
|
-
@container.dom_id = options.delete(:container_id) if options[:container_id]
|
16
|
-
@container.dom_attributes = options[:container_attributes] ? options.delete(:container_attributes) : {}
|
17
|
-
@container.selected_class = options.delete(:selected_class) if options[:selected_class]
|
19
|
+
|
18
20
|
@key = key
|
19
21
|
@method = options.delete(:method)
|
20
22
|
@name = name
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@sub_navigation.items = items if items
|
25
|
-
end
|
23
|
+
@container = setup_container(container, options)
|
24
|
+
|
25
|
+
setup_sub_navigation(items, &sub_nav_block)
|
26
26
|
end
|
27
27
|
|
28
|
-
# Returns the item's name.
|
29
|
-
#
|
28
|
+
# Returns the item's name.
|
29
|
+
# If :apply_generator option is set to true (default),
|
30
|
+
# the name will be passed to the name_generator specified
|
31
|
+
# in the configuration.
|
30
32
|
#
|
31
33
|
def name(options = {})
|
32
|
-
options
|
34
|
+
options = { apply_generator: true }.merge(options)
|
33
35
|
if (options[:apply_generator])
|
34
36
|
SimpleNavigation.config.name_generator.call(@name, self)
|
35
37
|
else
|
@@ -45,34 +47,45 @@ module SimpleNavigation
|
|
45
47
|
# * its url matches the url of the current request (auto highlighting)
|
46
48
|
#
|
47
49
|
def selected?
|
48
|
-
@selected
|
50
|
+
@selected ||= selected_by_config? ||
|
51
|
+
selected_by_subnav? ||
|
52
|
+
selected_by_condition?
|
49
53
|
end
|
50
54
|
|
51
|
-
# Returns the html-options hash for the item, i.e. the options specified
|
55
|
+
# Returns the html-options hash for the item, i.e. the options specified
|
56
|
+
# for this item in the config-file.
|
52
57
|
# It also adds the 'selected' class to the list of classes if necessary.
|
53
58
|
def html_options
|
54
|
-
|
55
|
-
options
|
56
|
-
|
57
|
-
|
59
|
+
options = @html_options
|
60
|
+
options[:id] ||= autogenerated_item_id if autogenerate_item_ids?
|
61
|
+
|
62
|
+
classes = [@html_options[:class], selected_class, active_leaf_class]
|
63
|
+
classes = classes.flatten.compact.join(' ')
|
64
|
+
options[:class] = classes unless classes.nil? || classes.empty?
|
65
|
+
|
58
66
|
options
|
59
67
|
end
|
60
68
|
|
61
69
|
# Returns the configured active_leaf_class if the item is the selected leaf,
|
62
70
|
# nil otherwise
|
63
71
|
def active_leaf_class
|
64
|
-
!selected_by_subnav? && selected_by_condition?
|
72
|
+
if !selected_by_subnav? && selected_by_condition?
|
73
|
+
SimpleNavigation.config.active_leaf_class
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
# Returns the configured selected_class if the item is selected,
|
68
78
|
# nil otherwise
|
69
79
|
def selected_class
|
70
|
-
selected?
|
80
|
+
if selected?
|
81
|
+
container.selected_class || SimpleNavigation.config.selected_class
|
82
|
+
end
|
71
83
|
end
|
72
84
|
|
73
85
|
protected
|
74
86
|
|
75
|
-
# Returns true if item has a subnavigation and
|
87
|
+
# Returns true if item has a subnavigation and
|
88
|
+
# the sub_navigation is selected
|
76
89
|
def selected_by_subnav?
|
77
90
|
sub_navigation && sub_navigation.selected?
|
78
91
|
end
|
@@ -83,22 +96,7 @@ module SimpleNavigation
|
|
83
96
|
|
84
97
|
# Returns true if the item's url matches the request's current url.
|
85
98
|
def selected_by_condition?
|
86
|
-
|
87
|
-
case highlights_on
|
88
|
-
when Regexp
|
89
|
-
SimpleNavigation.request_uri =~ highlights_on
|
90
|
-
when Proc
|
91
|
-
highlights_on.call
|
92
|
-
when :subpath
|
93
|
-
!!(SimpleNavigation.request_uri =~ /^#{Regexp.escape url_without_anchor}(\/|$|\?)/i)
|
94
|
-
else
|
95
|
-
raise ArgumentError, ':highlights_on must be a Regexp, Proc or :subpath'
|
96
|
-
end
|
97
|
-
elsif auto_highlight?
|
98
|
-
!!(root_path_match? || (url_without_anchor && SimpleNavigation.current_page?(url_without_anchor)))
|
99
|
-
else
|
100
|
-
false
|
101
|
-
end
|
99
|
+
highlights_on ? selected_by_highlights_on? : selected_by_autohighlight?
|
102
100
|
end
|
103
101
|
|
104
102
|
# Returns true if both the item's url and the request's url are root_path
|
@@ -118,7 +116,7 @@ module SimpleNavigation
|
|
118
116
|
|
119
117
|
# Return true if auto_highlight is on for this item.
|
120
118
|
def auto_highlight?
|
121
|
-
SimpleNavigation.config.auto_highlight &&
|
119
|
+
SimpleNavigation.config.auto_highlight && container.auto_highlight
|
122
120
|
end
|
123
121
|
|
124
122
|
def url_without_anchor
|
@@ -126,20 +124,78 @@ module SimpleNavigation
|
|
126
124
|
end
|
127
125
|
|
128
126
|
private
|
127
|
+
|
128
|
+
attr_reader :container
|
129
|
+
|
130
|
+
attr_writer :highlights_on,
|
131
|
+
:sub_navigation,
|
132
|
+
:url
|
133
|
+
|
134
|
+
def selected_by_autohighlight?
|
135
|
+
auto_highlight? &&
|
136
|
+
(root_path_match? ||
|
137
|
+
(url_without_anchor &&
|
138
|
+
SimpleNavigation.current_page?(url_without_anchor)))
|
139
|
+
end
|
140
|
+
|
141
|
+
def selected_by_highlights_on?
|
142
|
+
return false unless highlights_on
|
143
|
+
|
144
|
+
case highlights_on
|
145
|
+
when Regexp then SimpleNavigation.request_uri =~ highlights_on
|
146
|
+
when Proc then highlights_on.call
|
147
|
+
when :subpath
|
148
|
+
escaped_url = Regexp.escape(url_without_anchor)
|
149
|
+
!!(SimpleNavigation.request_uri =~ /^#{escaped_url}(\/|$|\?)/i)
|
150
|
+
else
|
151
|
+
fail ArgumentError, ':highlights_on must be a Regexp, Proc or :subpath'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def setup_container(container, options = {})
|
156
|
+
if options[:container_class]
|
157
|
+
container.dom_class = options.delete(:container_class)
|
158
|
+
end
|
159
|
+
|
160
|
+
if options[:container_id]
|
161
|
+
container.dom_id = options.delete(:container_id)
|
162
|
+
end
|
163
|
+
|
164
|
+
container.dom_attributes = if options[:container_attributes]
|
165
|
+
options.delete(:container_attributes)
|
166
|
+
else
|
167
|
+
{}
|
168
|
+
end
|
169
|
+
|
170
|
+
if options[:selected_class]
|
171
|
+
container.selected_class = options.delete(:selected_class)
|
172
|
+
end
|
173
|
+
|
174
|
+
container
|
175
|
+
end
|
176
|
+
|
129
177
|
def setup_url_and_options(url_or_options, options_or_nil)
|
130
|
-
options = options_or_nil
|
131
|
-
url = url_or_options
|
132
178
|
case url_or_options
|
133
|
-
when Hash
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
179
|
+
when Hash then options = url_or_options # there is no url
|
180
|
+
when Proc then self.url = url_or_options.call
|
181
|
+
else self.url = url_or_options
|
182
|
+
end
|
183
|
+
|
184
|
+
options ||= options_or_nil
|
185
|
+
self.highlights_on = options.delete(:highlights_on)
|
186
|
+
self.html_options = options
|
187
|
+
end
|
188
|
+
|
189
|
+
def setup_sub_navigation(items = nil, &sub_nav_block)
|
190
|
+
return unless sub_nav_block || items
|
191
|
+
|
192
|
+
self.sub_navigation = ItemContainer.new(container.level + 1)
|
193
|
+
|
194
|
+
if sub_nav_block
|
195
|
+
sub_nav_block.call sub_navigation
|
138
196
|
else
|
139
|
-
|
197
|
+
sub_navigation.items = items
|
140
198
|
end
|
141
|
-
@highlights_on = options.delete(:highlights_on)
|
142
|
-
@html_options = options
|
143
199
|
end
|
144
200
|
end
|
145
201
|
end
|