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.
- data/.editorconfig +14 -0
- data/.gitignore +2 -0
- data/.travis.yml +10 -2
- data/Appraisals +7 -0
- data/Gemfile +1 -1
- data/MIT-LICENSE +20 -0
- data/README.md +31 -20
- data/Rakefile +2 -1
- data/TODO +14 -0
- data/gemfiles/3.2.gemfile +7 -0
- data/gemfiles/3.2.gemfile.lock +112 -0
- data/gemfiles/4.0.gemfile +7 -0
- data/gemfiles/4.0.gemfile.lock +107 -0
- data/lib/generators/semantic_navigation/breadcrumb_renderer/templates/breadcrumb_renderer.rb +5 -5
- data/lib/generators/semantic_navigation/list_renderer/list_renderer_generator.rb +0 -1
- data/lib/generators/semantic_navigation/list_renderer/templates/list_renderer.rb +4 -4
- data/lib/semantic_navigation.rb +30 -0
- data/lib/semantic_navigation/configuration.rb +8 -9
- data/lib/semantic_navigation/core.rb +8 -6
- data/lib/semantic_navigation/core/leaf.rb +2 -2
- data/lib/semantic_navigation/core/mix_in/name_methods.rb +24 -0
- data/lib/semantic_navigation/core/mix_in/url_methods.rb +25 -0
- data/lib/semantic_navigation/core/navigation.rb +8 -2
- data/lib/semantic_navigation/core/node.rb +2 -2
- data/lib/semantic_navigation/deprecations/renderers/acts_as_breadcrumb.rb +14 -0
- data/lib/semantic_navigation/deprecations/renderers/acts_as_list.rb +12 -0
- data/lib/semantic_navigation/deprecations/renderers/render_helpers.rb +14 -0
- data/lib/semantic_navigation/helper_methods.rb +8 -4
- data/lib/semantic_navigation/railtie.rb +9 -19
- data/lib/semantic_navigation/renderers.rb +15 -8
- data/lib/semantic_navigation/renderers/bread_crumb.rb +6 -6
- data/lib/semantic_navigation/renderers/list.rb +6 -6
- data/lib/semantic_navigation/renderers/mix_in/acts_as_breadcrumb.rb +43 -0
- data/lib/semantic_navigation/renderers/mix_in/acts_as_list.rb +49 -0
- data/lib/semantic_navigation/renderers/mix_in/render_helpers.rb +110 -0
- data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +5 -5
- data/lib/semantic_navigation/twitter_bootstrap/list.rb +2 -2
- data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +2 -2
- data/lib/semantic_navigation/version.rb +1 -1
- data/semantic_navigation.gemspec +3 -2
- data/spec/lib/semantic_navigation/configuration_spec.rb +29 -24
- data/spec/lib/semantic_navigation/core/leaf_spec.rb +121 -114
- data/spec/lib/semantic_navigation/core/navigation_spec.rb +81 -76
- data/spec/lib/semantic_navigation/core/node_spec.rb +52 -49
- data/spec/lib/semantic_navigation/helper_methods_spec.rb +47 -42
- data/spec/lib/semantic_navigation/renderers/bread_crumb_spec.rb +191 -187
- data/spec/lib/semantic_navigation/renderers/deprecations_spec.rb +67 -0
- data/spec/lib/semantic_navigation/renderers/list_spec.rb +260 -258
- data/spec/lib/semantic_navigation/twitter_bootstrap/breadcrumb_spec.rb +163 -159
- data/spec/lib/semantic_navigation/twitter_bootstrap/list_spec.rb +263 -262
- data/spec/lib/semantic_navigation/twitter_bootstrap/tabs_spec.rb +269 -266
- data/spec/spec_helper.rb +6 -0
- metadata +41 -13
- data/gemfiles/rails3 +0 -7
- data/lib/semantic_navigation/core/name_methods.rb +0 -24
- data/lib/semantic_navigation/core/url_methods.rb +0 -24
- data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +0 -42
- data/lib/semantic_navigation/renderers/acts_as_list.rb +0 -48
- data/lib/semantic_navigation/renderers/render_helpers.rb +0 -109
@@ -1,8 +1,8 @@
|
|
1
1
|
class Renderers::<%= class_name %>
|
2
2
|
#Default render helpers. Do not delete this if don't want to write your own.
|
3
|
-
include SemanticNavigation::Renderers::RenderHelpers
|
3
|
+
include SemanticNavigation::Renderers::MixIn::RenderHelpers
|
4
4
|
#The default list rendering logic. Do not delete if don't want to write your own.
|
5
|
-
include SemanticNavigation::Renderers::ActsAsList
|
5
|
+
include SemanticNavigation::Renderers::MixIn::ActsAsList
|
6
6
|
|
7
7
|
#Default navigation classes
|
8
8
|
navigation_active_class [:active]
|
@@ -53,7 +53,7 @@ class Renderers::<%= class_name %>
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
#Navigation leaf block
|
56
|
+
#Navigation leaf block
|
57
57
|
def leaf(object)
|
58
58
|
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
59
59
|
:class => merge_classes(:leaf, object.active, object.classes) do
|
@@ -61,4 +61,4 @@ class Renderers::<%= class_name %>
|
|
61
61
|
:class => merge_classes(:link, object.active, object.link_classes)
|
62
62
|
end
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
data/lib/semantic_navigation.rb
CHANGED
@@ -4,3 +4,33 @@ require 'semantic_navigation/renderers'
|
|
4
4
|
require "semantic_navigation/configuration"
|
5
5
|
require 'semantic_navigation/railtie' if defined?(Rails)
|
6
6
|
|
7
|
+
module SemanticNavigation
|
8
|
+
def self.deprecation_message(type, deprecated_object, new_object, action = nil)
|
9
|
+
if SemanticNavigation::Configuration.display_deprecation_messages
|
10
|
+
message = ["DEPRECATION WARNING:",
|
11
|
+
"You are using deprecated #{type} `#{deprecated_object}`"]
|
12
|
+
if action
|
13
|
+
message[-1] += " for #{action}."
|
14
|
+
else
|
15
|
+
message[-1] += '.'
|
16
|
+
end
|
17
|
+
message += ["That #{type} will be depreacted soon.",
|
18
|
+
"Please use `#{new_object}` instead."]
|
19
|
+
puts message.join("\n")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.actual_config_location
|
24
|
+
locations = ["#{Rails.root}/config/initializers/semantic_navigation.rb",
|
25
|
+
"#{Rails.root}/config/semantic_navigation.rb"]
|
26
|
+
actual_location = locations.find{|l| File.exists?(l)}
|
27
|
+
raise ["Please create a semantic_navigation configuration",
|
28
|
+
"(rails g semantic_navigation:install)",
|
29
|
+
"file before starting the project!"].join(" ") unless actual_location
|
30
|
+
puts "DEPRECATION WARNING: Please move the configuration file from #{locations.second}
|
31
|
+
to #{locations.first}! Current configuration file path will be deprecated soon!" if locations.find_index(actual_location) == 1
|
32
|
+
actual_location
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -1,11 +1,18 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
@@view_object = nil
|
5
4
|
@@navigations = {}
|
6
5
|
@@renderers = {}
|
7
6
|
@@render_styles = {}
|
8
7
|
|
8
|
+
cattr_accessor :view_object do
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
cattr_accessor :display_deprecation_messages do
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
9
16
|
def self.run(&block)
|
10
17
|
self.class_eval &block if block_given?
|
11
18
|
end
|
@@ -52,14 +59,6 @@ module SemanticNavigation
|
|
52
59
|
"
|
53
60
|
end
|
54
61
|
|
55
|
-
def self.view_object
|
56
|
-
@@view_object
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.view_object=(view_object)
|
60
|
-
@@view_object = view_object
|
61
|
-
end
|
62
|
-
|
63
62
|
def self.navigation(name)
|
64
63
|
@@navigations[name]
|
65
64
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
%w(
|
2
|
+
base
|
3
|
+
mix_in/url_methods
|
4
|
+
mix_in/name_methods
|
5
|
+
navigation
|
6
|
+
leaf
|
7
|
+
node
|
8
|
+
).each do |file|
|
7
9
|
require "semantic_navigation/core/#{file}"
|
8
10
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Core
|
3
|
+
module MixIn
|
4
|
+
module NameMethods
|
5
|
+
def name(renderer_name = nil)
|
6
|
+
rendering_name = @name
|
7
|
+
rendering_name = rendering_name[renderer_name.to_sym] || rendering_name[:default] if rendering_name.is_a?(Hash)
|
8
|
+
rendering_name = view_object.instance_eval(&rendering_name).to_s if rendering_name.is_a?(Proc)
|
9
|
+
rendering_name || i18n_name(renderer_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def i18n_name(renderer_name = nil)
|
15
|
+
name = I18n.t("#{@i18n_name}.#{@id}", :default => '')
|
16
|
+
if name.is_a? Hash
|
17
|
+
name = name[renderer_name.to_sym] || name[:default]
|
18
|
+
end
|
19
|
+
name || ''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Core
|
3
|
+
module MixIn
|
4
|
+
module UrlMethods
|
5
|
+
|
6
|
+
def url
|
7
|
+
urls.first
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def urls
|
13
|
+
[@url].flatten(1).map do |url|
|
14
|
+
if url.is_a?(Proc)
|
15
|
+
view_object.instance_eval(&url) rescue ''
|
16
|
+
else
|
17
|
+
url
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -29,9 +29,15 @@ module SemanticNavigation
|
|
29
29
|
#Deprecation warning message
|
30
30
|
#TODO:Should be deleted after moving the header and divider definition via item
|
31
31
|
if element.url.nil? && !element.name.empty?
|
32
|
-
|
32
|
+
SemanticNavigation.deprecation_message(:method,
|
33
|
+
'item',
|
34
|
+
'header',
|
35
|
+
'header definition')
|
33
36
|
elsif element.url.nil? && element.name.empty?
|
34
|
-
|
37
|
+
SemanticNavigation.deprecation_message(:method,
|
38
|
+
'item',
|
39
|
+
'header',
|
40
|
+
'divider definition')
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module ActsAsBreadcrumb
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
SemanticNavigation.deprecation_message(:module,
|
7
|
+
"SemanticNavigation::Renderers::ActsAsBreadcrumb",
|
8
|
+
"SemanticNavigation::Renderers::MixIn::ActsAsBreadcrumb")
|
9
|
+
base.send :include, SemanticNavigation::Renderers::MixIn::ActsAsBreadcrumb
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module ActsAsList
|
4
|
+
def self.included(base)
|
5
|
+
SemanticNavigation.deprecation_message(:module,
|
6
|
+
"SemanticNavigation::Renderers::ActsAsList",
|
7
|
+
"SemanticNavigation::Renderers::MixIn::ActsAsList")
|
8
|
+
base.send :include, SemanticNavigation::Renderers::MixIn::ActsAsList
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module RenderHelpers
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
SemanticNavigation.deprecation_message(:module,
|
7
|
+
"SemanticNavigation::Renderers::RenderHelpers",
|
8
|
+
"SemanticNavigation::Renderers::MixIn::RenderHelpers")
|
9
|
+
base.send :include, SemanticNavigation::Renderers::MixIn::RenderHelpers
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -5,17 +5,21 @@ module SemanticNavigation::HelperMethods
|
|
5
5
|
render_name ||= :list
|
6
6
|
SemanticNavigation::Configuration.new.render(name, render_name, options, self)
|
7
7
|
end
|
8
|
-
|
9
|
-
def active_item_for(name, level = nil)
|
8
|
+
|
9
|
+
def active_item_for(name, level = nil, &block)
|
10
10
|
SemanticNavigation::Configuration.view_object = self
|
11
11
|
navigation = SemanticNavigation::Configuration.navigation(name)
|
12
12
|
navigation.mark_active
|
13
13
|
item = navigation
|
14
14
|
while !item.is_a?(SemanticNavigation::Core::Leaf) &&
|
15
|
-
!item.sub_elements.find{|e| e.active}.nil? &&
|
15
|
+
!item.sub_elements.find{|e| e.active}.nil? &&
|
16
16
|
(!level.nil? ? item.level < level : true)
|
17
17
|
item = item.sub_elements.find{|e| e.active}
|
18
18
|
end
|
19
|
-
|
19
|
+
if !block_given?
|
20
|
+
item != navigation ? item.name(:active_item_for) : ''
|
21
|
+
else
|
22
|
+
capture(item, &block)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
@@ -25,25 +25,15 @@ module SemanticNavigation
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if Rails.env == "production"
|
39
|
-
config.after_initialize {
|
40
|
-
load SemanticNavigation::Railtie.actual_config_location
|
41
|
-
}
|
42
|
-
else
|
43
|
-
ActionDispatch::Callbacks.before {
|
44
|
-
load SemanticNavigation::Railtie.actual_config_location
|
45
|
-
}
|
46
|
-
end
|
28
|
+
if Rails.env == "production"
|
29
|
+
config.after_initialize {
|
30
|
+
load SemanticNavigation.actual_config_location
|
31
|
+
}
|
32
|
+
else
|
33
|
+
ActionDispatch::Callbacks.before {
|
34
|
+
load SemanticNavigation.actual_config_location
|
35
|
+
}
|
36
|
+
end
|
47
37
|
|
48
38
|
end
|
49
39
|
end
|
@@ -1,8 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
%w(
|
2
|
+
renderers/mix_in/render_helpers
|
3
|
+
renderers/mix_in/acts_as_list
|
4
|
+
renderers/mix_in/acts_as_breadcrumb
|
5
|
+
deprecations/renderers/render_helpers
|
6
|
+
deprecations/renderers/acts_as_breadcrumb
|
7
|
+
deprecations/renderers/acts_as_list
|
8
|
+
renderers/list
|
9
|
+
renderers/bread_crumb
|
10
|
+
twitter_bootstrap/breadcrumb
|
11
|
+
twitter_bootstrap/list
|
12
|
+
twitter_bootstrap/tabs
|
13
|
+
).each do |file|
|
14
|
+
require "semantic_navigation/#{file}"
|
15
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
module Renderers
|
3
3
|
class BreadCrumb
|
4
|
-
include RenderHelpers
|
5
|
-
include ActsAsBreadcrumb
|
4
|
+
include MixIn::RenderHelpers
|
5
|
+
include MixIn::ActsAsBreadcrumb
|
6
6
|
|
7
7
|
style_accessor last_as_link: false,
|
8
8
|
breadcrumb_separator: '/'
|
@@ -27,8 +27,8 @@ module SemanticNavigation
|
|
27
27
|
content_tag(:li, nil, {id: show_id(:leaf, object.id),
|
28
28
|
class: merge_classes(:leaf, object.active, object.classes)
|
29
29
|
}.merge(object.html)) do
|
30
|
-
link_to(object_name(object),
|
31
|
-
object.url,
|
30
|
+
link_to(object_name(object),
|
31
|
+
object.url,
|
32
32
|
{id: show_id(:link, object.id),
|
33
33
|
class: merge_classes(:link, object.active, object.link_classes)
|
34
34
|
}.merge(object.link_html))
|
@@ -44,8 +44,8 @@ module SemanticNavigation
|
|
44
44
|
class: merge_classes(:leaf, object.active, object.classes)
|
45
45
|
}.merge(object.html) do
|
46
46
|
if last_as_link
|
47
|
-
link_to object_name(object),
|
48
|
-
object.url,
|
47
|
+
link_to object_name(object),
|
48
|
+
object.url,
|
49
49
|
{id: show_id(:link, object.id),
|
50
50
|
class: merge_classes(:link, object.active, object.link_classes)
|
51
51
|
}.merge(object.link_html)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
module Renderers
|
3
3
|
class List
|
4
|
-
include RenderHelpers
|
5
|
-
include ActsAsList
|
4
|
+
include MixIn::RenderHelpers
|
5
|
+
include MixIn::ActsAsList
|
6
6
|
|
7
7
|
navigation_default_classes [:list]
|
8
8
|
|
@@ -20,8 +20,8 @@ module SemanticNavigation
|
|
20
20
|
content_tag :li, nil, {id: show_id(:leaf, object.id),
|
21
21
|
class: merge_classes(:leaf, object.active, object.classes)
|
22
22
|
}.merge(object.html) do
|
23
|
-
link_to(object_name(object),
|
24
|
-
object.url,
|
23
|
+
link_to(object_name(object),
|
24
|
+
object.url,
|
25
25
|
{id: show_id(:link, object.id),
|
26
26
|
class: merge_classes(:link, object.active, object.link_classes)
|
27
27
|
}.merge(object.link_html))+
|
@@ -41,8 +41,8 @@ module SemanticNavigation
|
|
41
41
|
content_tag :li, nil, {id: show_id(:leaf, object.id),
|
42
42
|
class: merge_classes(:leaf, object.active, object.classes)
|
43
43
|
}.merge(object.html) do
|
44
|
-
link_to object_name(object),
|
45
|
-
object.url,
|
44
|
+
link_to object_name(object),
|
45
|
+
object.url,
|
46
46
|
{id: show_id(:link, object.id),
|
47
47
|
class: merge_classes(:link, object.active, object.link_classes)
|
48
48
|
}.merge(object.link_html)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module MixIn
|
4
|
+
module ActsAsBreadcrumb
|
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(&:active)
|
12
|
+
end
|
13
|
+
unless object.class.in?([SemanticNavigation::Core::Leaf, NilClass])
|
14
|
+
active_element = object.sub_elements.find{|e| e.active}
|
15
|
+
active_element.render(self) if active_element
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_node(object)
|
21
|
+
active_element = object.sub_elements.find{|e| e.active}
|
22
|
+
if active_element && !active_element.id.in?([except_for].flatten) && active_element.render_if
|
23
|
+
render_element = active_element.render(self)
|
24
|
+
end
|
25
|
+
if render_element
|
26
|
+
node(object) do
|
27
|
+
render_element
|
28
|
+
end
|
29
|
+
else
|
30
|
+
render_leaf(object)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_leaf(object)
|
35
|
+
show = !until_level.nil? ? object.level <= until_level+1 : true
|
36
|
+
return nil unless show
|
37
|
+
|
38
|
+
leaf(object)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|