Sha256: 4ef278d010b76a6bc13e5b190ce0455c8efd9b5ca47b84922d58e8b2e8ad3bb8

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true
module EffectiveMenusHelper

  def render_menu(name, options = {}, &block)
    name = name.to_s
    menu = Array(EffectivePages.menus).find { |menu| menu.to_s == name }

    if menu.blank?
      raise("unable to find menu #{name}. Please add it to config/initializers/effective_pages.rb")
    end

    content_tag(:ul, options) { render('effective/pages/menu', menu: menu) }
  end

  def render_breadcrumbs(menu, page = @page, root: 'Home')
    return breadcrumbs_root_url(page, root: root) if request.path == '/'
    return breadcrumbs_fallback(page, root: root) unless page.kind_of?(Effective::Page)

    parents = [page.menu_parent].compact

    content_tag(:ol, class: 'breadcrumb') do
      (
        [content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item')] +
        parents.map do |page|
          url = (page.menu_url.presence || effective_pages.page_path(page))
          content_tag(:li, link_to(page, url, title: page.title), class: 'breadcrumb-item')
        end +
        [content_tag(:li, page, class: 'breadcrumb-item active', 'aria-current': 'page')]
      ).join.html_safe
    end
  end

  alias_method :render_breadcrumb, :render_breadcrumbs

  def breadcrumbs_root_url(page = @page, root: 'Home')
    content_tag(:ol, class: 'breadcrumb') do
      content_tag(:li, root, class: 'breadcrumb-item active', 'aria-current': 'page')
    end
  end

  def breadcrumbs_fallback(page = @page, root: 'Home')
    label = (page if page.kind_of?(Effective::Page)) || @page_title || 'Here'

    content_tag(:ol, class: 'breadcrumb') do
      [
        content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item'),
        content_tag(:li, label, class: 'breadcrumb-item active', 'aria-current': 'page')
      ].join.html_safe
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
effective_pages-3.1.0 app/helpers/effective_menus_helper.rb
effective_pages-3.0.10 app/helpers/effective_menus_helper.rb
effective_pages-3.0.9 app/helpers/effective_menus_helper.rb
effective_pages-3.0.8 app/helpers/effective_menus_helper.rb
effective_pages-3.0.7 app/helpers/effective_menus_helper.rb
effective_pages-3.0.6 app/helpers/effective_menus_helper.rb
effective_pages-3.0.5 app/helpers/effective_menus_helper.rb
effective_pages-3.0.4 app/helpers/effective_menus_helper.rb
effective_pages-3.0.3 app/helpers/effective_menus_helper.rb
effective_pages-3.0.2 app/helpers/effective_menus_helper.rb