Sha256: 8ce5c38fee2040a747b9743206f31a9d4ddaf51c7131fd0e0c0793bf9c5bd926

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

module GovukNavigationHelpers
  class TaxonBreadcrumbs
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govuk_navigation_helpers-9.2.1 lib/govuk_navigation_helpers/taxon_breadcrumbs.rb