Class: MenuBar::Menu

Inherits:
AbstractContent show all
Defined in:
lib/menu_bar.rb

Direct Known Subclasses

MenuGroup

Constant Summary

Constants included from EasyMenu::Helpers

EasyMenu::Helpers::HTML_OPTIONS

Instance Attribute Summary

Attributes inherited from AbstractContent

#config, #content, #options

Instance Method Summary collapse

Methods inherited from AbstractContent

#empty?, #right_aligned?, #to_s

Methods included from EasyMenu::Helpers

#config_name, #css_class, #html_option_keys, #merge_class, #wrap_content, #wrapper_element

Constructor Details

#initialize(config, options = {}) {|_self| ... } ⇒ Menu

Returns a new instance of Menu.

Yields:

  • (_self)

Yield Parameters:

  • _self (MenuBar::Menu)

    the object that the method was called on



277
278
279
280
281
282
283
284
285
286
# File 'lib/menu_bar.rb', line 277

def initialize(config, options = {})
  raise if config[:template].is_a?(Hash) || config[:template].nil?

  @config = config
  @template = config[:template]
  @options = options
  @content = []

  yield self if block_given?
end

Instance Method Details

#group(title, options = {}) {|mg| ... } ⇒ Object

Yields:

  • (mg)


288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/menu_bar.rb', line 288

def group(title, options = {})
  initialize_options(options)

  mgt = @template.(config[:menu_group_title_element], title, merge_class(options[:menu_group_title], config[:menu_group_title_class]))
  mg = MenuGroup.new(config, options)

  yield mg if block_given?

  mc = MenuContent.new(config, [mgt, mg], options[:menu_content])

  store_menu_content(mc, options)

  return mg
end


303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/menu_bar.rb', line 303

def menu_content(content = nil, options = {}, &block)
  initialize_options(options)

  if block_given?
    options = content || options
    content = block.call
  end

  mc = MenuContent.new(config, content, options)

  store_menu_content(mc, options)
end


316
317
318
319
320
321
322
323
324
325
# File 'lib/menu_bar.rb', line 316

def menu_item(content, options = {})
  initialize_options(options)

  mi = MenuItem.new(config, content, options)
  mc = MenuContent.new(config, mi, options[:menu_content])

  store_menu_content(mc, options)

  return mi
end

#separator(options = {}) ⇒ Object



327
328
329
330
331
332
333
334
# File 'lib/menu_bar.rb', line 327

def separator(options = {})
  s = @template. :div, '', :class => config[:menu_separator_class]
  mc = MenuContent.new(config, s)

  store_menu_content(mc, options)

  return s
end