semantic_navigation 0.0.2.1 → 0.0.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/Changelog.md +9 -0
- data/README.md +1 -1
- data/lib/semantic_navigation/configuration.rb +4 -1
- data/lib/semantic_navigation/core/render.rb +25 -12
- data/lib/semantic_navigation/item.rb +11 -5
- data/lib/semantic_navigation/version.rb +1 -1
- metadata +4 -5
data/Changelog.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### 0.0.3 / January 4th, 2012
|
2
|
+
|
3
|
+
* Added levels rendering
|
4
|
+
* Added menu classes
|
5
|
+
|
6
|
+
### 0.0.2.1 / December 30th, 2011
|
7
|
+
|
8
|
+
* Fix one bug with configuration
|
9
|
+
|
1
10
|
### 0.0.2 / December 30th, 2011
|
2
11
|
|
3
12
|
* Definition of default render options (active_class and show_ids)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
This is semantic_menu manual
|
2
|
-
Current version: 0.0.
|
2
|
+
Current version: 0.0.3
|
3
3
|
|
4
4
|
###Purpose
|
5
5
|
The purpose of this gem is to generate simple and usefull navigation. You can define different menus and render them separately, specify root nodes, setup your own renderers and other.
|
@@ -19,6 +19,7 @@ module SemanticNavigation
|
|
19
19
|
SemanticNavigation::Item.set_default_option(name.chop,args[0])
|
20
20
|
else
|
21
21
|
menu = Item.new(name, args, nil)
|
22
|
+
menu.level = 0
|
22
23
|
@menus.merge!({name.to_sym => menu})
|
23
24
|
yield menu if block_given?
|
24
25
|
end
|
@@ -36,11 +37,13 @@ module SemanticNavigation
|
|
36
37
|
!item.nil? && !item.parent.nil? ? item.parent.name : ''
|
37
38
|
elsif command == :breadcrumb
|
38
39
|
return @menus[name.to_sym].render_breadcrumb
|
40
|
+
elsif command.is_a?(Hash) && command.keys == [:levels]
|
41
|
+
return @menus[name.to_sym].render_levels command[:levels]
|
39
42
|
else
|
40
43
|
raise NoMethodError.new("Wrong menu render parameter:`#{command.to_s}`")
|
41
44
|
end
|
42
45
|
else
|
43
|
-
raise NoMethodError.new("No such menu name:`#{name}` check your #{Rails.root}/config/semantic_navigation.rb
|
46
|
+
raise NoMethodError.new("No such menu name:`#{name}` check your #{Rails.root}/config/semantic_navigation.rb file")
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
@@ -2,16 +2,23 @@ module SemanticNavigation
|
|
2
2
|
module Core
|
3
3
|
module Render
|
4
4
|
|
5
|
-
def render
|
5
|
+
def render(last_level = nil)
|
6
6
|
return nil if !render_item?
|
7
7
|
if @parent
|
8
|
-
|
9
|
-
|
10
|
-
view_object.content_tag(:li,
|
8
|
+
level_condition = last_level.nil? ? true : @level < last_level
|
9
|
+
sub = (@active || show_submenu?) && level_condition ? render_submenu(last_level) : nil
|
10
|
+
view_object.content_tag(:li, item_link + sub, :id => li_id, :class => classes)
|
11
11
|
else
|
12
12
|
render_submenu
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
def render_submenu(last_level = nil)
|
17
|
+
if @sub_items.count > 0
|
18
|
+
sub = @sub_items.map{|s| s.render(last_level)}.sum
|
19
|
+
view_object.content_tag(:ul, sub, :id => ul_id, :class => menu_classes) if sub != 0
|
20
|
+
end
|
21
|
+
end
|
15
22
|
|
16
23
|
def set_as_active
|
17
24
|
@active = true
|
@@ -35,8 +42,7 @@ module SemanticNavigation
|
|
35
42
|
breadcrumb = nil
|
36
43
|
if @active
|
37
44
|
if @name
|
38
|
-
|
39
|
-
breadcrumb = view_object.content_tag(:li, link + breadcrumb_name, :id => li_id) if @name
|
45
|
+
breadcrumb = view_object.content_tag(:li, item_link + breadcrumb_name, :id => li_id) if @name
|
40
46
|
end
|
41
47
|
buff = @sub_items.map{|s| s.render_breadcrumb}.find{|s| !s.nil?}
|
42
48
|
if !breadcrumb.nil?
|
@@ -49,18 +55,25 @@ module SemanticNavigation
|
|
49
55
|
breadcrumb
|
50
56
|
end
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
view_object.content_tag(:ul, sub, :id => ul_id) if sub != 0
|
58
|
+
def render_levels levels
|
59
|
+
levels = levels.to_a
|
60
|
+
item = find_active_item
|
61
|
+
while item.level > levels.first-1 && item.level != 0
|
62
|
+
item = item.parent
|
58
63
|
end
|
64
|
+
item.level == levels.first-1 ? item.render_submenu(levels.last) : nil
|
59
65
|
end
|
66
|
+
|
67
|
+
private
|
60
68
|
|
61
69
|
def active?
|
62
70
|
!@parent.nil? ? view_object.current_page?(@url_options) : false
|
63
71
|
end
|
72
|
+
|
73
|
+
def item_link
|
74
|
+
view_object.link_to @name, @url_options, :class => classes, :id => a_id
|
75
|
+
end
|
76
|
+
|
64
77
|
end
|
65
78
|
end
|
66
79
|
end
|
@@ -10,11 +10,8 @@ module SemanticNavigation
|
|
10
10
|
@@show_active_class = true
|
11
11
|
@@show_menu_id = true
|
12
12
|
@@show_submenu = false
|
13
|
-
@@menu_prefix = ''
|
14
13
|
|
15
14
|
#Item variables
|
16
|
-
@@item_perfix = ''
|
17
|
-
@@name_prefix = ''
|
18
15
|
@@show_name_id = true
|
19
16
|
@@show_item_id = true
|
20
17
|
|
@@ -26,8 +23,8 @@ module SemanticNavigation
|
|
26
23
|
attr_accessor :active_class, :show_active_class, :show_menu_id,
|
27
24
|
:show_item_id, :show_name_id, :show_submenu,
|
28
25
|
:menu_prefix, :item_prefix, :name_prefix,
|
29
|
-
:item_classes,
|
30
|
-
:name, :parent
|
26
|
+
:item_classes, :menu_classes,
|
27
|
+
:name, :parent, :level
|
31
28
|
|
32
29
|
def initialize(id, args, parent)
|
33
30
|
@item_id = id
|
@@ -41,6 +38,7 @@ module SemanticNavigation
|
|
41
38
|
|
42
39
|
def method_missing(name, *args)
|
43
40
|
item = SemanticNavigation::Item.new(name.to_s, args, self)
|
41
|
+
item.level = @level + 1
|
44
42
|
@sub_items << item
|
45
43
|
yield item if block_given?
|
46
44
|
end
|
@@ -100,5 +98,13 @@ module SemanticNavigation
|
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
101
|
+
def menu_classes
|
102
|
+
if @menu_classes.is_a? Array
|
103
|
+
return @menu_classes.join(' ')
|
104
|
+
else
|
105
|
+
return @menu_classes
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
103
109
|
end
|
104
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.0.2.1
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Sergey Gribovski
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2012-01-03 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rspec
|