Module: Layered::Ui::NavigationHelper

Defined in:
app/helpers/layered/ui/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details

#l_ui_navigation_item(label, path, active: nil, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/layered/ui/navigation_helper.rb', line 4

def l_ui_navigation_item(label, path, active: nil, &block)
  if block_given?
    children = capture(&block)
    is_active = active.nil? ? (current_page?(path) || children.include?("l-ui-navigation__item--active")) : active
    css_class = is_active ? "l-ui-navigation__item--active" : "l-ui-navigation__item"
    options = { class: css_class }
    options["aria-current"] = "page" if is_active && current_page?(path)
    (:li) do
      link_to(label, path, options) +
        (:ul, children, class: "l-ui-navigation__secondary", role: "list")
    end
  else
    is_active = active.nil? ? current_page?(path) : active
    css_class = is_active ? "l-ui-navigation__item--active" : "l-ui-navigation__item"
    options = { class: css_class }
    options["aria-current"] = "page" if is_active
    (:li) { link_to label, path, options }
  end
end