Class: GovukPublishingComponents::Presenters::ContextualNavigation
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ContextualNavigation
- Defined in:
- lib/govuk_publishing_components/presenters/contextual_navigation.rb
Instance Attribute Summary collapse
-
#content_item ⇒ Object
readonly
Returns the value of attribute content_item.
-
#query_parameters ⇒ Object
readonly
Returns the value of attribute query_parameters.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
Instance Method Summary collapse
- #breadcrumbs ⇒ Object
- #breadcrumbs_based_on_ancestors ⇒ Object
- #content_has_curated_related_items? ⇒ Boolean
- #content_has_related_organisations? ⇒ Boolean
- #content_is_a_corporate_information_page? ⇒ Boolean
- #content_is_a_html_publication? ⇒ Boolean
- #content_is_a_specialist_document? ⇒ Boolean
- #content_is_tagged_to_a_live_taxon? ⇒ Boolean
- #content_is_travel_advice? ⇒ Boolean
- #content_parent_is_mainstream_browse? ⇒ Boolean
- #content_tagged_to_a_finder? ⇒ Boolean
- #content_tagged_to_a_reasonable_number_of_step_by_steps? ⇒ Boolean
- #content_tagged_to_current_step_by_step? ⇒ Boolean
- #content_tagged_to_mainstream_browse_pages? ⇒ Boolean
- #content_tagged_to_other_step_by_steps? ⇒ Boolean
- #content_tagged_to_ukraine_topical_event? ⇒ Boolean
- #finder_breadcrumbs ⇒ Object
- #html_publication_with_parent? ⇒ Boolean
-
#initialize(content_item, request) ⇒ ContextualNavigation
constructor
A new instance of ContextualNavigation.
- #organisation_breadcrumbs ⇒ Object
- #parent_api_path ⇒ Object
- #parent_finder ⇒ Object
- #show_ukraine_cta? ⇒ Boolean
- #simple_smart_answer? ⇒ Boolean
- #step_nav_helper ⇒ Object
- #taxon_breadcrumbs ⇒ Object
- #use_organisation_breadcrumbs? ⇒ Boolean
- #use_taxon_breadcrumbs? ⇒ Boolean
Constructor Details
#initialize(content_item, request) ⇒ ContextualNavigation
Returns a new instance of ContextualNavigation.
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_item ⇒ Object (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_parameters ⇒ Object (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_path ⇒ Object (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
#breadcrumbs ⇒ Object
40 41 42 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 40 def end |
#breadcrumbs_based_on_ancestors ⇒ Object
132 133 134 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 132 def ContentBreadcrumbsBasedOnAncestors.call(content_item) end |
#content_has_curated_related_items? ⇒ Boolean
79 80 81 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 79 def content_item.dig("links", "ordered_related_items").present? && content_item.dig("links", "parent").present? end |
#content_has_related_organisations? ⇒ Boolean
83 84 85 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 83 def ContentItem.new(content_item)..present? end |
#content_is_a_corporate_information_page? ⇒ 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
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
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
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
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
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
67 68 69 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 67 def content_tagged_to_a_finder? content_item.dig("links", "finder").present? end |
#content_tagged_to_a_reasonable_number_of_step_by_steps? ⇒ Boolean
108 109 110 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 108 def content_tagged_to_a_reasonable_number_of_step_by_steps? step_nav_helper. end |
#content_tagged_to_current_step_by_step? ⇒ Boolean
103 104 105 106 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 103 def content_tagged_to_current_step_by_step? # TODO: remove indirection here step_nav_helper.show_header? end |
#content_tagged_to_mainstream_browse_pages? ⇒ Boolean
71 72 73 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 71 def content_tagged_to_mainstream_browse_pages? content_item.dig("links", "mainstream_browse_pages").present? end |
#content_tagged_to_other_step_by_steps? ⇒ Boolean
112 113 114 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 112 def content_tagged_to_other_step_by_steps? step_nav_helper.show_also_part_of_step_nav? end |
#content_tagged_to_ukraine_topical_event? ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 116 def content_tagged_to_ukraine_topical_event? 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_breadcrumbs ⇒ Object
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 return [] unless parent_finder [ { title: "Home", url: "/", }, { title: parent_finder["title"], url: parent_finder["base_path"], }, ] end |
#html_publication_with_parent? ⇒ 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_breadcrumbs ⇒ Object
36 37 38 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 36 def @organisation_breadcrumbs ||= ContentBreadcrumbsBasedOnOrganisations.call(content_item) end |
#parent_api_path ⇒ Object
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_finder ⇒ Object
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
128 129 130 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 128 def show_ukraine_cta? content_tagged_to_ukraine_topical_event? end |
#simple_smart_answer? ⇒ 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_helper ⇒ Object
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_breadcrumbs ⇒ Object
32 33 34 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 32 def @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.call(content_item) end |
#use_organisation_breadcrumbs? ⇒ Boolean
63 64 65 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 63 def content_is_a_corporate_information_page? && end |
#use_taxon_breadcrumbs? ⇒ Boolean
59 60 61 |
# File 'lib/govuk_publishing_components/presenters/contextual_navigation.rb', line 59 def content_is_tagged_to_a_live_taxon? && !content_is_a_specialist_document? end |