Sha256: 96db03e5d19e24aa6a36547d20d36041d14dd997e3337246b46f799766784831
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
module ActiveAdmin module Views # Renders out a horizontal list of tabs. class TabsRenderer < Renderer # Pass in an ActiveAdmin::Menu and it will display the first level # of navigation as a horizontal list of tabs def to_html(menu, options = {}) @options = default_options.merge(options) render_menu(menu) end protected def render_menu(menu) content_tag :ul, :id => @options[:id] do menu.items.collect do |item| render_item(item) end.join.html_safe end end def render_item(item) if !call_method_or_proc_on(self, item.display_if_block) return elsif (!item.url or item.url == '#') and item.children.any? and (item.children.detect {|child| call_method_or_proc_on(self, child.display_if_block)}).nil? return end content_tag :li, :id => item.dom_id, :class => [("current" if current?(item)), ("has_nested" unless item.children.blank?)].compact.join(" ") do unless item.children.blank? link_to(item.name, item.url || "#") + render_nested_menu(item) else link_to item.name, item.url end end end def render_nested_menu(item) content_tag :ul do item.children.collect {|child| render_item(child)}.join.html_safe end end # Returns true if the menu item name is @current_tab def current?(menu_item) @current_tab.split("/").include?(menu_item.name) unless @current_tab.blank? end def default_options { :id => "tabs" } end end end end
Version data entries
3 entries across 3 versions & 2 rubygems