Class: Spark::NavMenuHelper::TreeNav

Inherits:
MenuHelper::Menu show all
Defined in:
app/helpers/spark/nav_menu_helper.rb

Direct Known Subclasses

SidebarNav

Constant Summary

Constants inherited from MenuHelper::Menu

MenuHelper::Menu::DEFAULTS

Instance Method Summary collapse

Methods inherited from MenuHelper::Menu

#display, #group, #header, #link

Constructor Details

#initialize(title = nil, options = {}) ⇒ TreeNav

Returns a new instance of TreeNav.



29
30
31
32
33
34
35
36
# File 'app/helpers/spark/nav_menu_helper.rb', line 29

def initialize( title = nil, options = {} )
  config({
    tag: :ul,
    base_class: 'nav-tree',
    role: 'tree'
  })
  super( title, options )
end

Instance Method Details

#item(content, url, options = {}, &block) ⇒ Object



38
39
40
41
42
# File 'app/helpers/spark/nav_menu_helper.rb', line 38

def item(content, url, options={}, &block)
  options['role'] = 'treeitem'

  super( content, url, options, &block )
end

#item_tree(name, options = {}, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/spark/nav_menu_helper.rb', line 44

def item_tree( name, options={}, &block )
  content, url, options = parse_item_args( "#", options, &block)

  return if content.blank? ||
            ( options.include?('if') && !options.delete('if') ) ||
            ( options.include?('unless') && !!options.delete('unless') )

  node = Spark::Helpers.dasherize( name.strip.downcase ).gsub('-','_')
  active  = !!(options.delete( 'active' ) || content.match(/item-active/))

  options.merge!({
    'role' => 'treeitem',
    'aria-expanded' => active || is_expanded?(node),
    'data-node' => node
  })

  name, options = set_content( name, options )

  classes = [config[:base_class] + "-item-wrapper"]
  classes.push( 'tree-active' ) if !!( options.delete( 'active' ) || content.match(/item-active/))

  options = add_class( options, classes )

  ( config[:item_tag], options ) do
    concat link_to("#", class: config[:base_class] + '-item'){
      concat name.call
      concat use_svg( 'chevron-down', class: 'expand-icon'  )
    }
    concat ( :ul, role: 'group', class: config[:base_class] + '-group' ) { content }
  end
end