Class: Spark::MenuHelper::Menu
- Defined in:
- app/helpers/spark/menu_helper.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULTS =
{ tag: :div, role: :menu, base_class: 'menu', header_tag: :h4, group_tag: :ul, item_tag: :li }
Instance Method Summary collapse
- #display(body) ⇒ Object
- #group(title = nil, options = {}, &block) ⇒ Object
- #header(text = nil, options = {}, &block) ⇒ Object
-
#initialize(title = nil, options = {}) ⇒ Menu
constructor
A new instance of Menu.
- #item(content = nil, url = nil, options = nil, &block) ⇒ Object
- #link(content = nil, url = nil, options = nil, &block) ⇒ Object
Constructor Details
#initialize(title = nil, options = {}) ⇒ Menu
Returns a new instance of Menu.
13 14 15 16 17 18 |
# File 'app/helpers/spark/menu_helper.rb', line 13 def initialize( title = nil, = {} ) , title = title, nil if title.is_a? Hash @options = add_class( , config[:base_class] ) @options['aria-label'] = title if title end |
Instance Method Details
#display(body) ⇒ Object
20 21 22 23 24 25 |
# File 'app/helpers/spark/menu_helper.rb', line 20 def display( body ) @options.merge!({ role: config[:role] }) content_tag( config[:tag], @options ) do concat( body ) end end |
#group(title = nil, options = {}, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/spark/menu_helper.rb', line 47 def group( title=nil, ={}, &block ) = add_class( , config[:base_class] + "-group" ) ['role'] = 'group' content = capture( &block ) return if content.blank? || ( .include?('if') && !.delete('if') ) || ( .include?('unless') && !!.delete('unless') ) concat header( title ) if title content_tag( config[:group_tag], , &block ) end |
#header(text = nil, options = {}, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/spark/menu_helper.rb', line 27 def header( text = nil, = {}, &block ) , text = text, nil if text.is_a?( Hash ) = add_class( , config[:base_class] + "-header" ) content_tag( :header, ) { concat( content_tag( config[:header_tag], text, class: config[:base_class] + '-title' ) ) if text concat( capture( &block ).html_safe ) if block_given? } end |
#item(content = nil, url = nil, options = nil, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/spark/menu_helper.rb', line 60 def item( content=nil, url=nil, =nil, &block ) content, url, = parse_item_args( content, url, , &block) return if ( .include?('if') && !.delete('if') ) || ( .include?('unless') && !!.delete('unless') ) if url content_tag( config[:item_tag], role: 'none', class: config[:base_class] + "-item-wrapper" ) do link( url, ) { content } end else content, = set_content( content, ) = add_class( , config[:base_class] + "-item" ) content_tag( config[:item_tag], , &content ) end end |
#link(content = nil, url = nil, options = nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/spark/menu_helper.rb', line 37 def link( content=nil, url=nil, =nil, &block ) content, url, = parse_item_args( content, url, , &block) content, = set_content( content, ) = add_class( , config[:base_class] + "-item" ) ['role'] ||= 'menuitem' link_to( url, , &content ) end |