Class: Radiant::AdminUI::TabSet
- Includes:
- Enumerable
- Defined in:
- lib/radiant/admin_ui.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(name, url, options = {}) ⇒ Object
- #clear ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ TabSet
constructor
A new instance of TabSet.
- #remove(name) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ TabSet
Returns a new instance of TabSet.
27 28 29 |
# File 'lib/radiant/admin_ui.rb', line 27 def initialize @tabs = [] end |
Instance Method Details
#[](index) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/radiant/admin_ui.rb', line 57 def [](index) if index.kind_of? Integer @tabs[index] else @tabs.find { |tab| tab.name == index } end end |
#add(name, url, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/radiant/admin_ui.rb', line 31 def add(name, url, = {}) .symbolize_keys! before = .delete(:before) after = .delete(:after) tab_name = before || after if self[name] raise DuplicateTabNameError.new("duplicate tab name `#{name}'") else if tab_name index = @tabs.index(self[tab_name]) index += 1 if before.nil? @tabs.insert(index, Tab.new(name, url, )) else @tabs << Tab.new(name, url, ) end end end |
#clear ⇒ Object
69 70 71 |
# File 'lib/radiant/admin_ui.rb', line 69 def clear @tabs.clear end |
#each ⇒ Object
65 66 67 |
# File 'lib/radiant/admin_ui.rb', line 65 def each @tabs.each { |t| yield t } end |
#remove(name) ⇒ Object
49 50 51 |
# File 'lib/radiant/admin_ui.rb', line 49 def remove(name) @tabs.delete(self[name]) end |
#size ⇒ Object
53 54 55 |
# File 'lib/radiant/admin_ui.rb', line 53 def size @tabs.size end |