Class: Olelo::MenuItem

Inherits:
Menu show all
Defined in:
lib/olelo/menu.rb

Instance Attribute Summary collapse

Attributes inherited from Menu

#name

Instance Method Summary collapse

Methods inherited from Menu

#<<, #[], #append, #clear, #each, #empty?, #html_id, #item, #remove, #to_html

Methods included from Util

#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?

Constructor Details

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

Returns a new instance of MenuItem.



82
83
84
85
86
# File 'lib/olelo/menu.rb', line 82

def initialize(name, options = {})
  super(name)
  @parent = nil
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



79
80
81
# File 'lib/olelo/menu.rb', line 79

def options
  @options
end

#parentObject

Returns the value of attribute parent.



80
81
82
# File 'lib/olelo/menu.rb', line 80

def parent
  @parent
end

Instance Method Details

#build_menuObject



92
93
94
95
96
97
98
99
# File 'lib/olelo/menu.rb', line 92

def build_menu
  attrs = options.dup
  label = attrs.delete(:label) || Locale.translate("menu_#{path.join('_')}", fallback: titlecase(name))
  klass = [*attrs.delete(:class)].flatten.compact
  klass = klass.empty? ? '' : %{class="#{klass.join(' ')}" }
  attrs = attrs.map {|k,v| %{#{k}="#{escape_html v}"} }.join(' ')
  %{<li #{klass}id="item-#{html_id}"><a #{attrs}>#{escape_html label}</a>#{super}</li>}
end

#pathObject



88
89
90
# File 'lib/olelo/menu.rb', line 88

def path
  parent ? parent.path << super : super
end