Class: ActiveAdmin::Views::TabsRenderer

Inherits:
Renderer show all
Defined in:
lib/active_admin/views/tabs_renderer.rb

Overview

Renders out a horizontal list of tabs.

Constant Summary

Constants included from Arbre::HTML

Arbre::HTML::AUTO_BUILD_ELEMENTS, Arbre::HTML::HTML5_ELEMENTS

Instance Attribute Summary

Attributes inherited from Renderer

#assigns, #view

Instance Method Summary collapse

Methods inherited from Renderer

#call_method_or_proc_on, #haml, #initialize, #method_missing, #set_ivar_on_view, #to_s

Methods included from Arbre::HTML

#current_dom_context, #helpers, #method_missing

Methods included from ActiveAdmin::ViewHelpers::RendererHelper

#render

Constructor Details

This class inherits a constructor from ActiveAdmin::Renderer

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveAdmin::Renderer

Instance Method Details

#current?(menu_item) ⇒ Boolean (protected)

Returns true if the menu item name is @current_tab

Returns:

  • (Boolean)


47
48
49
# File 'lib/active_admin/views/tabs_renderer.rb', line 47

def current?(menu_item)
  @current_tab.split("/").include?(menu_item.name) unless @current_tab.blank?
end

#default_optionsObject (protected)



51
52
53
# File 'lib/active_admin/views/tabs_renderer.rb', line 51

def default_options
  { :id => "tabs" }
end

#render_item(item) ⇒ Object (protected)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_admin/views/tabs_renderer.rb', line 24

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
  
   :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

#render_menu(menu) ⇒ Object (protected)



16
17
18
19
20
21
22
# File 'lib/active_admin/views/tabs_renderer.rb', line 16

def render_menu(menu)
   :ul, :id => @options[:id] do
    menu.items.collect do |item|
      render_item(item)
    end.join.html_safe
  end
end

#render_nested_menu(item) ⇒ Object (protected)



40
41
42
43
44
# File 'lib/active_admin/views/tabs_renderer.rb', line 40

def render_nested_menu(item)
   :ul do
    item.children.collect {|child| render_item(child)}.join.html_safe
  end
end

#to_html(menu, options = {}) ⇒ Object

Pass in an ActiveAdmin::Menu and it will display the first level of navigation as a horizontal list of tabs



9
10
11
12
# File 'lib/active_admin/views/tabs_renderer.rb', line 9

def to_html(menu, options = {})
  @options = default_options.merge(options)
  render_menu(menu)
end