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

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

Overview

Hash structure containing simple navigation menu configuration

Defined Under Namespace

Classes: Menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Navigation

Returns a new instance of Navigation.



168
169
170
171
172
173
174
175
# File 'lib/simple_navigation.rb', line 168

def initialize(name, options = {})
  options.merge!(:i18n => false) unless options.has_key?(:i18n)
  self.translation = ['simple_navigation', name].join('.')
  self.id = name
  self.menus = []
  self.name = name
  self.options = options
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



166
167
168
# File 'lib/simple_navigation.rb', line 166

def id
  @id
end

Returns the value of attribute menus.



166
167
168
# File 'lib/simple_navigation.rb', line 166

def menus
  @menus
end

#nameObject

Returns the value of attribute name.



166
167
168
# File 'lib/simple_navigation.rb', line 166

def name
  @name
end

#optionsObject

Returns the value of attribute options.



166
167
168
# File 'lib/simple_navigation.rb', line 166

def options
  @options
end

#translationObject

Returns the value of attribute translation.



166
167
168
# File 'lib/simple_navigation.rb', line 166

def translation
  @translation
end

Instance Method Details

#buildObject

render menu



191
192
193
194
195
196
# File 'lib/simple_navigation.rb', line 191

def build
  { :id => self.id.to_sym,
    :name => self.name.to_sym,
    :menus => self.menus,
    :options => self.options }
end

Create a new root menu

Yields:



178
179
180
181
182
183
184
185
186
187
188
# File 'lib/simple_navigation.rb', line 178

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