Module: NavHelper

Defined in:
app/helpers/nav_helper.rb

Constant Summary collapse

'nav'.freeze
'nav-tabs'.freeze
'nav-pills'.freeze
[NAV_TABS_CLASS, NAV_PILLS_CLASS]

Instance Method Summary collapse

Instance Method Details



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/nav_helper.rb', line 7

def nav(options = {}, type = NAV_TABS_CLASS, &block)
  options, type = {}, options unless options.is_a?(Hash)
  options[:class] ||= []
  options[:class] = [*options[:class]]
  options[:class].unshift(NAV_CLASS) unless options[:class].include?(NAV_CLASS)
  options[:class] << type unless NAV_CLASSES.any? { |c| options[:class].include?(c) }

  content_or_options_with_block = options if block_given?
  (:ul, content_or_options_with_block, options, &block)
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/nav_helper.rb', line 23

def nav_to(name = nil, options = nil, html_options = nil, &block)
  if block_given?
    url_options, html_options = name, options
  else
    url_options = options
  end

  url_options ||= {}

  active = html_options.try(:delete, :active)
  active = current_page?(url_options) if active.nil?
  tab_class = active ? 'active' : nil

  (:li, role: 'presentation', class: tab_class) do
    link_to(name, options, html_options, &block)
  end
end

#pills(*args, &block) ⇒ Object



19
20
21
# File 'app/helpers/nav_helper.rb', line 19

def pills(*args, &block)
  nav(*args, NAV_PILLS_CLASS, &block)
end