Class: AbAdmin::Menu::Item

Inherits:
Object show all
Includes:
Utils::EvalHelpers
Defined in:
lib/ab_admin/menu/item.rb

Instance Method Summary collapse

Methods included from Utils::EvalHelpers

#call_method_or_proc_on, #evaluate_method

Constructor Details

#initialize(title, url, options) ⇒ Item

Returns a new instance of Item


6
7
8
9
10
# File 'lib/ab_admin/menu/item.rb', line 6

def initialize(title, url, options)
  @title = title.is_a?(Symbol) ? I18n.t(title, scope: [:admin, :navigation]) : title
  @url = url
  @options = options
end

Instance Method Details

#render(template) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ab_admin/menu/item.rb', line 12

def render(template)
  return if @options[:if] && !call_method_or_proc_on(template, @options[:if])
  return if @options[:unless] && call_method_or_proc_on(template, @options[:unless])

  item_url = @url.is_a?(String) ? @url : call_method_or_proc_on(template, @url)
  active = template.request.path.split('/')[2] == item_url.split('/')[2]

  <<-HTML.html_safe
    <li class="#{'active' if active}">#{template.link_to title(template), item_url, @options.except(:if, :unless)}</li>
  HTML
end