Sha256: 28035837d4dedff1650e2b104f3aa64ed2c6e328ec99ec415cbbff00f48e6903

Contents?: true

Size: 974 Bytes

Versions: 251

Compression:

Stored size: 974 Bytes

Contents

module GovukPublishingComponents
  module Presenters
    # @private
    class ContentBreadcrumbsBasedOnTaxons
      def initialize(content_item)
        @content_item = ContentItem.new(content_item)
      end

      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?
        }

        {
          breadcrumbs: ordered_parents.reverse
        }
      end

    private

      attr_reader :content_item

      def all_parents
        parents = []

        direct_parent = content_item.parent_taxon
        while direct_parent
          parents << direct_parent
          direct_parent = direct_parent.parent_taxon
        end

        parents
      end
    end
  end
end

Version data entries

251 entries across 251 versions & 1 rubygems

Version Path
govuk_publishing_components-21.27.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.27.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.26.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.26.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.26.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.25.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.24.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.23.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.23.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.22.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.22.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.22.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.21.3 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.21.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.21.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.21.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.20.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.19.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.19.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
govuk_publishing_components-21.18.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb