Sha256: 66c3cdf175d6057667f60ce7a0f4b5209ef5dc0efc31b0b043f9fea5671d9503

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

format :html do
  view :navbar_links, perms: :none do
    wrap_with :ul, class: "navbar-nav" do
      navbar_items
    end
  end

  # Iterates over all nests and links and renders them as bootstrap navbar items.
  # Items that are pointer cards become dropdowns
  def navbar_items view: :nav_item, link_class: "nav-link"
    process_content nil, chunk_list: :references do |chunk|
      case chunk
      when Card::Content::Chunk::Link
        navbar_link_chunk chunk, view, link_class
      when Card::Content::Chunk::Nest
        navbar_nest_chunk chunk, view
      else
        chunk.process_chunk
      end
    end
  end

  # overridden in Abstract::Items to render dropdown
  view :nav_item do
    wrap_with_nav_item link_view(class: "nav-link")
  end

  def wrap_with_nav_item content
    wrap_with(:li, content, class: "nav-item")
  end

  view :nav_link_in_dropdown do
    link_to_card card, render_title, class: "dropdown-item"
  end

  def nav_dropdown
    wrap_with(:li, class: "nav-item dropdown") do
      [
        dropdown_toggle_link,
        dropdown_menu
      ]
    end
  end

  def dropdown_toggle_link
    link_to(render_title, href: "#", class: "nav-link dropdown-toggle",
                          "data-bs-toggle": "dropdown")
  end

  def dropdown_menu
    wrap_with :div, dropdown_menu_items, class: "dropdown-menu"
  end

  def dropdown_menu_items
    navbar_items view: :nav_link_in_dropdown, link_class: "dropdown-item"
  end

  private

  def navbar_link_chunk chunk, view, link_class
    link = chunk.render_link view: view, explicit_link_opts: { class: link_class }
    chunk.explicit_link? && view == :nav_item ? wrap_with_nav_item(link) : link
  end

  def navbar_nest_chunk chunk, view
    content_nest chunk.options.merge view: view
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
card-mod-layout-0.18.1 set/all/navbar_links.rb
card-mod-layout-0.18.0 set/all/navbar_links.rb
card-mod-layout-0.17.0 set/all/navbar_links.rb
card-mod-layout-0.16.0 set/all/navbar_links.rb
card-mod-layout-0.15.6 set/all/navbar_links.rb
card-mod-layout-0.15.5 set/all/navbar_links.rb
card-mod-layout-0.15.4 set/all/navbar_links.rb
card-mod-layout-0.15.3 set/all/navbar_links.rb
card-mod-layout-0.15.2.pre1 set/all/navbar_links.rb
card-mod-layout-0.15.1.1 set/all/navbar_links.rb
card-mod-layout-0.15.1 set/all/navbar_links.rb
card-mod-layout-0.15.0 set/all/navbar_links.rb