Class: TrustyCms::AdminUI::NavTab

Inherits:
Array
  • Object
show all
Defined in:
lib/trusty_cms/admin_ui.rb

Overview

The NavTab Class holds the structure of a navigation tab (including its sub-nav items).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ NavTab

Returns a new instance of NavTab.



16
17
18
# File 'lib/trusty_cms/admin_ui.rb', line 16

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/trusty_cms/admin_ui.rb', line 14

def name
  @name
end

Instance Method Details

#<<(*args) ⇒ Object Also known as: add



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/trusty_cms/admin_ui.rb', line 28

def <<(*args)
  options = args.extract_options!
  item = args.size > 1 ? deprecated_add(*(args << caller)) : args.first
  raise DuplicateTabNameError.new("duplicate tab name `#{item.name}'") if self[item.name]

  item.tab = self if item.respond_to?(:tab=)
  if options.empty?
    super(item)
  else
    options.symbolize_keys!
    before = options.delete(:before)
    after = options.delete(:after)
    tab_name = before || after
    if self[tab_name]
      _index = index(self[tab_name])
      _index += 1 unless before
      insert(_index, item)
    else
      super(item)
    end
  end
end

#[](id) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/trusty_cms/admin_ui.rb', line 20

def [](id)
  if id.is_a? Integer
    super
  else
    find { |subnav_item| subnav_item.name.to_s.titleize == id.to_s.titleize }
  end
end

#add_item(*args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/trusty_cms/admin_ui.rb', line 53

def add_item(*args)
  options = args.extract_options!
  options.symbolize_keys!
  before = options.delete(:before)
  after = options.delete(:after)
  tab_name = before || after
  if self[tab_name]
    _index = index(self[tab_name])
    _index += 1 unless before
    insert(_index, NavSubItem.new(args.first, args.second))
  else
    add NavSubItem.new(args.first, args.second)
  end
end

#deprecated_add(name, url, caller) ⇒ Object



72
73
74
75
# File 'lib/trusty_cms/admin_ui.rb', line 72

def deprecated_add(name, url, caller)
  ActiveSupport::Deprecation.warn("admin.tabs.add is no longer supported in TrustyCms 0.9.x.  Please update your code to use: \ntab \"Content\" do\n\tadd_item(...)\nend", caller)
  NavSubItem.new(name, url)
end

#visible?(user) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/trusty_cms/admin_ui.rb', line 68

def visible?(user)
  any? { |sub_item| sub_item.visible?(user) }
end