Class: Radiant::AdminUI::NavTab
Overview
The NavTab Class holds the structure of a navigation tab (including its sub-nav items).
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proper_name ⇒ Object
readonly
Returns the value of attribute proper_name.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #<<(*args) ⇒ Object (also: #add)
- #[](id) ⇒ Object
- #deprecated_add(name, url, caller) ⇒ Object
-
#initialize(name, proper_name, visibility = [:all]) ⇒ NavTab
constructor
A new instance of NavTab.
- #visible?(user) ⇒ Boolean
Constructor Details
#initialize(name, proper_name, visibility = [:all]) ⇒ NavTab
Returns a new instance of NavTab.
16 17 18 |
# File 'lib/radiant/admin_ui.rb', line 16 def initialize(name, proper_name, visibility = [:all]) @name, @proper_name, @visibility = name, proper_name, Array(visibility) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/radiant/admin_ui.rb', line 14 def name @name end |
#proper_name ⇒ Object (readonly)
Returns the value of attribute proper_name.
14 15 16 |
# File 'lib/radiant/admin_ui.rb', line 14 def proper_name @proper_name end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
14 15 16 |
# File 'lib/radiant/admin_ui.rb', line 14 def visibility @visibility 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 |
# File 'lib/radiant/admin_ui.rb', line 28 def <<(*args) = args. 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 .empty? super(item) else .symbolize_keys! before = .delete(:before) after = .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/radiant/admin_ui.rb', line 20 def [](id) unless id.kind_of? Fixnum self.find {|| .name.to_s == id.to_s } else super end end |
#deprecated_add(name, url, caller) ⇒ Object
56 57 58 59 |
# File 'lib/radiant/admin_ui.rb', line 56 def deprecated_add(name, url, caller) ActiveSupport::Deprecation.warn("admin.tabs.add is no longer supported in Radiant 0.9.x. Please update your code to use admin.nav", caller) NavSubItem.new(name.underscore.to_sym, name, url) end |
#visible?(user) ⇒ Boolean
52 53 54 |
# File 'lib/radiant/admin_ui.rb', line 52 def visible?(user) visibility.include?(:all) || visibility.any? {|v| user.has_role?(v) } end |