Module: EasyMenu::Helpers

Included in:
MenuBar, MenuBar::AbstractContent
Defined in:
lib/easy_menu_helpers.rb

Constant Summary collapse

HTML_OPTIONS =
[:id, :class, :title, :style, :data]

Instance Method Summary collapse

Instance Method Details

#config_nameObject

Determines the config name from the class name. e.g. MenuBar => ‘menu_bar’



7
8
9
# File 'lib/easy_menu_helpers.rb', line 7

def config_name
  self.class.name.demodulize.underscore
end

#css_classObject



11
12
13
# File 'lib/easy_menu_helpers.rb', line 11

def css_class
  config[:"#{config_name}_class"]
end

#html_option_keysObject



32
33
34
# File 'lib/easy_menu_helpers.rb', line 32

def html_option_keys
  HTML_OPTIONS + @options.keys.select{|key| key.to_s.starts_with? 'data-'}
end

#merge_class(hash, *classes) ⇒ Object



27
28
29
30
# File 'lib/easy_menu_helpers.rb', line 27

def merge_class(hash, *classes)
  hash[:class] = ([hash[:class]] + classes.flatten).select(&:present?).join(' ')
  return hash
end

#wrap_content(content) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/easy_menu_helpers.rb', line 19

def wrap_content(content)
  if (wrapper_element)
    @template. wrapper_element, content, html_options
  else
    content
  end
end

#wrapper_elementObject



15
16
17
# File 'lib/easy_menu_helpers.rb', line 15

def wrapper_element
  config[:"#{config_name}_element"]
end