Module: Compass::Breadcrumb

Defined in:
lib/compass/breadcrumb.rb,
lib/compass/breadcrumb/strategies/http.rb,
lib/compass/breadcrumb/strategies/cookie.rb

Overview

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

Defined Under Namespace

Modules: Strategies

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: current_context, max: 5)
=> [
 { url: "/home", label: "Home" },
 { url: "/section", label: "Section" },
 { url: "/section/page", label: "Page" }
]

Parameters:

  • context (Compass::Context, nil)

    The request-scoped context. Strategies that need the request read it from context.request.

  • max (Integer) (defaults to: 10)

    The maximum number of items to return.

Returns:

  • (Array<Hash>, nil)

    The breadcrumb items, or nil when no strategy is configured.



27
28
29
# File 'lib/compass/breadcrumb.rb', line 27

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

.push(context:, url:, label:) ⇒ nil

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

I.e.:

Compass::Breadcrumb.push(
context: current_context,
url: "/section/page",
label: "Page"
)

Parameters:

  • context (Compass::Context, nil)

    The request-scoped context. Strategies that need the request read it from context.request.

  • url (String)

    The URL of the breadcrumb item.

  • label (String)

    The label of the breadcrumb item.

Returns:

  • (nil)


46
47
48
# File 'lib/compass/breadcrumb.rb', line 46

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