Class: SimpleNavigation::Configuration::Builder::Navigation::Menu
- Inherits:
-
Object
- Object
- SimpleNavigation::Configuration::Builder::Navigation::Menu
- Defined in:
- lib/simple_navigation.rb
Overview
Menu builder
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#menus ⇒ Object
Returns the value of attribute menus.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#title ⇒ Object
Returns the value of attribute title.
-
#translation ⇒ Object
Returns the value of attribute translation.
-
#url ⇒ Object
Returns the value of attribute url.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
- #build ⇒ Object
- #connect(options = {}) ⇒ Object
-
#initialize(name, title = nil, options = {}) ⇒ Menu
constructor
A new instance of Menu.
-
#menu(name, *args) {|menu| ... } ⇒ Object
Create a new child menu.
Constructor Details
#initialize(name, title = nil, options = {}) ⇒ Menu
Returns a new instance of Menu.
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/simple_navigation.rb', line 203 def initialize(name, title = nil, = {}) self.id = [[:prefix], name].join('_') self. = [] self.name = name self.title = title self.translation = [[:translation], name].join('.') self.url = [:url] self.urls = [] .delete(:translation) .delete(:url) self. = end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def id @id end |
#menus ⇒ Object
Returns the value of attribute menus.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def @menus end |
#name ⇒ Object
Returns the value of attribute name.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def @options end |
#title ⇒ Object
Returns the value of attribute title.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def title @title end |
#translation ⇒ Object
Returns the value of attribute translation.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def translation @translation end |
#url ⇒ Object
Returns the value of attribute url.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def url @url end |
#urls ⇒ Object
Returns the value of attribute urls.
201 202 203 |
# File 'lib/simple_navigation.rb', line 201 def urls @urls end |
Instance Method Details
#build ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/simple_navigation.rb', line 234 def build = { :id => self.id.to_sym, :name => self.name.to_sym, :options => self. } # Add keys with values only: .merge!(:menus => self.) unless self..empty? .merge!(:title => self.title) unless self.title.nil? .merge!(:translation => [self.translation, 'title'].join('.')) if self.[:i18n] == true .merge!(:url => self.url) unless self.url.nil? .merge!(:urls => self.urls) unless self.urls.empty? # Return menu hash end |
#connect(options = {}) ⇒ Object
229 230 231 232 |
# File 'lib/simple_navigation.rb', line 229 def connect( = {}) [:controller] = self.url[:controller] unless .has_key?(:controller) self.urls << end |
#menu(name, *args) {|menu| ... } ⇒ Object
Create a new child menu
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/simple_navigation.rb', line 217 def (name, *args, &block) title = args.first.is_a?(String) ? args.first : nil = args.last.is_a?(::Hash) ? args.last : {} .merge!(:i18n => self.[:i18n]) .merge!(:translation => [self.translation, 'menus'].join('.')) .merge!(:prefix => self.id) .merge!(:class => "") unless .has_key?(:class) = Menu.new(name, title, ) yield if block self. << .build end |