Module: NavHelper
- Defined in:
- app/helpers/nav_helper.rb
Constant Summary collapse
- NAV_CLASS =
'nav'.freeze
- NAV_TABS_CLASS =
'nav-tabs'.freeze
- NAV_PILLS_CLASS =
'nav-pills'.freeze
- NAV_CLASSES =
[NAV_TABS_CLASS, NAV_PILLS_CLASS]
Instance Method Summary collapse
- #nav(options = {}, type = NAV_TABS_CLASS, &block) ⇒ Object (also: #tabs)
- #nav_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #pills(*args, &block) ⇒ Object
Instance Method Details
#nav(options = {}, type = NAV_TABS_CLASS, &block) ⇒ Object Also known as: tabs
7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/nav_helper.rb', line 7 def nav( = {}, type = NAV_TABS_CLASS, &block) , type = {}, unless .is_a?(Hash) [:class] ||= [] [:class] = [*[:class]] [:class].unshift(NAV_CLASS) unless [:class].include?(NAV_CLASS) [:class] << type unless NAV_CLASSES.any? { |c| [:class].include?(c) } = if block_given? content_tag(:ul, , , &block) end |
#nav_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
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, = nil, = nil, &block) if block_given? , = name, else = end ||= {} active = .try(:delete, :active) active = current_page?() if active.nil? tab_class = active ? 'active' : nil content_tag(:li, role: 'presentation', class: tab_class) do link_to(name, , , &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 |