Class: Waiter::Menu::Item
- Inherits:
-
Object
- Object
- Waiter::Menu::Item
- Defined in:
- lib/waiter/menu/item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#submenu ⇒ Object
readonly
Returns the value of attribute submenu.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #column? ⇒ Boolean
- #controller ⇒ Object
- #controllers ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(parent, name, path = {}, options = {}, &block) ⇒ Item
constructor
A new instance of Item.
- #inspect ⇒ Object
- #item_title ⇒ Object
- #items ⇒ Object
- #menu_title ⇒ Object
- #section? ⇒ Boolean
- #selected? ⇒ Boolean
- #submenu? ⇒ Boolean
Constructor Details
#initialize(parent, name, path = {}, options = {}, &block) ⇒ Item
Returns a new instance of Item.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/waiter/menu/item.rb', line 13 def initialize(parent, name, path = {}, = {}, &block) @parent = parent @name = name @path = complete_path_for(path) @options = collect_controllers @options.reverse_merge!(parent. || {}) if block_given? @submenu = Menu.new([@parent.name, name].compact, @parent.context, @options.dup) @submenu.parent = self @submenu.update(&block) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/waiter/menu/item.rb', line 9 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/waiter/menu/item.rb', line 10 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/waiter/menu/item.rb', line 9 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/waiter/menu/item.rb', line 9 def path @path end |
#submenu ⇒ Object (readonly)
Returns the value of attribute submenu.
9 10 11 |
# File 'lib/waiter/menu/item.rb', line 9 def @submenu end |
Instance Method Details
#[](name) ⇒ Object
46 47 48 49 |
# File 'lib/waiter/menu/item.rb', line 46 def [](name) return nil if items.empty? items[name] end |
#column? ⇒ Boolean
34 35 36 |
# File 'lib/waiter/menu/item.rb', line 34 def column? false end |
#controller ⇒ Object
63 64 65 |
# File 'lib/waiter/menu/item.rb', line 63 def controller @controller ||= find_controller end |
#controllers ⇒ Object
67 68 69 |
# File 'lib/waiter/menu/item.rb', line 67 def controllers [:controllers] end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/waiter/menu/item.rb', line 42 def empty? items.empty? end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/waiter/menu/item.rb', line 86 def inspect "#<#{self.class.name}:#{'0x%x' % (36971870 << 1)} name=#{name.inspect} options=#{.inspect} parent=#{parent.inspect} submenu=#{.inspect}>" end |
#item_title ⇒ Object
59 60 61 |
# File 'lib/waiter/menu/item.rb', line 59 def item_title translate(name) end |
#items ⇒ Object
38 39 40 |
# File 'lib/waiter/menu/item.rb', line 38 def items @submenu.try(:items) || [] end |
#menu_title ⇒ Object
55 56 57 |
# File 'lib/waiter/menu/item.rb', line 55 def translate(:title) end |
#section? ⇒ Boolean
30 31 32 |
# File 'lib/waiter/menu/item.rb', line 30 def section? false end |
#selected? ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/waiter/menu/item.rb', line 71 def selected? return name == [:selected] if [:selected] current_controller = context.params[:controller] if wildcard_controllers.any? return true if wildcard_controllers.any? do |c| r = Regexp.new('\A' + c.sub(%r{/\*\Z}, '(/*)?').gsub('*', '.*')) r =~ current_controller end end controllers.include?(current_controller) end |
#submenu? ⇒ Boolean
51 52 53 |
# File 'lib/waiter/menu/item.rb', line 51 def .present? end |