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



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

def breadcrumbs
  breadcrumbs_based_on_ancestors
end


116
117
118
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 116

def breadcrumbs_based_on_ancestors
  ContentBreadcrumbsBasedOnAncestors.call(content_item)
end

Returns:

  • (Boolean)


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

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

#content_is_a_html_publication?Boolean

Returns:

  • (Boolean)


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

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

#content_is_a_specialist_document?Boolean

Returns:

  • (Boolean)


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

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

#content_is_tagged_to_a_live_taxon?Boolean

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#content_tagged_to_a_reasonable_number_of_step_by_steps?Boolean

Returns:

  • (Boolean)


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

def 
  step_nav_helper.show_related_links?
end

#content_tagged_to_current_step_by_step?Boolean

Returns:

  • (Boolean)


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

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

#content_tagged_to_mainstream_browse_pages?Boolean

Returns:

  • (Boolean)


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

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

#content_tagged_to_other_step_by_steps?Boolean

Returns:

  • (Boolean)


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

def 
  step_nav_helper.show_also_part_of_step_nav?
end

#content_tagged_to_ukraine_topical_event?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 100

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 40

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

#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



124
125
126
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 124

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

#show_ukraine_cta?Boolean

Returns:

  • (Boolean)


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

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



120
121
122
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 120

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_taxon_breadcrumbs?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 55

def use_taxon_breadcrumbs?
  content_is_tagged_to_a_live_taxon? && !content_is_a_specialist_document?
end