Class: SimpleNavigation::Configuration::Builder::Navigation::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_navigation.rb

Overview

Menu builder

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  self.id = [options[:prefix], name].join('_')
  self.menus = []
  self.name = name
  self.title = title
  self.translation = [options[:translation], name].join('.')
  self.url = options[:url]
  self.urls = []
  options.delete(:translation)
  options.delete(:url)
  self.options = options
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def id
  @id
end

Returns the value of attribute menus.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def menus
  @menus
end

#nameObject

Returns the value of attribute name.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def name
  @name
end

#optionsObject

Returns the value of attribute options.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def options
  @options
end

#titleObject

Returns the value of attribute title.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def title
  @title
end

#translationObject

Returns the value of attribute translation.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def translation
  @translation
end

#urlObject

Returns the value of attribute url.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def url
  @url
end

#urlsObject

Returns the value of attribute urls.



201
202
203
# File 'lib/simple_navigation.rb', line 201

def urls
  @urls
end

Instance Method Details

#buildObject



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/simple_navigation.rb', line 234

def build
  menu = { :id => self.id.to_sym, :name => self.name.to_sym,
    :options => self.options }
  # Add keys with values only:
  menu.merge!(:menus => self.menus) unless self.menus.empty?
  menu.merge!(:title => self.title) unless self.title.nil?
  menu.merge!(:translation => [self.translation, 'title'].join('.')) if self.options[:i18n] == true
  menu.merge!(:url => self.url) unless self.url.nil?
  menu.merge!(:urls => self.urls) unless self.urls.empty?
  # Return menu hash
  menu
end

#connect(options = {}) ⇒ Object



229
230
231
232
# File 'lib/simple_navigation.rb', line 229

def connect(options = {})
  options[:controller] = self.url[:controller] unless options.has_key?(:controller)
  self.urls << options
end

Create a new child menu

Yields:



217
218
219
220
221
222
223
224
225
226
227
# File 'lib/simple_navigation.rb', line 217

def menu(name, *args, &block)
  title = args.first.is_a?(String) ? args.first : nil
  options = args.last.is_a?(::Hash) ? args.last : {}
  options.merge!(:i18n => self.options[:i18n])
  options.merge!(:translation => [self.translation, 'menus'].join('.'))
  options.merge!(:prefix => self.id)
  options.merge!(:class => "") unless options.has_key?(:class)
  menu = Menu.new(name, title, options)
  yield menu if block
  self.menus << menu.build
end