Sha256: d97f4fe4b14dcbcc5a8ff1a4f13c822393cb8d21697e78e60c2afde41a63ac0e

Contents?: true

Size: 782 Bytes

Versions: 314

Compression:

Stored size: 782 Bytes

Contents

module GovukPublishingComponents
  module Presenters
    class ContentBreadcrumbsBasedOnTopic
      def self.call(content_item)
        new(content_item).breadcrumbs
      end

      attr_reader :content_item

      def initialize(content_item)
        @content_item = content_item
      end

      def breadcrumbs
        breadcrumbs = [{ title: "Home", url: "/" }]
        return breadcrumbs unless topics.present?

        breadcrumbs << topic_breadcrumb
        breadcrumbs
      end

      def topic_breadcrumb
        {
          title: first_topic["title"],
          url: first_topic["base_path"],
        }
      end

      def first_topic
        topics.first
      end

      def topics
        @topics ||= content_item.dig("links", "topics")
      end
    end
  end
end

Version data entries

314 entries across 314 versions & 1 rubygems

Version Path
govuk_publishing_components-37.0.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-36.1.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-36.0.3 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-36.0.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-36.0.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-36.0.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.23.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.22.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.21.4 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.21.3 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.21.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.21.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.21.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.20.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.20.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.19.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.18.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.17.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.16.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-35.16.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb