Class: MenuBar

Inherits:
Object
  • Object
show all
Includes:
EasyMenu::Configuration, EasyMenu::Helpers
Defined in:
lib/menu_bar.rb

Direct Known Subclasses

MenuBarGroup

Defined Under Namespace

Classes: AbstractContent, AbstractItem, Menu, MenuBarContent, MenuBarGroup, MenuBarInput, MenuBarItem, MenuBarTrigger, MenuContent, MenuGroup, MenuItem

Constant Summary

Constants included from EasyMenu::Configuration

EasyMenu::Configuration::Bootstrap, EasyMenu::Configuration::Default

Constants included from EasyMenu::Helpers

EasyMenu::Helpers::HTML_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EasyMenu::Configuration

included

Methods included from EasyMenu::Helpers

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

Constructor Details

#initialize(template, options = {}) {|_self| ... } ⇒ MenuBar

Returns a new instance of MenuBar.

Yields:

  • (_self)

Yield Parameters:

  • _self (MenuBar)

    the object that the method was called on



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/menu_bar.rb', line 11

def initialize(template, options = {})
  @template = template
  @options = options.reverse_merge(:theme => config[:default_theme_class], :remove_dangling_separators => true)
  config.merge! options[:config] if options[:config] # Allow per menu overriding of configuration
  config[:template] = @template

  @content = []
  @groups = [] # Subset of content that allows user to perform simpler non-sequential insertion into a particular group

  yield self if block_given?
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/menu_bar.rb', line 9

def content
  @content
end

#groupsObject (readonly)

Returns the value of attribute groups.



9
10
11
# File 'lib/menu_bar.rb', line 9

def groups
  @groups
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/menu_bar.rb', line 23

def empty?
  @content.blank?
end

#group(options = {}) {|mbg| ... } ⇒ Object

Yields:

  • (mbg)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/menu_bar.rb', line 27

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

  mbg = MenuBarGroup.new(@template, options.merge(@options.slice(:config)))
  mbc = MenuBarContent.new(config, mbg, options[:menu_bar_content])

  yield mbg if block_given?

  store_menu_bar_content(mbc, options)
  @groups << mbg

  return mbg
end

#html_safe?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/menu_bar.rb', line 117

def html_safe?
  true
end

Yields:

  • (m)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/menu_bar.rb', line 81

def menu(button_text, options = {})
  initialize_options(options)

  arrow = @template.(:span, '', :class => config[:menu_bar_item_arrow_class])

  m = Menu.new(config, options)
  mbt = MenuBarTrigger.new(config, button_text.html_safe + ' ' + arrow, m, options[:menu_bar_item])

  yield m if block_given?

  # We give the menu bar content a special class so we can treat its contents differently than one without a menu inside
  mbc = MenuBarContent.new(config, mbt, merge_class(options[:menu_bar_content], config[:menu_bar_content_with_menu_class]))

  store_menu_bar_content(mbc, options)

  return m
end


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/menu_bar.rb', line 41

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

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

  mbc = MenuBarContent.new(config, content, options)

  store_menu_bar_content(mbc, options)

  return mbc
end


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/menu_bar.rb', line 69

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

  mbin = MenuBarInput.new config, content, options
  mbi = MenuBarItem.new config, mbin, options[:menu_bar_item]
  mbc = MenuBarContent.new(config, mbi, options[:menu_bar_content])

  store_menu_bar_content(mbc, options)

  return mbi
end


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/menu_bar.rb', line 56

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

  raise if config[:template].is_a?(Hash) || config[:template].nil?

  mbi = MenuBarItem.new config, content, options
  mbc = MenuBarContent.new(config, mbi, options[:menu_bar_content])

  store_menu_bar_content(mbc, options)

  return mbi
end

#separator(options = {}) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/menu_bar.rb', line 99

def separator(options = {})
  s = @template. :div, '', :class => config[:menu_bar_separator_class]
  mbc = MenuBarContent.new(config, s, options.reverse_merge(:remove_if_dangling => @options[:remove_dangling_separators]))

  store_menu_bar_content(mbc, options)

  return s
end

#to_sObject



108
109
110
111
# File 'lib/menu_bar.rb', line 108

def to_s
  @content.pop if @content.last && @content.last.options[:remove_if_dangling]
  wrap_content(@content.join.html_safe)
end

#to_strObject



113
114
115
# File 'lib/menu_bar.rb', line 113

def to_str
  to_s
end