Class: Olelo::MenuItem
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from Menu
Instance Method Summary collapse
- #build_menu ⇒ Object
-
#initialize(name, options = {}) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #path ⇒ Object
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, = {}) super(name) @parent = nil @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
79 80 81 |
# File 'lib/olelo/menu.rb', line 79 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
80 81 82 |
# File 'lib/olelo/menu.rb', line 80 def parent @parent end |
Instance Method Details
#build_menu ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/olelo/menu.rb', line 92 def attrs = .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 |
#path ⇒ Object
88 89 90 |
# File 'lib/olelo/menu.rb', line 88 def path parent ? parent.path << super : super end |