Sha256: fcfa657e43f16de90421c6e1489f678ae7ec055948de8cab2cf6a8767245ad69

Contents?: true

Size: 1.94 KB

Versions: 38

Compression:

Stored size: 1.94 KB

Contents

module GovukPublishingComponents
  module Presenters
    # @private
    class ContextualNavigation
      attr_reader :content_item, :request_path

      # @param content_item A content item hash with strings as keys
      # @param request_path `request.path`
      def initialize(content_item, request_path)
        @content_item = content_item
        @request_path = request_path
      end

      def taxonomy_sidebar
        @taxonomy_sidebar ||= TaxonomyNavigation.new(content_item).sidebar
      end

      def taxon_breadcrumbs
        @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.new(content_item).breadcrumbs
      end

      def breadcrumbs
        if content_item["schema_name"] == "specialist_document"
          parent_finder = content_item.dig("links", "finder", 0)
          return [] unless parent_finder

          [
            {
              title: "Home",
              url: "/",
            },
            {
              title: parent_finder['title'],
              url: parent_finder['base_path'],
            }
          ]
        else
          ContentBreadcrumbsBasedOnParent.new(content_item).breadcrumbs[:breadcrumbs]
        end
      end

      def content_tagged_to_mainstream_browse_pages?
        content_item.dig("links", "mainstream_browse_pages").present?
      end

      def content_has_curated_related_items?
        content_item.dig("links", "ordered_related_items").present?
      end

      def content_is_tagged_to_a_live_taxon?
        content_item.dig("links", "taxons").to_a.any? { |taxon| taxon["phase"] == "live" }
      end

      def content_tagged_to_single_step_by_step?
        # TODO: remove indirection here
        step_nav_helper.show_header?
      end

      def content_tagged_to_a_reasonable_number_of_step_by_steps?
        step_nav_helper.show_related_links?
      end

      def step_nav_helper
        @step_nav_helper ||= PageWithStepByStepNavigation.new(content_item, request_path)
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
govuk_publishing_components-9.12.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.11.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.10.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.9.1 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.9.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.8.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.7.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.6.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.5.3 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.5.2 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.5.1 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.5.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.4.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.6 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.5 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.4 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.3 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.2 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.1 lib/govuk_publishing_components/presenters/contextual_navigation.rb
govuk_publishing_components-9.3.0 lib/govuk_publishing_components/presenters/contextual_navigation.rb