Module: Compass::Breadcrumb

Defined in:
lib/compass/breadcrumb.rb,
lib/compass/breadcrumb/middleware.rb

Overview

Compass breadcrumb handling module. It leverages the configured breadcrumb strategy to fetch and push breadcrumb items.

Defined Under Namespace

Classes: Middleware

Class Method Summary collapse

Class Method Details

.for(context: {}, max: 10) ⇒ Array<Hash>?

Fetch breadcrumb for the given context, using the configured strategy.

I.e.:

Compass::Breadcrumb.for(context_id, context: { current_user: }, max: 5)
 => [
   { url: "/home", label: "Home" },
   { url: "/section", label: "Section" },
   { url: "/section/page", label: "Page" }
 ]

Parameters:

  • context_id (String)

    The context identifier.

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

    The context hash.

  • max (Integer) (defaults to: 10)

    The maximum number of items to return.

Returns:

  • (Array<Hash>, nil)

    The breadcrumb items.



23
24
25
# File 'lib/compass/breadcrumb.rb', line 23

def self.for(context: {}, max: 10)
  Compass.config.breadcrumb.strategy&.for(context: context, max: max)
end

.push(context: {}, url:, label:) ⇒ Object

Push a new breadcrumb item for the given context, using the configured strategy.

I.e.:

Compass::Breadcrumb.push(
  context_id,
  context: { current_user: },
  url: "/section/page",
  label: "Page"
)

Parameters:

  • context_id (String)

    The context identifier.

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

    The context hash.

  • url (String)

    The URL of the breadcrumb item.

  • label (String)

    The label of the breadcrumb item.



42
43
44
# File 'lib/compass/breadcrumb.rb', line 42

def self.push(context: {}, url:, label:)
  Compass.config.breadcrumb.strategy&.push(context: context, url: url, label: label)
end