Class: Ramenu::Menus::Element
- Inherits:
-
Object
- Object
- Ramenu::Menus::Element
- Defined in:
- lib/ramenu/menus.rb
Overview
Represents a navigation element in the menu collection.
Instance Attribute Summary collapse
-
#childs ⇒ Hash
The element/link childs.
-
#name ⇒ String
The element/link name.
-
#options ⇒ Hash
The element/link URL.
-
#parent ⇒ Element
The element/link parent.
-
#path ⇒ String
The element/link URL.
Instance Method Summary collapse
- #add_menu(name, path, options = {}, &block) ⇒ Object (also: #add_child)
-
#initialize(name, path, options = {}) ⇒ Element
constructor
Initializes the Element with given parameters.
- #translation_key ⇒ Object
Constructor Details
#initialize(name, path, options = {}) ⇒ Element
Initializes the Element with given parameters.
139 140 141 142 143 144 145 146 |
# File 'lib/ramenu/menus.rb', line 139 def initialize(name, path, = {}) self.name = name self.path = path self.childs = [] #self.parent = @options[:parent] self.parent = .delete(:parent) self. = end |
Instance Attribute Details
#childs ⇒ Hash
Returns The element/link childs.
126 127 128 |
# File 'lib/ramenu/menus.rb', line 126 def childs @childs end |
#name ⇒ String
Returns The element/link name.
122 123 124 |
# File 'lib/ramenu/menus.rb', line 122 def name @name end |
#options ⇒ Hash
Returns The element/link URL.
130 131 132 |
# File 'lib/ramenu/menus.rb', line 130 def @options end |
#parent ⇒ Element
Returns The element/link parent.
128 129 130 |
# File 'lib/ramenu/menus.rb', line 128 def parent @parent end |
#path ⇒ String
Returns The element/link URL.
124 125 126 |
# File 'lib/ramenu/menus.rb', line 124 def path @path end |
Instance Method Details
#add_menu(name, path, options = {}, &block) ⇒ Object Also known as: add_child
160 161 162 163 164 |
# File 'lib/ramenu/menus.rb', line 160 def (name, path, = {}, &block) opts = .merge({:parent => self}) opts.merge!(self..slice(:flag_for_menu)) self.childs << Ramenu.(name, path, opts, &block) end |
#translation_key ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ramenu/menus.rb', line 148 def translation_key key = '' elem = self while !elem.nil? do key = '.' + elem.name.to_s + key if elem.name.is_a?(Symbol) key = '.' + elem.name.to_sym.to_s + key if elem.name.is_a?(String) elem = elem.parent end key += '.root' if self.childs.count > 0 return key end |