Module: MaquinaComponents::BreadcrumbsHelper

Defined in:
app/helpers/maquina_components/breadcrumbs_helper.rb

Overview

Breadcrumbs Helper

Provides helper methods for rendering breadcrumb navigation. Supports both simple hash-based API and composable partials.

Instance Method Summary collapse

Instance Method Details

Render breadcrumbs from a hash of links

Examples:

Basic usage

breadcrumbs({"Home" => root_path, "Users" => users_path}, "John Doe")

Without current page

breadcrumbs({"Home" => root_path, "Users" => users_path})

Parameters:

  • links (Hash) (defaults to: {})

    Hash of text => path pairs

  • current_page (String, nil) (defaults to: nil)

    Text for current page (no link)

  • css_classes (String) (defaults to: "")

    Additional CSS classes for nav element

Returns:

  • (String)

    HTML string



23
24
25
26
27
28
29
# File 'app/helpers/maquina_components/breadcrumbs_helper.rb', line 23

def breadcrumbs(links = {}, current_page = nil, css_classes: "")
  render "components/breadcrumbs", css_classes: css_classes do
    render "components/breadcrumbs/list" do
      build_breadcrumb_items(links, current_page, responsive: false)
    end
  end
end

#responsive_breadcrumbs(links = {}, current_page = nil, css_classes: "", collapse_after: nil) ⇒ String

Render responsive breadcrumbs that auto-collapse on overflow

Uses Stimulus controller to hide middle items when space is limited, showing an ellipsis element instead.

collapse_after is accepted and ignored. It existed only because the width-based collapse never fired -- the last item's flex-shrink absorbed the overflow, so scrollWidth never exceeded clientWidth -- and it compensated by collapsing on item count alone, with no idea how much room there was. Space-based collapsing works now, so a count threshold can only collapse a bar that fits. Still in the signature so existing callers do not raise; drop it in 0.8.0.

Examples:

responsive_breadcrumbs(
  {"Home" => root_path, "Docs" => docs_path, "Components" => components_path},
  "Button"
)

Parameters:

  • links (Hash) (defaults to: {})

    Hash of text => path pairs

  • current_page (String, nil) (defaults to: nil)

    Text for current page (no link)

  • css_classes (String) (defaults to: "")

    Additional CSS classes for nav element

  • collapse_after (Integer) (defaults to: nil)

    Deprecated, ignored. Removed in 0.8.0.

Returns:

  • (String)

    HTML string



55
56
57
58
59
60
61
# File 'app/helpers/maquina_components/breadcrumbs_helper.rb', line 55

def responsive_breadcrumbs(links = {}, current_page = nil, css_classes: "", collapse_after: nil)
  render "components/breadcrumbs", css_classes: css_classes, responsive: true do
    render "components/breadcrumbs/list" do
      build_breadcrumb_items(links, current_page, responsive: true)
    end
  end
end