Sha256: 3d697833f92f59a2ea2491941316a9ec891acbd34cf69a21f8d75c7b3898cec8

Contents?: true

Size: 678 Bytes

Versions: 40

Compression:

Stored size: 678 Bytes

Contents

module GovukNavigationHelpers
  class Breadcrumbs
    def initialize(content_item)
      @content_item = ContentItem.new(content_item)
    end

    def breadcrumbs
      ordered_parents = all_parents.map do |parent|
        { title: parent.title, url: parent.base_path }
      end

      ordered_parents << { title: "Home", url: "/" }

      {
        breadcrumbs: ordered_parents.reverse
      }
    end

  private

    attr_reader :content_item

    def all_parents
      parents = []

      direct_parent = content_item.parent
      while direct_parent
        parents << direct_parent

        direct_parent = direct_parent.parent
      end

      parents
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
govuk_navigation_helpers-9.2.1 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-9.2.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-9.1.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-9.0.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.2.2 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.2.1 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.2.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.1.1 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.1.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-8.0.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.5.1 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.5.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.4.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.3.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.2.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.1.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-7.0.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-6.3.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-6.2.0 lib/govuk_navigation_helpers/breadcrumbs.rb
govuk_navigation_helpers-6.1.0 lib/govuk_navigation_helpers/breadcrumbs.rb