Class: GovukPublishingComponents::AppHelpers::TaxonBreadcrumbs

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/app_helpers/taxon_breadcrumbs.rb

Defined Under Namespace

Classes: ContentItem

Instance Method Summary collapse

Constructor Details

#initialize(content_item) ⇒ TaxonBreadcrumbs

Returns a new instance of TaxonBreadcrumbs.

Parameters:

  • content_item

    A taxon



5
6
7
# File 'lib/govuk_publishing_components/app_helpers/taxon_breadcrumbs.rb', line 5

def initialize(content_item)
  @content_item = TaxonBreadcrumbs::ContentItem.new(content_item)
end

Instance Method Details

Generate a breadcrumb trail for a taxon, using the taxon_parent link field

Returns:

  • (Hash)

    Payload for the GOV.UK breadcrumbs component

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/govuk_publishing_components/app_helpers/taxon_breadcrumbs.rb', line 13

def breadcrumbs
  ordered_parents = all_parents.map.with_index do |parent, index|
    {
      title: parent.title,
      url: parent.base_path,
      is_page_parent: index.zero?,
    }
  end

  ordered_parents << {
    title: "Home",
    url: "/",
    is_page_parent: ordered_parents.empty?,
  }

  ordered_parents.reverse
end