semantic_navigation 0.0.6 → 0.0.8
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.md +10 -1
- data/README.md +33 -4
- data/Rakefile +3 -0
- data/lib/generators/semantic_navigation/install/install_generator.rb +20 -0
- data/lib/generators/semantic_navigation/install/templates/semantic_navigation.en.yml +2 -0
- data/lib/generators/semantic_navigation/install/templates/semantic_navigation.rb +25 -0
- data/lib/semantic_navigation.rb +2 -0
- data/lib/semantic_navigation/configuration.rb +52 -44
- data/lib/semantic_navigation/core.rb +4 -0
- data/lib/semantic_navigation/core/base.rb +21 -0
- data/lib/semantic_navigation/core/leaf.rb +25 -0
- data/lib/semantic_navigation/core/navigation.rb +35 -0
- data/lib/semantic_navigation/core/node.rb +29 -0
- data/lib/semantic_navigation/helper_methods.rb +14 -17
- data/lib/semantic_navigation/railtie.rb +14 -6
- data/lib/semantic_navigation/renderers.rb +8 -0
- data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +39 -0
- data/lib/semantic_navigation/renderers/acts_as_list.rb +46 -0
- data/lib/semantic_navigation/renderers/bread_crumb.rb +50 -0
- data/lib/semantic_navigation/renderers/list.rb +44 -0
- data/lib/semantic_navigation/renderers/render_helpers.rb +113 -0
- data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +58 -0
- data/lib/semantic_navigation/twitter_bootstrap/list.rb +76 -0
- data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +70 -0
- data/lib/semantic_navigation/version.rb +1 -1
- data/semantic_navigation.gemspec +3 -3
- data/spec/lib/semantic_navigation/configuration_spec.rb +55 -0
- data/spec/lib/semantic_navigation/custom_renderer.rb +3 -0
- data/spec/lib/semantic_navigation/helper_methods_spec.rb +1 -0
- data/spec/lib/semantic_navigation_spec.rb +1 -0
- data/spec/spec_helper.rb +8 -0
- metadata +32 -14
- data/lib/semantic_navigation/core/procs.rb +0 -15
- data/lib/semantic_navigation/core/render.rb +0 -94
- data/lib/semantic_navigation/item.rb +0 -118
- data/lib/tasks/semantic_navigation.rake +0 -8
- data/lib/tasks/templates/semantic_navigation.rb +0 -53
@@ -0,0 +1,46 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module ActsAsList
|
4
|
+
|
5
|
+
def render_navigation(object)
|
6
|
+
navigation(object) do
|
7
|
+
while !object.class.in?(SemanticNavigation::Core::Leaf, NilClass) &&
|
8
|
+
from_level.to_i > object.level
|
9
|
+
object = object.sub_elements.find{|e| e.active}
|
10
|
+
end
|
11
|
+
show = !until_level.nil? && !object.nil? ? object.level <= until_level : true
|
12
|
+
if !object.class.in?(SemanticNavigation::Core::Leaf, NilClass) && show
|
13
|
+
object.sub_elements.map{|element| element.render(self)}.compact.sum
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_node(object)
|
19
|
+
if !object.id.in?([except_for].flatten)
|
20
|
+
content = render_node_content(object)
|
21
|
+
if content
|
22
|
+
node(object) do
|
23
|
+
content
|
24
|
+
end
|
25
|
+
else
|
26
|
+
render_leaf(object)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_node_content(object)
|
32
|
+
if (!until_level.nil? && until_level >= object.level) || until_level.nil?
|
33
|
+
node_content(object) do
|
34
|
+
object.sub_elements.map{|element| element.render(self)}.compact.sum
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def render_leaf(object)
|
40
|
+
if !object.id.in?([except_for].flatten)
|
41
|
+
leaf(object)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
class BreadCrumb
|
4
|
+
include RenderHelpers
|
5
|
+
include ActsAsBreadcrumb
|
6
|
+
|
7
|
+
style_accessor :last_as_link => false,
|
8
|
+
:breadcrumb_separator => '/'
|
9
|
+
|
10
|
+
navigation_default_classes [:breadcrumb]
|
11
|
+
show_navigation_active_class false
|
12
|
+
show_node_active_class false
|
13
|
+
show_leaf_active_class false
|
14
|
+
show_link_active_class false
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def navigation(object)
|
19
|
+
content_tag :ul, nil, :id => show_id(:navigation, object.id),
|
20
|
+
:class => merge_classes(:navigation, object.active, object.classes) do
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def node(object)
|
26
|
+
content_tag(:li, nil, :id => show_id(:leaf, object.id),
|
27
|
+
:class => merge_classes(:leaf, object.active, object.classes)) do
|
28
|
+
link_to(object.name, object.url, :id => show_id(:link, object.id),
|
29
|
+
:class => merge_classes(:link, object.active, object.link_classes))
|
30
|
+
end +
|
31
|
+
content_tag(:li) do
|
32
|
+
breadcrumb_separator
|
33
|
+
end +
|
34
|
+
yield
|
35
|
+
end
|
36
|
+
|
37
|
+
def leaf(object)
|
38
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
39
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
40
|
+
if last_as_link
|
41
|
+
link_to object.name, object.url, :id => show_id(:link, object.id),
|
42
|
+
:class => merge_classes(:link, object.active, object.link_classes)
|
43
|
+
else
|
44
|
+
object.name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
class List
|
4
|
+
include RenderHelpers
|
5
|
+
include ActsAsList
|
6
|
+
|
7
|
+
navigation_default_classes [:list]
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def navigation(object)
|
12
|
+
content_tag :ul, nil, :id => show_id(:navigation, object.id),
|
13
|
+
:class => merge_classes(:navigation, object.active, object.classes) do
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def node(object)
|
19
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
20
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
21
|
+
link_to(object.name, object.url, :id => show_id(:link, object.id),
|
22
|
+
:class => merge_classes(:link, object.active, object.link_classes))+
|
23
|
+
yield
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def node_content(object)
|
28
|
+
content_tag(:ul, nil, :id => show_id(:node, object.id),
|
29
|
+
:class => merge_classes(:node, object.active, object.node_classes)) do
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def leaf(object)
|
35
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
36
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
37
|
+
link_to object.name, object.url, :id => show_id(:link, object.id),
|
38
|
+
:class => merge_classes(:link, object.active, object.link_classes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module Renderers
|
3
|
+
module RenderHelpers
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
base.class_eval do
|
9
|
+
style_accessor :navigation_active_class => [:active],
|
10
|
+
:node_active_class => [:active],
|
11
|
+
:leaf_active_class => [:active],
|
12
|
+
:link_active_class => [:active],
|
13
|
+
|
14
|
+
:show_navigation_active_class => true,
|
15
|
+
:show_node_active_class => true,
|
16
|
+
:show_leaf_active_class => true,
|
17
|
+
:show_link_active_class => true,
|
18
|
+
|
19
|
+
:show_navigation_id => true,
|
20
|
+
:show_node_id => true,
|
21
|
+
:show_leaf_id => true,
|
22
|
+
:show_link_id => true,
|
23
|
+
|
24
|
+
:navigation_default_classes => [],
|
25
|
+
:node_default_classes => [],
|
26
|
+
:leaf_default_classes => [],
|
27
|
+
:link_default_classes => []
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
|
33
|
+
def style_accessor(hash)
|
34
|
+
hash.keys.each do |key|
|
35
|
+
class_eval "
|
36
|
+
@@#{key} = nil
|
37
|
+
@#{key} = nil
|
38
|
+
|
39
|
+
def self.#{key}(value)
|
40
|
+
@@#{key}= value
|
41
|
+
end
|
42
|
+
|
43
|
+
def #{key}(value = nil)
|
44
|
+
@#{key} = value unless value.nil?
|
45
|
+
@#{key}.nil? ? @@#{key} : @#{key}
|
46
|
+
end
|
47
|
+
|
48
|
+
def #{key}=(value)
|
49
|
+
@#{key} = value
|
50
|
+
end
|
51
|
+
"
|
52
|
+
send key, hash[key]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def property_for(class_name,name)
|
57
|
+
class_object = "semantic_navigation/core/#{class_name}".classify.constantize
|
58
|
+
class_object.class_eval "
|
59
|
+
unless defined?(#{name})
|
60
|
+
def #{name}
|
61
|
+
@#{name}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module InstanceMethods
|
69
|
+
attr_accessor :from_level, :until_level, :except_for
|
70
|
+
|
71
|
+
def level=(level)
|
72
|
+
@from_level = level
|
73
|
+
@until_level = level
|
74
|
+
end
|
75
|
+
|
76
|
+
def levels=(level_range)
|
77
|
+
@from_level = level_range.first
|
78
|
+
@until_level = level_range.last
|
79
|
+
end
|
80
|
+
|
81
|
+
def initialize(view_object)
|
82
|
+
@view_object = view_object
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def content_tag(tag_name, content = nil, options={}, &block)
|
88
|
+
@view_object.content_tag(tag_name, content, options) {yield if block_given?}
|
89
|
+
end
|
90
|
+
|
91
|
+
def link_to(link_name, url, options={})
|
92
|
+
@view_object.link_to(link_name, url, options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def merge_classes(name, active, object_classes = [])
|
96
|
+
classes = []
|
97
|
+
classes += [send("#{name}_default_classes")].flatten
|
98
|
+
if active && send("show_#{name}_active_class")
|
99
|
+
classes.push [send("#{name}_active_class")].flatten
|
100
|
+
end
|
101
|
+
classes += [object_classes].flatten
|
102
|
+
classes.compact
|
103
|
+
end
|
104
|
+
|
105
|
+
def show_id(name, id)
|
106
|
+
id if send("show_#{name}_id")
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module TwitterBootstrap
|
3
|
+
class Breadcrumb
|
4
|
+
include SemanticNavigation::Renderers::RenderHelpers
|
5
|
+
include SemanticNavigation::Renderers::ActsAsBreadcrumb
|
6
|
+
|
7
|
+
style_accessor :last_as_link => false,
|
8
|
+
:breadcrumb_separator => '/'
|
9
|
+
|
10
|
+
navigation_default_classes [:breadcrumb]
|
11
|
+
|
12
|
+
show_navigation_active_class false
|
13
|
+
show_node_active_class false
|
14
|
+
show_leaf_active_class false
|
15
|
+
show_link_active_class false
|
16
|
+
show_navigation_id false
|
17
|
+
show_node_id false
|
18
|
+
show_leaf_id false
|
19
|
+
show_link_id false
|
20
|
+
|
21
|
+
property_for :base, :ico
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def navigation(object)
|
26
|
+
content_tag :ul, nil, :id => show_id(:navigation, object.id),
|
27
|
+
:class => merge_classes(:navigation, object.active, object.classes) do
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def node(object)
|
33
|
+
content_tag(:li, nil, :id => show_id(:leaf, object.id),
|
34
|
+
:class => merge_classes(:leaf, object.active, object.classes)) do
|
35
|
+
[object.ico ? content_tag(:i,nil,:class => "icon-#{object.ico}") : ''.html_safe,
|
36
|
+
link_to(object.name, object.url, :id => show_id(:link, object.id),
|
37
|
+
:class => merge_classes(:link, object.active, object.link_classes)),
|
38
|
+
content_tag(:span, nil, :class=> [:divider]) {breadcrumb_separator}].sum
|
39
|
+
end +
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
|
43
|
+
def leaf(object)
|
44
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
45
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
46
|
+
[object.ico ? content_tag(:i,nil,:class => "icon-#{object.ico}") : ''.html_safe,
|
47
|
+
if last_as_link
|
48
|
+
link_to(object.name, object.url, :id => show_id(:link, object.id),
|
49
|
+
:class => merge_classes(:link, object.active, object.link_classes))
|
50
|
+
else
|
51
|
+
object.name
|
52
|
+
end].sum
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module TwitterBootstrap
|
3
|
+
class List
|
4
|
+
include SemanticNavigation::Renderers::RenderHelpers
|
5
|
+
include SemanticNavigation::Renderers::ActsAsList
|
6
|
+
|
7
|
+
navigation_default_classes [:nav, 'nav-list']
|
8
|
+
show_navigation_id false
|
9
|
+
show_node_id false
|
10
|
+
show_leaf_id false
|
11
|
+
show_link_id false
|
12
|
+
|
13
|
+
property_for :base, :ico
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def navigation(object)
|
18
|
+
content_tag :ul, nil, :id => show_id(:navigation, object.id),
|
19
|
+
:class => merge_classes(:navigation, object.active, object.classes) do
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def node(object)
|
25
|
+
if object.ico
|
26
|
+
name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
|
27
|
+
object.name].sum
|
28
|
+
else
|
29
|
+
name = object.name
|
30
|
+
end
|
31
|
+
|
32
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
33
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
34
|
+
link_to(name, object.url, :id => show_id(:link, object.id),
|
35
|
+
:class => merge_classes(:link, object.active, object.link_classes)) +
|
36
|
+
yield
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def node_content(object)
|
41
|
+
content_tag(:ul, nil, :id => show_id(:node, object.id),
|
42
|
+
:class => merge_classes(:node, object.active, object.node_classes)) do
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def leaf(object)
|
48
|
+
if object.name.empty? && object.url.nil?
|
49
|
+
classes = 'divider'
|
50
|
+
elsif object.url.nil?
|
51
|
+
classes = 'nav-header'
|
52
|
+
else
|
53
|
+
classes = merge_classes(:leaf, object.active, object.classes)
|
54
|
+
end
|
55
|
+
|
56
|
+
if object.ico
|
57
|
+
name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
|
58
|
+
object.name].sum
|
59
|
+
else
|
60
|
+
name = object.name
|
61
|
+
end
|
62
|
+
|
63
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
64
|
+
:class => classes do
|
65
|
+
if object.url.nil?
|
66
|
+
name
|
67
|
+
else
|
68
|
+
link_to name, object.url, :id => show_id(:link, object.id),
|
69
|
+
:class => merge_classes(:link, object.active, object.link_classes)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
module TwitterBootstrap
|
3
|
+
class Tabs
|
4
|
+
include SemanticNavigation::Renderers::RenderHelpers
|
5
|
+
include SemanticNavigation::Renderers::ActsAsList
|
6
|
+
|
7
|
+
style_accessor :direction => 'left'
|
8
|
+
|
9
|
+
navigation_default_classes [:nav, 'nav-tabs']
|
10
|
+
show_navigation_id false
|
11
|
+
show_node_id false
|
12
|
+
show_leaf_id false
|
13
|
+
show_link_id false
|
14
|
+
|
15
|
+
property_for :base, :ico
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def navigation(object)
|
20
|
+
content_tag :ul, nil, :id => show_id(:navigation, object.id),
|
21
|
+
:class => merge_classes(:navigation, object.active, object.classes).push("pull-#{direction}") do
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def node(object)
|
27
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
28
|
+
:class => merge_classes(:leaf, object.active, object.classes).push(:dropdown) do
|
29
|
+
content_tag(:a, :href => '#',
|
30
|
+
:id => show_id(:link, object.id),
|
31
|
+
:class => merge_classes(:link, object.active, object.link_classes).push('dropdown-toggle'),
|
32
|
+
'data-toggle'=> :dropdown) do
|
33
|
+
[object.ico ? content_tag(:i,nil,:class => "icon-#{object.ico}") : '',
|
34
|
+
object.name,
|
35
|
+
content_tag(:b,nil,:class => :caret)
|
36
|
+
].sum.html_safe
|
37
|
+
end +
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def node_content(object)
|
43
|
+
content_tag(:ul, nil, :id => show_id(:node, object.id),
|
44
|
+
:class => merge_classes(:node, false, object.node_classes).push('dropdown-menu')) do
|
45
|
+
yield
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def leaf(object)
|
50
|
+
if object.ico
|
51
|
+
name = [content_tag(:i,nil,:class => "icon-#{object.ico}"),
|
52
|
+
object.name].sum
|
53
|
+
else
|
54
|
+
name = object.name
|
55
|
+
end
|
56
|
+
|
57
|
+
content_tag :li, nil, :id => show_id(:leaf, object.id),
|
58
|
+
:class => merge_classes(:leaf, object.active, object.classes) do
|
59
|
+
if object.url.nil?
|
60
|
+
name
|
61
|
+
else
|
62
|
+
link_to name, object.url, :id => show_id(:link, object.id),
|
63
|
+
:class => merge_classes(:link, object.active, object.link_classes)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|