govuk_publishing_components 21.50.0 → 21.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/all_components.js +1 -3
  3. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +3 -0
  4. data/app/assets/javascripts/govuk_publishing_components/components/button.js +5 -0
  5. data/app/assets/javascripts/govuk_publishing_components/components/character-count.js +3 -0
  6. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +2 -1
  7. data/app/assets/javascripts/govuk_publishing_components/components/error-summary.js +3 -0
  8. data/app/assets/javascripts/govuk_publishing_components/components/header.js +5 -0
  9. data/app/assets/javascripts/govuk_publishing_components/components/radio.js +3 -0
  10. data/app/assets/javascripts/govuk_publishing_components/components/tabs.js +5 -0
  11. data/app/assets/javascripts/govuk_publishing_components/lib.js +1 -0
  12. data/app/assets/javascripts/govuk_publishing_components/modules.js +15 -3
  13. data/app/assets/stylesheets/component_guide/application.scss +0 -7
  14. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +4 -13
  15. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +7 -2
  16. data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +13 -4
  17. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_steps.scss +1 -1
  18. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss +0 -3
  19. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +24 -0
  20. data/app/views/govuk_publishing_components/component_guide/index.html.erb +8 -1
  21. data/app/views/govuk_publishing_components/components/_action_link.html.erb +16 -8
  22. data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +5 -36
  23. data/app/views/govuk_publishing_components/components/_input.html.erb +12 -1
  24. data/app/views/govuk_publishing_components/components/docs/input.yml +9 -0
  25. data/lib/govuk_publishing_components.rb +1 -0
  26. data/lib/govuk_publishing_components/presenters/breadcrumb_selector.rb +105 -0
  27. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority.rb +19 -9
  28. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb +1 -3
  29. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +40 -19
  30. data/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb +5 -29
  31. data/lib/govuk_publishing_components/version.rb +1 -1
  32. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 159d020ba82914af6816875f569ef650b3bde9b0a3573048c576cdd2e3b0d864
4
- data.tar.gz: 777fcff7c030364ae8018fee71e746c24ab1b60aaa4a08bc7a1665ffe704086e
3
+ metadata.gz: 9b75297c083a34e5136622cab23b3e1b393318cf789a15ba9c5deca7d96a4115
4
+ data.tar.gz: 6cf830ee77d6f2126b007ed24a55e905d42884b80cac984d29bd900b1d1dbb3f
5
5
  SHA512:
6
- metadata.gz: cf14fda6410001b1c39da5fc1e878ad6865cf0ba4d13110b1af3ea0c9bf2745ff949ab7ade06cf12449e34a3855108d655e92b5b32ce42e5dd78b2a5f94a0692
7
- data.tar.gz: 7e8af37602ddc795cba2d4f5c2c81888169bd9a0919ec9c5c16db2c1fd298aa6a0a62b331ce5579ae6afee9069af07c793a2d58a473b853dc0325b55c3a4caa4
6
+ metadata.gz: 365054c463d00d090f45861e6ce505a99c97b39e477759d94e1595254024c68bebaa02c329ec50b2635712d8a4fb7e1de34b17439473ee2136a0993a51fcdf97
7
+ data.tar.gz: f4a3fc8fc08f9e3e10840bcb8ef0bde1c94da69ef388ee6b5cf2be405ce4424bd35315a300c3e640af310a76e3c666c6ad2213bcfe9eaa47a084c9a1e314f6bf
@@ -1,6 +1,4 @@
1
1
  // = require_tree ./lib
2
2
  // = require_tree ./components
3
- // = require govuk/all.js
4
3
 
5
- // Initialise all GOVUKFrontend components
6
- window.GOVUKFrontend.initAll()
4
+ window.GOVUKFrontend.initAll = function () {}
@@ -1,2 +1,5 @@
1
1
  // This component relies on JavaScript from GOV.UK Frontend
2
2
  // = require govuk/components/accordion/accordion.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Accordion = window.GOVUKFrontend
@@ -0,0 +1,5 @@
1
+ // This component relies on JavaScript from GOV.UK Frontend
2
+ // = require govuk/components/button/button.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Button = window.GOVUKFrontend
@@ -1,2 +1,5 @@
1
1
  // This component relies on JavaScript from GOV.UK Frontend
2
2
  // = require govuk/components/character-count/character-count.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.CharacterCount = window.GOVUKFrontend
@@ -1,7 +1,8 @@
1
1
  /* eslint-env jquery */
2
2
  // = require govuk/components/checkboxes/checkboxes.js
3
3
  window.GOVUK = window.GOVUK || {}
4
- window.GOVUK.Modules = window.GOVUK.Modules || {};
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Checkboxes = window.GOVUKFrontend;
5
6
 
6
7
  (function (Modules) {
7
8
  'use strict'
@@ -1,2 +1,5 @@
1
1
  // This component relies on JavaScript from GOV.UK Frontend
2
2
  // = require govuk/components/error-summary/error-summary.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.ErrorSummary = window.GOVUKFrontend
@@ -0,0 +1,5 @@
1
+ // This component relies on JavaScript from GOV.UK Frontend
2
+ // = require govuk/components/header/header.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Header = window.GOVUKFrontend
@@ -1,2 +1,5 @@
1
1
  // This component relies on JavaScript from GOV.UK Frontend
2
2
  // = require govuk/components/radios/radios.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Radios = window.GOVUKFrontend
@@ -0,0 +1,5 @@
1
+ // This component relies on JavaScript from GOV.UK Frontend
2
+ // = require govuk/components/tabs/tabs.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.Tabs = window.GOVUKFrontend
@@ -0,0 +1 @@
1
+ // = require_tree ./lib
@@ -28,13 +28,25 @@
28
28
  for (var i = 0, l = modules.length; i < l; i++) {
29
29
  var module
30
30
  var element = $(modules[i])
31
- var type = camelCaseAndCapitalise(element.data('module'))
31
+ var moduleName = camelCaseAndCapitalise(element.data('module'))
32
32
  var started = element.data('module-started')
33
+ var frontendModuleName = moduleName.replace('Govuk', '')
33
34
 
34
- if (typeof GOVUK.Modules[type] === 'function' && !started) {
35
- module = new GOVUK.Modules[type]()
35
+ if ( // GOV.UK Publishing & Legacy Modules
36
+ typeof GOVUK.Modules[moduleName] === 'function' &&
37
+ !GOVUK.Modules[moduleName].prototype.init &&
38
+ !started
39
+ ) {
40
+ module = new GOVUK.Modules[moduleName]()
36
41
  module.start(element)
37
42
  element.data('module-started', true)
43
+ } else if ( // GOV.UK Frontend Modules
44
+ typeof GOVUK.Modules[frontendModuleName] === 'function' &&
45
+ GOVUK.Modules[frontendModuleName].prototype.init &&
46
+ !started
47
+ ) {
48
+ module = new GOVUK.Modules[frontendModuleName](element[0]).init()
49
+ element.data('module-started', true)
38
50
  }
39
51
  }
40
52
 
@@ -1,12 +1,5 @@
1
1
  // This file contains the styles for the Component Guide.
2
2
 
3
- @import "govuk_publishing_components/components/helpers/govuk-frontend-settings";
4
- @import "govuk_publishing_components/components/helpers/markdown-typography";
5
- @import "govuk/settings/all";
6
- @import "govuk/tools/all";
7
- @import "govuk/helpers/all";
8
- @import "govuk/core/all";
9
-
10
3
  @import "govuk_publishing_components/all_components";
11
4
 
12
5
  $gem-guide-border-width: 1px;
@@ -1,20 +1,11 @@
1
1
  // This is the file that the application needs to include in order to use
2
2
  // the components.
3
3
 
4
- // Include all of the GOV.UK Frontend styles. This includes fonts, and individual components.
4
+ @import "govuk_publishing_components/govuk_frontend_support";
5
+ @import "govuk_publishing_components/component_support";
5
6
 
6
- @import "components/helpers/govuk-frontend-settings";
7
-
8
- // Include common imports used by many components
9
- @import "govuk/all";
10
-
11
- @import "components/helpers/variables";
12
- @import "components/helpers/brand-colours";
13
- @import "components/mixins/govuk-template-link-focus-override";
14
- @import "components/mixins/media-down";
15
- @import "components/mixins/margins";
16
- @import "components/mixins/clearfix";
17
- @import "components/mixins/css3";
7
+ // Include all govuk frontend components
8
+ @import "govuk/components/all";
18
9
 
19
10
  // components
20
11
  @import "components/accordion";
@@ -20,6 +20,11 @@
20
20
  }
21
21
  }
22
22
 
23
+ .gem-c-action-link__contents-wrapper {
24
+ display: table-cell;
25
+ vertical-align: middle;
26
+ }
27
+
23
28
  .gem-c-action-link__link-wrapper {
24
29
  @include govuk-font(19, $weight: bold, $line-height: 1.3);
25
30
  display: table-cell;
@@ -89,7 +94,7 @@
89
94
  background-image: image-url("govuk_publishing_components/action-link-arrow--simple.svg");
90
95
  // sass-lint:enable no-duplicate-properties
91
96
  background-size: 25px auto;
92
- background-position: 0 0;
97
+ background-position: 0 2px;
93
98
  }
94
99
 
95
100
  .gem-c-action-link__link {
@@ -112,7 +117,7 @@
112
117
  background-image: image-url("govuk_publishing_components/action-link-arrow--dark.svg");
113
118
  // sass-lint:enable no-duplicate-properties
114
119
  background-size: 25px auto;
115
- background-position: 0 0;
120
+ background-position: 0 2px;
116
121
  }
117
122
 
118
123
  .gem-c-action-link__link {
@@ -31,22 +31,31 @@
31
31
  }
32
32
  }
33
33
 
34
+ .gem-c-input__prefix,
34
35
  .gem-c-input__suffix {
35
36
  @include govuk-font($size: 19);
36
37
 
37
38
  background-color: govuk-colour("light-grey", $legacy: "grey-3");
38
39
  border: $govuk-border-width-form-element solid $govuk-input-border-colour;
39
- border-left: 0;
40
40
  box-sizing: border-box;
41
41
  cursor: default; // emphasise non-editable status of prefixes and suffixes
42
42
  display: inline-block;
43
- flex: 0 0 0;
44
- padding: govuk-spacing(1);
45
43
  white-space: nowrap;
46
44
  width: auto;
45
+ text-align: center;
47
46
  height: 40px;
47
+ padding: govuk-spacing(1);
48
+ min-width: 40px;
48
49
  @if $govuk-typography-use-rem {
49
- height: govuk-px-to-rem(40px);
50
+ min-width: govuk-px-to-rem(40px);
50
51
  }
51
52
  margin-top: 0;
52
53
  }
54
+
55
+ .gem-c-input__prefix {
56
+ border-right: 0;
57
+ }
58
+
59
+ .gem-c-input__suffix {
60
+ border-left: 0;
61
+ }
@@ -10,7 +10,7 @@
10
10
  margin-left: 0;
11
11
  padding: .75em 0 .75em 2.5em;
12
12
 
13
- @for $i from 1 through 14 {
13
+ @for $i from 1 through 30 {
14
14
  &:nth-child(#{$i}) {
15
15
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Ccircle cx='125' cy='125' r='100' fill='black' /%3E%3Ctext x='50%25' y='50%25' text-anchor='middle' alignment-baseline='middle' font-family='sans-serif' font-size='100px' fill='white'%3E#{$i}%3C/text%3E%3C/svg%3E");
16
16
  background-repeat: no-repeat;
@@ -1,6 +1,3 @@
1
- @import "govuk/settings/colours-organisations";
2
- @import "govuk/helpers/colour";
3
-
4
1
  @mixin organisation-brand-colour {
5
2
  @each $organisation in map-keys($govuk-colours-organisations) {
6
3
  .brand--#{$organisation} {
@@ -10,6 +10,7 @@ module GovukPublishingComponents
10
10
  @components_in_use_docs = components_in_use_docs.used_in_this_app
11
11
  @components_in_use_sass = components_in_use_sass(false)
12
12
  @components_in_use_print_sass = components_in_use_sass(true)
13
+ @components_in_use_js = components_in_use_js
13
14
  end
14
15
 
15
16
  def show
@@ -62,6 +63,25 @@ module GovukPublishingComponents
62
63
  }.compact.uniq.sort.join("\n").squeeze("\n").prepend(additional_files)
63
64
  end
64
65
 
66
+ def components_in_use_js
67
+ additional_files = "//= require govuk_publishing_components/lib\n"
68
+
69
+ components = components_in_use
70
+ extra_components = []
71
+
72
+ components.each do |component|
73
+ components_in_component = components_within_component(component)
74
+ extra_components << components_in_component
75
+ end
76
+
77
+ components << extra_components.compact
78
+ components = components.flatten.uniq.sort
79
+
80
+ components.map { |component|
81
+ "//= require govuk_publishing_components/components/#{component.gsub('_', '-')}" if component_has_js_file(component.gsub("_", "-"))
82
+ }.compact.uniq.sort.join("\n").squeeze("\n").prepend(additional_files)
83
+ end
84
+
65
85
  private
66
86
 
67
87
  def component_docs
@@ -95,6 +115,10 @@ module GovukPublishingComponents
95
115
  Pathname.new(@component_gem_path + "/app/assets/stylesheets/govuk_publishing_components/components/#{print_path}_#{component}.scss").exist?
96
116
  end
97
117
 
118
+ def component_has_js_file(component)
119
+ Pathname.new(@component_gem_path + "/app/assets/javascripts/govuk_publishing_components/components/#{component}.js").exist?
120
+ end
121
+
98
122
  def components_within_component(component)
99
123
  data = File.read(@component_gem_path + "/app/views/govuk_publishing_components/components/_#{component}.html.erb")
100
124
  match = data.scan(/(govuk_publishing_components\/components\/[a-z_-]+)/)
@@ -20,7 +20,7 @@
20
20
  <h2 class="component-doc-h2">Gem components used by this app (<%= @components_in_use_docs.length %>)</h2>
21
21
 
22
22
  <%= render "govuk_publishing_components/components/details", {
23
- title: "Suggested Sass for this application"
23
+ title: "Suggested imports for this application"
24
24
  } do %>
25
25
  <%= render "govuk_publishing_components/components/textarea", {
26
26
  label: {
@@ -36,6 +36,13 @@
36
36
  name: "print-sass",
37
37
  value: @components_in_use_print_sass
38
38
  } %>
39
+ <%= render "govuk_publishing_components/components/textarea", {
40
+ label: {
41
+ text: "Add this to your application's main js file, before your other local imports."
42
+ },
43
+ name: "main-js",
44
+ value: @components_in_use_js
45
+ } %>
39
46
  <% end %>
40
47
  <pre>
41
48
 
@@ -24,16 +24,24 @@
24
24
  %>
25
25
  <% if href.present? && text.present? %>
26
26
  <div class="<%= css_classes.join(' ') %>">
27
- <span class="gem-c-action-link__link-wrapper">
28
- <%= link_to href, :class => link_classes, :data => data do %>
29
- <%= text %>
30
- <%= content_tag(:span, nowrap_text, class: "gem-c-action-link__nowrap-text") if nowrap_text %>
27
+ <% contents = capture do %>
28
+ <span class="gem-c-action-link__link-wrapper">
29
+ <%= link_to href, :class => link_classes, :data => data do %>
30
+ <%= text %>
31
+ <%= content_tag(:span, nowrap_text, class: "gem-c-action-link__nowrap-text") if nowrap_text %>
32
+ <% end %>
33
+ </span>
34
+ <% if subtext %>
35
+ <span class="gem-c-action-link__subtext-wrapper">
36
+ <%= content_tag(:span, subtext, class: "gem-c-action-link__subtext") %>
37
+ </span>
31
38
  <% end %>
32
- </span>
39
+ <% end %>
40
+
33
41
  <% if subtext %>
34
- <span class="gem-c-action-link__subtext-wrapper">
35
- <%= content_tag(:span, subtext, class: "gem-c-action-link__subtext") %>
36
- </span>
42
+ <%= content_tag(:span, contents, class: "gem-c-action-link__contents-wrapper") %>
43
+ <% else %>
44
+ <%= contents %>
37
45
  <% end %>
38
46
  </div>
39
47
  <% end %>
@@ -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>
@@ -22,6 +22,7 @@
22
22
  error_id = "error-#{SecureRandom.hex(4)}"
23
23
  search_icon ||= nil
24
24
  heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
25
+ prefix ||= nil
25
26
  suffix ||= nil
26
27
 
27
28
  css_classes = %w(gem-c-input govuk-input)
@@ -92,7 +93,17 @@
92
93
  }
93
94
  %>
94
95
 
95
- <% if suffix %>
96
+ <% if prefix && suffix %>
97
+ <%= tag.div class: "gem-c-input__wrapper" do %>
98
+ <%= tag.span prefix, class: "gem-c-input__prefix", aria: { hidden: true } %>
99
+ <%= input_tag %>
100
+ <%= tag.span suffix, class: "gem-c-input__suffix", aria: { hidden: true } %>
101
+ <% end %>
102
+ <% elsif prefix %>
103
+ <%= tag.div class: "gem-c-input__wrapper" do %>
104
+ <%= tag.span prefix, class: "gem-c-input__prefix", aria: { hidden: true } %><%= input_tag %>
105
+ <% end %>
106
+ <% elsif suffix %>
96
107
  <%= tag.div class: "gem-c-input__wrapper" do %>
97
108
  <%= input_tag %><%= tag.span suffix, class: "gem-c-input__suffix", aria: { hidden: true } %>
98
109
  <% end %>
@@ -140,6 +140,15 @@ examples:
140
140
  name: "lead-times"
141
141
  width: 10
142
142
  suffix: "days"
143
+ with_prefix_and_suffix:
144
+ description: To help users understand how the input should look like. Often used for units of measurement.
145
+ data:
146
+ label:
147
+ text: "Cost per item, in pounds"
148
+ name: "Cost-per-item"
149
+ width: 10
150
+ prefix: "£"
151
+ suffix: "per item"
143
152
  with_suffix_and_error:
144
153
  description: To help users understand how the input should look like. Often used for units of measurement.
145
154
  data:
@@ -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,19 +24,29 @@ 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
30
- taxons = content_item.dig("links", "taxons")&.map do |taxon|
31
- taxon.dig("links", "parent_taxons")&.select do |parent_taxon|
32
- PRIORITY_TAXONS.values.include?(parent_taxon["content_id"])
33
- end
34
+ return [] unless content_item["links"].is_a?(Hash)
35
+
36
+ taxons = content_item.dig("links", "taxons")
37
+ taxon_tree(taxons).select do |taxon|
38
+ priority_taxon?(taxon)
34
39
  end
35
- return [] unless taxons
40
+ end
41
+
42
+ def taxon_tree(taxons)
43
+ return [] if taxons.blank?
44
+
45
+ taxons + taxons.flat_map { |taxon| taxon_tree(taxon.dig("links", "parent_taxons")) }
46
+ end
36
47
 
37
- taxons.flatten!
38
- taxons.compact!
39
- taxons
48
+ def priority_taxon?(taxon)
49
+ PRIORITY_TAXONS.values.include?(taxon["content_id"])
40
50
  end
41
51
  end
42
52
  end
@@ -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
@@ -58,29 +58,10 @@ module GovukPublishingComponents
58
58
  question = page.title
59
59
 
60
60
  doc.xpath("html/body").children.each_with_object({}) do |element, q_and_as|
61
- _q_and_as, question = recursive_question_and_answers(element, question, q_and_as)
62
- end
63
- end
64
-
65
- def recursive_question_and_answers(element, question, q_and_as)
66
- if is_a_question?(element)
67
- question = element.text
68
- q_and_as[question] = { anchor: element["id"] }
69
- else
70
- q_and_as = add_answer_to_question(q_and_as, element, question)
71
- element.children.each do |child_element|
72
- if child_element.element?
73
- q_and_as, question = recursive_question_and_answers(child_element, question, q_and_as)
74
- end
75
- end
76
- end
77
-
78
- [q_and_as, question]
79
- end
80
-
81
- def add_answer_to_question(q_and_as, element, question)
82
- if no_questions_in_subtree?(element)
83
- if question_hash_is_unset?(q_and_as, question)
61
+ if question_element?(element)
62
+ question = element.text
63
+ q_and_as[question] = { anchor: element["id"] }
64
+ elsif question_hash_is_unset?(q_and_as, question)
84
65
  q_and_as[question] = { answer: element.to_s }
85
66
  elsif answer_is_unset?(q_and_as, question)
86
67
  q_and_as[question][:answer] = element.to_s
@@ -88,11 +69,6 @@ module GovukPublishingComponents
88
69
  q_and_as[question][:answer] << element.to_s
89
70
  end
90
71
  end
91
- q_and_as
92
- end
93
-
94
- def no_questions_in_subtree?(element)
95
- element.search(QUESTION_TAG).none?
96
72
  end
97
73
 
98
74
  def question_hash_is_unset?(q_and_as, question)
@@ -106,7 +82,7 @@ module GovukPublishingComponents
106
82
  # we use H2 tags as the "question" and the html between them as the "answer"
107
83
  QUESTION_TAG = "h2".freeze
108
84
 
109
- def is_a_question?(element)
85
+ def question_element?(element)
110
86
  element.name == QUESTION_TAG
111
87
  end
112
88
 
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "21.50.0".freeze
2
+ VERSION = "21.53.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.50.0
4
+ version: 21.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters
@@ -408,6 +408,7 @@ files:
408
408
  - app/assets/javascripts/component_guide/visual-regression.js
409
409
  - app/assets/javascripts/govuk_publishing_components/all_components.js
410
410
  - app/assets/javascripts/govuk_publishing_components/components/accordion.js
411
+ - app/assets/javascripts/govuk_publishing_components/components/button.js
411
412
  - app/assets/javascripts/govuk_publishing_components/components/character-count.js
412
413
  - app/assets/javascripts/govuk_publishing_components/components/checkboxes.js
413
414
  - app/assets/javascripts/govuk_publishing_components/components/contextual-guidance.js
@@ -417,11 +418,14 @@ files:
417
418
  - app/assets/javascripts/govuk_publishing_components/components/error-summary.js
418
419
  - app/assets/javascripts/govuk_publishing_components/components/feedback.js
419
420
  - app/assets/javascripts/govuk_publishing_components/components/govspeak.js
421
+ - app/assets/javascripts/govuk_publishing_components/components/header.js
420
422
  - app/assets/javascripts/govuk_publishing_components/components/initial-focus.js
421
423
  - app/assets/javascripts/govuk_publishing_components/components/modal-dialogue.js
422
424
  - app/assets/javascripts/govuk_publishing_components/components/radio.js
423
425
  - app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
426
+ - app/assets/javascripts/govuk_publishing_components/components/tabs.js
424
427
  - app/assets/javascripts/govuk_publishing_components/dependencies.js
428
+ - app/assets/javascripts/govuk_publishing_components/lib.js
425
429
  - app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js
426
430
  - app/assets/javascripts/govuk_publishing_components/lib/current-location.js
427
431
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js
@@ -744,6 +748,7 @@ files:
744
748
  - lib/govuk_publishing_components/engine.rb
745
749
  - lib/govuk_publishing_components/minitest/component_guide_test.rb
746
750
  - lib/govuk_publishing_components/presenters/attachment.rb
751
+ - lib/govuk_publishing_components/presenters/breadcrumb_selector.rb
747
752
  - lib/govuk_publishing_components/presenters/breadcrumbs.rb
748
753
  - lib/govuk_publishing_components/presenters/button_helper.rb
749
754
  - lib/govuk_publishing_components/presenters/checkboxes_helper.rb