lib/rocket_navigation/renderer/bootstrap.rb in rocket_navigation-0.2.2 vs lib/rocket_navigation/renderer/bootstrap.rb in rocket_navigation-0.2.3
- old
+ new
@@ -7,21 +7,28 @@
class Bootstrap < RocketNavigation::Renderer::Base
def initialize(container, options = {})
super(container, options)
end
+ def list_tag
+ options[:ordered] ? :ol : :ul
+ end
+
def render(item_container)
if skip_if_empty? && item_container.empty?
''.html_safe
else
if item_container.level > 1
content = list_content(item_container)
- content_tag(:div, content, {class: "dropdown-menu"})
+ if options[:superfish]
+ content_tag(list_tag, content, {class: "dropdown-menu"})
+ else
+ content_tag(:div, content, {class: "dropdown-menu"})
+ end
else
- tag = options[:ordered] ? :ol : :ul
content = list_content(item_container)
- content_tag(tag, content, container_html)
+ content_tag(list_tag, content, container_html)
end
end
end
def render_item(item)
@@ -30,11 +37,21 @@
if include_sub_navigation?(item)
li_content << render_sub_navigation_for(item)
end
content_tag(:li, li_content, item_options(item))
else
- tag_for(item)
+ if include_sub_navigation?(item)
+ content = tag_for(item)
+ content << render_sub_navigation_for(item)
+ if options[:superfish]
+ content_tag(:li, content, class: "dropdown")
+ else
+ content_tag(:div, content, class: "dropdown")
+ end
+ else
+ tag_for(item)
+ end
end
end
def list_content(item_container)
ret = ActiveSupport::SafeBuffer.new
@@ -72,11 +89,24 @@
super(item)
end
end
def tag_for(item)
- if item.level == 1 && item.sub_navigation
- link_to(item.name, item.url, {class: "nav-link dropdown-toggle", 'data-toggle' => "dropdown"})
+ if item.sub_navigation
+ cl = ""
+ if item.level == 1
+ cl = "nav-link"
+ else
+ cl = "dropdown-item"
+ end
+ opt = {
+ class: cl
+ }
+ opt[:class] += " dropdown-toggle"
+ unless options[:superfish]
+ opt['data-toggle'] = "dropdown"
+ end
+ link_to(item.name, item.url, opt)
else
super(item)
end
end
end