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.9.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.9.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.8.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.8.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.7.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.7.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.6.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.6.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.5.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.5.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.4.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.3.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.3.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.2.4 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.2.3 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.2.2 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.2.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.2.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.1.1 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
govuk_publishing_components-37.1.0 lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb