govuk_publishing_components 21.52.1 → 21.53.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65eb0fccf1664b1adcf30dd55e74c36e06f066c820af124c0552d44ebbe78d31
4
- data.tar.gz: e9b31f220f80191550b6e4674b29971dea1a1caf707ef586733cb13b42137642
3
+ metadata.gz: 9b75297c083a34e5136622cab23b3e1b393318cf789a15ba9c5deca7d96a4115
4
+ data.tar.gz: 6cf830ee77d6f2126b007ed24a55e905d42884b80cac984d29bd900b1d1dbb3f
5
5
  SHA512:
6
- metadata.gz: a28ae072f25f52aa4c900228f8e12f0939de188df0d47aa74d594fc43eb57d4bf180413a7e902a82a9aacec8d5747dc2c4f124a762a39edd44684693ecad0b3a
7
- data.tar.gz: b8501ea511d02c48db9b3fa4ffa27c7db8178caf5c427dcc6b74adedfaba54a006695df9cf13153fec95507ef10bf2be557cca4a2e089fdfbc4ae5c5c35bad75
6
+ metadata.gz: 365054c463d00d090f45861e6ce505a99c97b39e477759d94e1595254024c68bebaa02c329ec50b2635712d8a4fb7e1de34b17439473ee2136a0993a51fcdf97
7
+ data.tar.gz: f4a3fc8fc08f9e3e10840bcb8ef0bde1c94da69ef388ee6b5cf2be405ce4424bd35315a300c3e640af310a76e3c666c6ad2213bcfe9eaa47a084c9a1e314f6bf
@@ -1,47 +1,16 @@
1
- <% navigation = GovukPublishingComponents::Presenters::ContextualNavigation.new(content_item, request) %>
2
1
  <% prioritise_taxon_breadcrumbs ||= false %>
2
+ <% breadcrumb_selector = GovukPublishingComponents::Presenters::BreadcrumbSelector.call(content_item, request, prioritise_taxon_breadcrumbs) %>
3
3
  <% inverse ||= false %>
4
4
  <% collapse_on_mobile ||= true unless local_assigns[:collapse_on_mobile].eql?(false) %>
5
5
 
6
6
  <div class='gem-c-contextual-breadcrumbs'>
7
-
8
- <% if navigation.priority_taxon %>
9
- <%= render 'govuk_publishing_components/components/step_by_step_nav_header',
10
- {
11
- title: navigation.priority_taxon['title'],
12
- path: navigation.priority_taxon['base_path']
13
- }
14
- %>
15
- <% elsif navigation.content_tagged_to_current_step_by_step? %>
16
- <%# Rendering step by step nav breadcrumbs because there's 1 step by step %>
7
+ <% if breadcrumb_selector[:step_by_step] %>
17
8
  <%= render 'govuk_publishing_components/components/step_by_step_nav_header',
18
- navigation.step_nav_helper.header %>
19
- <% elsif navigation.content_tagged_to_a_finder? %>
20
- <%# Rendering finder breadcrumbs because the page is tagged to a finder %>
21
- <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse, collapse_on_mobile: collapse_on_mobile %>
22
- <% elsif navigation.content_is_tagged_to_a_live_taxon? && prioritise_taxon_breadcrumbs %>
23
- <%# Rendering taxonomy breadcrumbs because the page is tagged to live taxons
24
- and we want to prioritise them over all other breadcrumbs %>
9
+ breadcrumb_selector[:breadcrumbs] %>
10
+ <% elsif breadcrumb_selector[:breadcrumbs] %>
25
11
  <%= render 'govuk_publishing_components/components/breadcrumbs',
26
- breadcrumbs: navigation.taxon_breadcrumbs[:breadcrumbs],
12
+ breadcrumbs: breadcrumb_selector[:breadcrumbs],
27
13
  inverse: inverse,
28
14
  collapse_on_mobile: collapse_on_mobile %>
29
- <% elsif navigation.content_tagged_to_mainstream_browse_pages? %>
30
- <%# Rendering parent-based breadcrumbs because the page is tagged to mainstream browse %>
31
- <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse, collapse_on_mobile: collapse_on_mobile %>
32
- <% elsif navigation.content_has_curated_related_items? %>
33
- <%# Rendering parent-based breadcrumbs because the page has curated related links %>
34
- <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse, collapse_on_mobile: collapse_on_mobile %>
35
- <% elsif navigation.content_is_tagged_to_a_live_taxon? && !navigation.content_is_a_specialist_document? %>
36
- <%# Rendering taxonomy breadcrumbs because the page is tagged to live taxons %>
37
- <%= render 'govuk_publishing_components/components/breadcrumbs',
38
- breadcrumbs: navigation.taxon_breadcrumbs[:breadcrumbs],
39
- inverse: inverse,
40
- collapse_on_mobile: collapse_on_mobile %>
41
- <% elsif navigation.breadcrumbs.any? %>
42
- <%# Rendering parent-based breadcrumbs because no browse, no related links, no live taxons %>
43
- <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: navigation.breadcrumbs, inverse: inverse, collapse_on_mobile: collapse_on_mobile %>
44
- <% else %>
45
- <%# Not rendering any breadcrumbs because there aren't any %>
46
15
  <% end %>
47
16
  </div>
@@ -6,6 +6,7 @@ require "govuk_publishing_components/engine"
6
6
  require "govuk_publishing_components/presenters/shared_helper"
7
7
  require "govuk_publishing_components/presenters/attachment"
8
8
  require "govuk_publishing_components/presenters/breadcrumbs"
9
+ require "govuk_publishing_components/presenters/breadcrumb_selector"
9
10
  require "govuk_publishing_components/presenters/button_helper"
10
11
  require "govuk_publishing_components/presenters/contextual_navigation"
11
12
  require "govuk_publishing_components/presenters/related_navigation_helper"
@@ -0,0 +1,105 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class BreadcrumbSelector
4
+ def self.call(*args)
5
+ new(*args).output
6
+ end
7
+
8
+ attr_reader :content_item, :request, :prioritise_taxon_breadcrumbs
9
+
10
+ def initialize(content_item, request, prioritise_taxon_breadcrumbs)
11
+ @content_item = content_item
12
+ @request = request
13
+ @prioritise_taxon_breadcrumbs = prioritise_taxon_breadcrumbs
14
+ end
15
+
16
+ def content_item_navigation
17
+ @content_item_navigation ||= ContextualNavigation.new(content_item, request)
18
+ end
19
+
20
+ def parent_item_navigation
21
+ @parent_item_navigation ||= ContextualNavigation.new(parent_item, request)
22
+ end
23
+
24
+ def parent_item
25
+ @parent_item ||= Services.content_store.content_item(content_item_navigation.parent_api_path)
26
+ rescue GdsApi::ContentStore::ItemNotFound
27
+ # Do nothing
28
+ end
29
+
30
+ def parent_item_options
31
+ @parent_item_options ||= options(parent_item_navigation)
32
+ end
33
+
34
+ def content_item_options
35
+ @content_item_options ||= options(content_item_navigation)
36
+ end
37
+
38
+ def parent_breadcrumbs
39
+ breadcrumbs = [parent_item_options[:breadcrumbs]].flatten # to ensure breadcrumbs always an array
40
+ breadcrumbs.last[:is_page_parent] = false
41
+ breadcrumbs << {
42
+ title: parent_item["title"],
43
+ url: parent_item["base_path"],
44
+ is_page_parent: true,
45
+ }
46
+ end
47
+
48
+ def output
49
+ return content_item_options unless content_item_navigation.html_document_with_parent?
50
+ return parent_item_options if parent_item_navigation.priority_breadcrumbs
51
+
52
+ {
53
+ step_by_step: parent_item_options[:step_by_step],
54
+ breadcrumbs: parent_breadcrumbs,
55
+ }
56
+ end
57
+
58
+ def options(navigation)
59
+ if navigation.priority_breadcrumbs
60
+ {
61
+ step_by_step: true,
62
+ breadcrumbs: navigation.priority_breadcrumbs,
63
+ }
64
+ elsif navigation.content_tagged_to_current_step_by_step?
65
+ {
66
+ step_by_step: true,
67
+ breadcrumbs: navigation.step_nav_helper.header,
68
+ }
69
+ elsif navigation.content_tagged_to_a_finder?
70
+ {
71
+ step_by_step: false,
72
+ breadcrumbs: navigation.breadcrumbs,
73
+ }
74
+ elsif navigation.content_is_tagged_to_a_live_taxon? && prioritise_taxon_breadcrumbs
75
+ {
76
+ step_by_step: false,
77
+ breadcrumbs: navigation.taxon_breadcrumbs,
78
+ }
79
+ elsif navigation.content_tagged_to_mainstream_browse_pages?
80
+ {
81
+ step_by_step: false,
82
+ breadcrumbs: navigation.breadcrumbs,
83
+ }
84
+ elsif navigation.content_has_curated_related_items?
85
+ {
86
+ step_by_step: false,
87
+ breadcrumbs: navigation.breadcrumbs,
88
+ }
89
+ elsif navigation.use_taxon_breadcrumbs?
90
+ {
91
+ step_by_step: false,
92
+ breadcrumbs: navigation.taxon_breadcrumbs,
93
+ }
94
+ elsif navigation.breadcrumbs.any?
95
+ {
96
+ step_by_step: false,
97
+ breadcrumbs: navigation.breadcrumbs,
98
+ }
99
+ else
100
+ {}
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -11,7 +11,7 @@ module GovukPublishingComponents
11
11
 
12
12
  # Returns the highest priority taxon that has a content_id matching those in PRIORITY_TAXONS
13
13
  def self.call(content_item)
14
- new(content_item).taxon
14
+ new(content_item).breadcrumbs
15
15
  end
16
16
 
17
17
  attr_reader :content_item
@@ -24,9 +24,15 @@ module GovukPublishingComponents
24
24
  @taxon ||= priority_taxons.min_by { |t| PRIORITY_TAXONS.values.index(t["content_id"]) }
25
25
  end
26
26
 
27
+ def breadcrumbs
28
+ taxon && { title: taxon["title"], path: taxon["base_path"] }
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def priority_taxons
34
+ return [] unless content_item["links"].is_a?(Hash)
35
+
30
36
  taxons = content_item.dig("links", "taxons")
31
37
  taxon_tree(taxons).select do |taxon|
32
38
  priority_taxon?(taxon)
@@ -21,9 +21,7 @@ module GovukPublishingComponents
21
21
  is_page_parent: ordered_parents.empty?,
22
22
  }
23
23
 
24
- {
25
- breadcrumbs: ordered_parents.reverse,
26
- }
24
+ ordered_parents.reverse
27
25
  end
28
26
 
29
27
  private
@@ -16,32 +16,41 @@ module GovukPublishingComponents
16
16
  content_item["document_type"] == "simple_smart_answer"
17
17
  end
18
18
 
19
+ def html_document_with_parent?
20
+ (content_item["document_type"] == "html_publication") && parent_api_path
21
+ end
22
+
23
+ def parent_api_path
24
+ parent = content_item.dig("links", "parent")&.first
25
+ parent["base_path"] if parent
26
+ end
27
+
19
28
  def taxon_breadcrumbs
20
29
  @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.new(content_item).breadcrumbs
21
30
  end
22
31
 
23
- def priority_taxon
24
- @priority_taxon ||= ContentBreadcrumbsBasedOnPriority.call(content_item)
32
+ def priority_breadcrumbs
33
+ @priority_breadcrumbs ||= ContentBreadcrumbsBasedOnPriority.call(content_item)
25
34
  end
26
35
 
27
36
  def breadcrumbs
28
- if content_tagged_to_a_finder?
29
- parent_finder = content_item.dig("links", "finder", 0)
30
- return [] unless parent_finder
31
-
32
- [
33
- {
34
- title: "Home",
35
- url: "/",
36
- },
37
- {
38
- title: parent_finder["title"],
39
- url: parent_finder["base_path"],
40
- },
41
- ]
42
- else
43
- ContentBreadcrumbsBasedOnParent.new(content_item).breadcrumbs[:breadcrumbs]
44
- end
37
+ return breadcrumbs_based_on_parent unless content_tagged_to_a_finder?
38
+ return [] unless parent_finder
39
+
40
+ [
41
+ {
42
+ title: "Home",
43
+ url: "/",
44
+ },
45
+ {
46
+ title: parent_finder["title"],
47
+ url: parent_finder["base_path"],
48
+ },
49
+ ]
50
+ end
51
+
52
+ def use_taxon_breadcrumbs?
53
+ content_is_tagged_to_a_live_taxon? && !content_is_a_specialist_document?
45
54
  end
46
55
 
47
56
  def content_tagged_to_a_finder?
@@ -64,6 +73,10 @@ module GovukPublishingComponents
64
73
  content_item["schema_name"] == "specialist_document"
65
74
  end
66
75
 
76
+ def content_is_a_html_publication?
77
+ content_item["document_type"] == "html_publication"
78
+ end
79
+
67
80
  def tagged_to_brexit?
68
81
  taxons = content_item.dig("links", "taxons").to_a
69
82
  brexit_taxon = "d6c2de5d-ef90-45d1-82d4-5f2438369eea"
@@ -106,9 +119,17 @@ module GovukPublishingComponents
106
119
  step_nav_helper.show_also_part_of_step_nav?
107
120
  end
108
121
 
122
+ def breadcrumbs_based_on_parent
123
+ ContentBreadcrumbsBasedOnParent.new(content_item).breadcrumbs[:breadcrumbs]
124
+ end
125
+
109
126
  def step_nav_helper
110
127
  @step_nav_helper ||= PageWithStepByStepNavigation.new(content_item, request_path, query_parameters)
111
128
  end
129
+
130
+ def parent_finder
131
+ @parent_finder ||= content_item.dig("links", "finder", 0)
132
+ end
112
133
  end
113
134
  end
114
135
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "21.52.1".freeze
2
+ VERSION = "21.53.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.52.1
4
+ version: 21.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -748,6 +748,7 @@ files:
748
748
  - lib/govuk_publishing_components/engine.rb
749
749
  - lib/govuk_publishing_components/minitest/component_guide_test.rb
750
750
  - lib/govuk_publishing_components/presenters/attachment.rb
751
+ - lib/govuk_publishing_components/presenters/breadcrumb_selector.rb
751
752
  - lib/govuk_publishing_components/presenters/breadcrumbs.rb
752
753
  - lib/govuk_publishing_components/presenters/button_helper.rb
753
754
  - lib/govuk_publishing_components/presenters/checkboxes_helper.rb