Class: GovukPublishingComponents::Presenters::ContextualNavigation

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/contextual_navigation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_item, request) ⇒ ContextualNavigation

Returns a new instance of ContextualNavigation.

Parameters:

  • content_item

    A content item hash with strings as keys

  • request_path

    ‘request.path`



9
10
11
12
13
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 9

def initialize(content_item, request)
  @content_item = content_item
  @request_path = simple_smart_answer? ? content_item["base_path"] : request.path
  @query_parameters = request.query_parameters
end

Instance Attribute Details

#content_itemObject (readonly)

Returns the value of attribute content_item.



5
6
7
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 5

def content_item
  @content_item
end

#query_parametersObject (readonly)

Returns the value of attribute query_parameters.



5
6
7
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 5

def query_parameters
  @query_parameters
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



5
6
7
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 5

def request_path
  @request_path
end

Instance Method Details



40
41
42
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 40

def breadcrumbs
  breadcrumbs_based_on_ancestors
end


132
133
134
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 132

def breadcrumbs_based_on_ancestors
  ContentBreadcrumbsBasedOnAncestors.call(content_item)
end

Returns:

  • (Boolean)


79
80
81
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 79

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

Returns:

  • (Boolean)


83
84
85
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 83

def content_has_related_organisations?
  ContentItem.new(content_item).related_organisations.present?
end

#content_is_a_corporate_information_page?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 95

def content_is_a_corporate_information_page?
  content_item["schema_name"] == "corporate_information_page"
end

#content_is_a_html_publication?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 99

def content_is_a_html_publication?
  content_item["document_type"] == "html_publication"
end

#content_is_a_specialist_document?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 91

def content_is_a_specialist_document?
  content_item["schema_name"] == "specialist_document"
end

#content_is_tagged_to_a_live_taxon?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 87

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

#content_is_travel_advice?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 19

def content_is_travel_advice?
  content_item["document_type"] == "travel_advice"
end

#content_parent_is_mainstream_browse?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 75

def content_parent_is_mainstream_browse?
  content_item.dig("links", "parent").present? && content_item.dig("links", "parent", 0, "document_type") == "mainstream_browse_page"
end

#content_tagged_to_a_finder?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 67

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

#content_tagged_to_a_reasonable_number_of_step_by_steps?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 108

def 
  step_nav_helper.show_related_links?
end

#content_tagged_to_current_step_by_step?Boolean

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 103

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

#content_tagged_to_mainstream_browse_pages?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 71

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

#content_tagged_to_other_step_by_steps?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 112

def 
  step_nav_helper.show_also_part_of_step_nav?
end

#content_tagged_to_ukraine_topical_event?Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 116

def 
  ukraine_topical_event_id = "bfa79635-ffda-4b5d-8266-a9cd3a03649c"
  topical_events = content_item.dig("links", "topical_events").to_a
  topical_events.each do |topical_event|
    if topical_event["content_id"].eql?(ukraine_topical_event_id)
      return true
    end
  end

  false
end

#finder_breadcrumbsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 44

def finder_breadcrumbs
  return [] unless parent_finder

  [
    {
      title: "Home",
      url: "/",
    },
    {
      title: parent_finder["title"],
      url: parent_finder["base_path"],
    },
  ]
end

#html_publication_with_parent?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 23

def html_publication_with_parent?
  (content_item["document_type"] == "html_publication") && parent_api_path
end

#organisation_breadcrumbsObject



36
37
38
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 36

def organisation_breadcrumbs
  @organisation_breadcrumbs ||= ContentBreadcrumbsBasedOnOrganisations.call(content_item)
end

#parent_api_pathObject



27
28
29
30
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 27

def parent_api_path
  parent = content_item.dig("links", "parent")&.first
  parent["base_path"] if parent
end

#parent_finderObject



140
141
142
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 140

def parent_finder
  @parent_finder ||= content_item.dig("links", "finder", 0)
end

#show_ukraine_cta?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 128

def show_ukraine_cta?
  
end

#simple_smart_answer?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 15

def simple_smart_answer?
  content_item["document_type"] == "simple_smart_answer"
end

#step_nav_helperObject



136
137
138
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 136

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

#taxon_breadcrumbsObject



32
33
34
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 32

def taxon_breadcrumbs
  @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.call(content_item)
end

#use_organisation_breadcrumbs?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 63

def use_organisation_breadcrumbs?
  content_is_a_corporate_information_page? && content_has_related_organisations?
end

#use_taxon_breadcrumbs?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 59

def use_taxon_breadcrumbs?
  content_is_tagged_to_a_live_taxon? && !content_is_a_specialist_document?
end