conte_rails_template 0.0.34 → 0.0.35
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/conte_rails_template/version.rb +1 -1
- data/lib/navigation_renderer.rb +46 -44
- metadata +1 -1
data/lib/navigation_renderer.rb
CHANGED
@@ -1,55 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module ConteRailsTemplate
|
2
|
+
class NavigationRenderer < SimpleNavigation::Renderer::Base
|
3
|
+
def render(item_container)
|
4
|
+
list_content = item_container.items.inject([]) do |list, item|
|
5
|
+
li_content = []
|
6
|
+
li_content << tag_for(item)
|
7
|
+
if include_sub_navigation?(item)
|
8
|
+
li_content << render_sub_navigation_for(item)
|
9
|
+
end
|
10
|
+
list << content_tag(:div, li_content.join, class: 'accordion-group')
|
11
|
+
end.join
|
12
|
+
if skip_if_empty? && item_container.empty?
|
13
|
+
''
|
14
|
+
else
|
15
|
+
content_tag :div, list_content, {:class => 'accordion', "id" => 'navigation'}
|
8
16
|
end
|
9
|
-
list << content_tag(:div, li_content.join, class: 'accordion-group')
|
10
|
-
end.join
|
11
|
-
if skip_if_empty? && item_container.empty?
|
12
|
-
''
|
13
|
-
else
|
14
|
-
content_tag :div, list_content, {:class => 'accordion', "id" => 'navigation'}
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
+
protected
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
def tag_for(item)
|
22
|
+
item_content = nil
|
23
|
+
options = link_options_for(item)
|
24
|
+
if suppress_link?(item)
|
25
|
+
content = []
|
26
|
+
content << item.name
|
27
|
+
content << content_tag(:b, nil, class: 'caret')
|
28
|
+
if options[:class] && options[:class].include?('active')
|
29
|
+
options[:class] = [options[:class], 'accordion-toggle in'].flatten.compact.join(' ')
|
30
|
+
else
|
31
|
+
options[:class] = [options[:class], 'accordion-toggle collapsed'].flatten.compact.join(' ')
|
32
|
+
end
|
33
|
+
options = options.merge('data-toggle' => "collapse", 'data-parent' => "#navigation")
|
34
|
+
item_content = link_to(content.join(' '), "#collapse_#{item.key}", options)
|
29
35
|
else
|
30
|
-
options[:class] = [options[:class], 'accordion-toggle
|
36
|
+
options[:class] = [options[:class], 'accordion-toggle'].flatten.compact.join(' ')
|
37
|
+
item_content = link_to(item.name, item.url, options)
|
31
38
|
end
|
32
|
-
|
33
|
-
item_content = link_to(content.join(' '), "#collapse_#{item.key}", options)
|
34
|
-
else
|
35
|
-
options[:class] = [options[:class], 'accordion-toggle'].flatten.compact.join(' ')
|
36
|
-
item_content = link_to(item.name, item.url, options)
|
39
|
+
content_tag :div, item_content, class: 'accordion-heading'
|
37
40
|
end
|
38
|
-
content_tag :div, item_content, class: 'accordion-heading'
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
def render_sub_navigation_for(item)
|
43
|
+
options = link_options_for(item)
|
44
|
+
sub_list_content = item.sub_navigation.items.inject([]) do |list, sub_item|
|
45
|
+
li_content = link_to(sub_item.name, sub_item.url, link_options_for(sub_item))
|
46
|
+
list << content_tag(:li, li_content)
|
47
|
+
end.join
|
48
|
+
sub_list = content_tag(:ul, sub_list_content)
|
49
|
+
inner_container = content_tag(:div, sub_list, class: 'accordion-inner')
|
50
|
+
if options[:class] && options[:class].include?('active')
|
51
|
+
content_tag(:div, inner_container, {:class => 'accordion-body in collapse', 'id' => "collapse_#{item.key}"})
|
52
|
+
else
|
53
|
+
content_tag(:div, inner_container, {:class => 'accordion-body collapse', 'id' => "collapse_#{item.key}"})
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|