govuk_publishing_components 34.1.0 → 34.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2070abba195716c8e72ea85dc7d7f207df27c52e497e808c8bc5d79c7b56b8af
4
- data.tar.gz: f9978ff5d94c66b454978bc58346b8a76f7ff5408210695fd38372e4e5d29c20
3
+ metadata.gz: 14acdf5801364f256fc2f6bbf90bc8f2e707ad2c6ec7efdec2107c6e049afec3
4
+ data.tar.gz: 16341b4908cd390fa02460a2ec1b42c3fcab5bfb2c5f6dcee2badb6c809a6d98
5
5
  SHA512:
6
- metadata.gz: c587c35eadec57a5515587e2064f5d55154cc9767a823015e4fb103bab8599bf367e2cfdbd5f58e65fd2612d690ba85b7760dd6535899ff5b90ad479b19a4ef9
7
- data.tar.gz: c888b0e1e6ef2f1fde331e163009bd6f84077bb8011fcc799612af5d00d72f52cec00935f7cd71e347dd2d357f6c9e98ccc91a0c277b0bc4763ca9cdf4123591
6
+ metadata.gz: 0d8a6b735e43f3dea62c1ec898254b619ef6d329423572b56bad4df236c356d0f7d585a2893c8b4ea1c65ed0c3bae098b62c616577cf92d08e950b776294496b
7
+ data.tar.gz: 1db3cf177445fa4aba896b725744b25df73e1ac8c623208754dc82f00437cc3c8d8ea066e6d04bc18d29efd8cb470c39757e775c46f4d2dc4b93c2fde54079f5
@@ -57,12 +57,12 @@
57
57
 
58
58
  .brand--prime-ministers-office-10-downing-street {
59
59
  .brand__color {
60
- color: govuk-colour("bright-purple");
60
+ color: govuk-colour("black");
61
61
 
62
62
  &:link,
63
63
  &:visited,
64
64
  &:active {
65
- color: govuk-colour("bright-purple");
65
+ color: govuk-colour("black");
66
66
  }
67
67
 
68
68
  &:hover,
@@ -34,7 +34,7 @@ module GovukPublishingComponents
34
34
  @in_application = false
35
35
  @in_application = true unless ENV["MAIN_COMPONENT_GUIDE"]
36
36
 
37
- components = AuditComponents.new(gem_path, false)
37
+ components = AuditComponents.new(gem_path)
38
38
  applications = analyse_applications(host_dir, application_dirs)
39
39
  compared_data = AuditComparer.new(components.data, applications)
40
40
 
@@ -252,7 +252,7 @@ module GovukPublishingComponents
252
252
  results = []
253
253
  found_something = false
254
254
 
255
- @gem_data[:component_listing].each do |component|
255
+ @gem_data[:component_file_details].each do |component|
256
256
  component_name = component[:name]
257
257
  locations = []
258
258
 
@@ -2,65 +2,123 @@ module GovukPublishingComponents
2
2
  class AuditComponents
3
3
  attr_reader :data
4
4
 
5
- def initialize(path, simple)
6
- @data = {
7
- gem_found: false,
8
- }
9
- @data = compile_data(path, simple) if Dir.exist?(path)
10
- end
11
-
12
- private
13
-
14
- def compile_data(path, simple)
15
- # simple is used to reduce effort (and therefore page load time) required
16
- # when loading auditing summary on the main component guide page
17
- @simple = simple
18
-
5
+ def initialize(path)
19
6
  # paths to key file locations
20
7
  @templates_path = "app/views/govuk_publishing_components/components"
21
8
  @stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components"
22
9
  @print_stylesheets_path = "app/assets/stylesheets/govuk_publishing_components/components/print"
23
10
  @javascripts_path = "app/assets/javascripts/govuk_publishing_components/components"
24
11
  @tests_path = "spec/components"
25
- @js_tests_path = "spec/javascripts/components"
12
+ @javascript_tests_path = "spec/javascripts/components"
26
13
  @helpers_path = "lib/govuk_publishing_components/presenters"
27
14
 
28
- # get all files in key file locations
29
- templates = Dir["#{path}/#{@templates_path}/*.erb"]
30
- stylesheets = Dir["#{path}/#{@stylesheets_path}/*.scss"]
31
- print_stylesheets = Dir["#{path}/#{@print_stylesheets_path}/*.scss"]
32
- javascripts = Dir["#{path}/#{@javascripts_path}/*.js"]
33
- tests = Dir["#{path}/#{@tests_path}/*.rb"]
34
- js_tests = Dir["#{path}/#{@js_tests_path}/*.js"]
35
- helpers = Dir["#{path}/#{@helpers_path}/*_helper.rb"]
36
-
15
+ @all_templates = Dir["#{path}/#{@templates_path}/*.erb"].sort
37
16
  @templates_full_path = "#{path}/#{@templates_path}/"
38
17
 
39
- # find the cleaned names of components in key file locations
40
- # i.e. will show that 'component name' has a stylesheet
41
- # standardised like this to be used later for easier comparison
42
- @components = clean_files(templates, [path, @templates_path].join("/"))
43
- @component_stylesheets = clean_files(stylesheets, [path, @stylesheets_path].join("/"))
44
- @component_print_stylesheets = clean_files(print_stylesheets, [path, @print_stylesheets_path].join("/"))
45
- @component_javascripts = clean_files(javascripts, [path, @javascripts_path].join("/"))
46
- @component_tests = clean_files(tests, [path, @tests_path].join("/"))
47
- @component_js_tests = clean_files(js_tests, [path, @js_tests_path].join("/"))
48
- @component_helpers = clean_files(helpers, [path, @helpers_path].join("/"))
18
+ @component_numbers = {
19
+ template: 0,
20
+ stylesheet: 0,
21
+ print_stylesheet: 0,
22
+ javascript: 0,
23
+ test: 0,
24
+ javascript_test: 0,
25
+ helper: 0,
26
+ }
49
27
 
28
+ @data = {
29
+ gem_found: false,
30
+ }
31
+ @data = compile_data(path) if Dir.exist?(path)
32
+ end
33
+
34
+ private
35
+
36
+ def compile_data(path)
50
37
  {
51
38
  gem_found: true,
52
- component_code: @components,
53
- component_stylesheets: @component_stylesheets,
54
- component_print_stylesheets: @component_print_stylesheets,
55
- component_javascripts: @component_javascripts,
56
- component_tests: @component_tests,
57
- component_js_tests: @component_js_tests,
58
- component_helpers: @component_helpers,
59
- components_containing_components: find_all_partials_in(templates),
60
- component_listing: list_all_component_details,
39
+ component_code: clean_files(@all_templates, @templates_full_path).sort,
40
+ components_containing_components: find_all_partials_in(@all_templates),
41
+ component_file_details: get_component_file_details(path),
42
+ component_numbers: @component_numbers,
61
43
  }
62
44
  end
63
45
 
46
+ def get_component_file_details(path)
47
+ component_templates = clean_files(@all_templates, @templates_full_path).sort
48
+ details = []
49
+ component_templates.each do |component|
50
+ component_detail = {
51
+ name: component,
52
+ link: get_component_link(component),
53
+ }
54
+ file_details = [
55
+ {
56
+ type: "template",
57
+ file: "#{[path, @templates_path].join('/')}/_#{component.gsub(' ', '_')}.html.erb",
58
+ },
59
+ {
60
+ type: "stylesheet",
61
+ file: "#{[path, @stylesheets_path].join('/')}/_#{component.gsub(' ', '-')}.scss",
62
+ },
63
+ {
64
+ type: "print_stylesheet",
65
+ file: "#{[path, @stylesheets_path].join('/')}/_#{component.gsub(' ', '-')}.scss",
66
+ },
67
+ {
68
+ type: "javascript",
69
+ file: "#{[path, @javascripts_path].join('/')}/#{component.gsub(' ', '-')}.js",
70
+ },
71
+ {
72
+ type: "test",
73
+ file: "#{[path, @tests_path].join('/')}/#{component.gsub(' ', '_')}_spec.rb",
74
+ },
75
+ {
76
+ type: "javascript_test",
77
+ file: "#{[path, @javascript_tests_path].join('/')}/#{component.gsub(' ', '-')}-spec.js",
78
+ },
79
+ {
80
+ type: "helper",
81
+ file: "#{[path, @helpers_path].join('/')}/#{component.gsub(' ', '_')}_helper.rb",
82
+ },
83
+ ]
84
+ file_details.each do |detail|
85
+ component_detail = component_detail.merge(get_component_asset_detail(detail, component))
86
+ end
87
+
88
+ details << component_detail
89
+ end
90
+
91
+ details
92
+ end
93
+
94
+ def get_component_asset_detail(detail, component)
95
+ details = {}
96
+ type = detail[:type]
97
+ file = detail[:file]
98
+ details["#{type}_exists".to_sym] = false
99
+ if File.file?(file)
100
+ # we don't have separate print stylesheets anymore
101
+ # so check the main stylesheet for print styles
102
+ if type == "print_stylesheet"
103
+ unless File.foreach(file).grep(/(media-type: print)/).empty?
104
+ details["#{type}_exists".to_sym] = true
105
+ @component_numbers[type.to_sym] += 1
106
+ end
107
+ else
108
+ @component_numbers[type.to_sym] += 1
109
+ details["#{type}_exists".to_sym] = true
110
+ details["#{type}_lines".to_sym] = count_lines_in(file)
111
+ details["#{type}_link".to_sym] = get_asset_link(type, component)
112
+ end
113
+ end
114
+
115
+ details
116
+ end
117
+
118
+ def count_lines_in(file)
119
+ File.read(file).each_line.count
120
+ end
121
+
64
122
  def clean_files(files, replace)
65
123
  files.map { |file| clean_file_name(file.gsub(replace, "")) }.sort
66
124
  end
@@ -91,8 +149,6 @@ module GovukPublishingComponents
91
149
  end
92
150
 
93
151
  def find_all_partials_in(templates)
94
- return [] if @simple
95
-
96
152
  components = []
97
153
 
98
154
  templates.each do |template|
@@ -144,52 +200,17 @@ module GovukPublishingComponents
144
200
  end
145
201
  end
146
202
 
147
- def list_all_component_details
148
- return [] if @simple
149
-
150
- all_component_information = []
151
-
152
- @components.each do |component|
153
- all_component_information << {
154
- name: component,
155
- link: get_component_link(component),
156
- stylesheet: check_component_has("stylesheet", component),
157
- print_stylesheet: check_component_has("print_stylesheet", component),
158
- javascript: check_component_has("javascript", component),
159
- tests: check_component_has("test", component),
160
- js_tests: check_component_has("js_test", component),
161
- helper: check_component_has("helper", component),
162
- }
163
- end
164
-
165
- all_component_information
166
- end
167
-
168
- def check_component_has(a_thing, component)
169
- look_in = @component_stylesheets if a_thing == "stylesheet"
170
- look_in = @component_print_stylesheets if a_thing == "print_stylesheet"
171
- look_in = @component_javascripts if a_thing == "javascript"
172
- look_in = @component_tests if a_thing == "test"
173
- look_in = @component_js_tests if a_thing == "js_test"
174
- look_in = @component_helpers if a_thing == "helper"
175
-
176
- if look_in.include?(component)
177
- return get_asset_link(a_thing, component)
178
- end
179
-
180
- false
181
- end
182
-
183
203
  def get_asset_link(a_thing, component)
184
204
  url = "https://github.com/alphagov"
185
205
  repo = "govuk_publishing_components"
186
206
  blob = "blob/main"
187
207
  link = nil
208
+ link = "#{url}/#{repo}/#{blob}/#{@templates_path}/_#{component.gsub(' ', '_')}.html.erb" if a_thing == "template"
188
209
  link = "#{url}/#{repo}/#{blob}/#{@stylesheets_path}/_#{component.gsub(' ', '-')}.scss" if a_thing == "stylesheet"
189
210
  link = "#{url}/#{repo}/#{blob}/#{@print_stylesheets_path}/_#{component.gsub(' ', '-')}.scss" if a_thing == "print_stylesheet"
190
211
  link = "#{url}/#{repo}/#{blob}/#{@javascripts_path}/#{component.gsub(' ', '-')}.js" if a_thing == "javascript"
191
212
  link = "#{url}/#{repo}/#{blob}/#{@tests_path}/#{component.gsub(' ', '_')}_spec.rb" if a_thing == "test"
192
- link = "#{url}/#{repo}/#{blob}/#{@js_tests_path}/#{component.gsub(' ', '-')}-spec.js" if a_thing == "js_test"
213
+ link = "#{url}/#{repo}/#{blob}/#{@javascript_tests_path}/#{component.gsub(' ', '-')}-spec.js" if a_thing == "javascript_test"
193
214
  link = "#{url}/#{repo}/#{blob}/#{@helpers_path}/#{component.gsub(' ', '_')}_helper.rb" if a_thing == "helper"
194
215
 
195
216
  link
@@ -12,7 +12,7 @@
12
12
  <%= render "govuk_publishing_components/components/details", {
13
13
  title: "How to use this information"
14
14
  } do %>
15
- <p class="govuk-body">This page shows information about component use on GOV.UK. This information has been cross referenced with the components in the gem to produce warnings where e.g. a print stylesheet for a component exists but has not been included in an application.</p>
15
+ <p class="govuk-body">This page shows information about component use on GOV.UK. This information has been cross referenced with the components in the gem to produce warnings where e.g. JavaScript for a component exists but has not been included in an application.</p>
16
16
  <p class="govuk-body">Warnings should be investigated, although there may be a reason why the application has been configured as it is. Note that 'code' can refer to templates or ruby code.</p>
17
17
  <% end %>
18
18
 
@@ -1,78 +1,86 @@
1
- <%
2
- total_components = components.length
3
- components_with_stylesheet = 0
4
- components_with_print_stylesheet = 0
5
- components_with_javascript = 0
6
- components_with_test = 0
7
- components_with_javascript_test = 0
8
- components_with_helper = 0
9
-
10
- components.each do |component|
11
- components_with_stylesheet += 1 if component[:stylesheet]
12
- components_with_print_stylesheet += 1 if component[:print_stylesheet]
13
- components_with_javascript += 1 if component[:javascript]
14
- components_with_test += 1 if component[:tests]
15
- components_with_javascript_test += 1 if component[:js_tests]
16
- components_with_helper += 1 if component[:helper]
17
- end
18
- %>
19
1
  <table class="govuk-table">
20
2
  <thead class="govuk-table__head">
21
3
  <tr class="govuk-table__row">
22
- <th scope="col" class="govuk-table__header sticky-table-header">Component (<%= total_components %>)</th>
23
- <th scope="col" class="govuk-table__header sticky-table-header">CSS (<%= components_with_stylesheet %>)</th>
24
- <th scope="col" class="govuk-table__header sticky-table-header">Print CSS (<%= components_with_print_stylesheet %>)</th>
25
- <th scope="col" class="govuk-table__header sticky-table-header">JS (<%= components_with_javascript %>)</th>
26
- <th scope="col" class="govuk-table__header sticky-table-header">Test (<%= components_with_test %>)</th>
27
- <th scope="col" class="govuk-table__header sticky-table-header">JS test (<%= components_with_javascript_test %>)</th>
28
- <th scope="col" class="govuk-table__header sticky-table-header">Helper (<%= components_with_helper %>)</th>
4
+ <th scope="col" class="govuk-table__header sticky-table-header">Component</th>
5
+ <th scope="col" class="govuk-table__header sticky-table-header">Template (<%= @components[:component_numbers][:template] %>)</th>
6
+ <th scope="col" class="govuk-table__header sticky-table-header">CSS (<%= @components[:component_numbers][:stylesheet] %>)</th>
7
+ <th scope="col" class="govuk-table__header sticky-table-header">Print styles (<%= @components[:component_numbers][:print_stylesheet] %>)</th>
8
+ <th scope="col" class="govuk-table__header sticky-table-header">JS (<%= @components[:component_numbers][:javascript] %>)</th>
9
+ <th scope="col" class="govuk-table__header sticky-table-header">Test (<%= @components[:component_numbers][:test] %>)</th>
10
+ <th scope="col" class="govuk-table__header sticky-table-header">JS test (<%= @components[:component_numbers][:javascript_test] %>)</th>
11
+ <th scope="col" class="govuk-table__header sticky-table-header">Helper (<%= @components[:component_numbers][:helper] %>)</th>
29
12
  </tr>
30
13
  </thead>
31
14
  <tbody class="govuk-table__body">
32
- <% components.each do |component| %>
15
+ <% @components[:component_file_details].each do |component| %>
33
16
  <tr class="govuk-table__row">
34
17
  <th scope="row" class="govuk-table__header">
35
- <a href="<%= component[:link] %>" class="govuk-link"><%= component[:name] %></a>
18
+ <a href="<%= component[:link] %>" class="govuk-link">
19
+ <%= component[:name] %>
20
+ </a>
36
21
  </th>
37
22
  <td class="govuk-table__cell">
38
- <% if component[:stylesheet] %>
23
+ <% if component[:template_exists] %>
39
24
  <strong class="govuk-tag govuk-tag--green">
40
- <a href="<%= component[:stylesheet] %>" class="govuk-link">Yes</a>
25
+ <a href="<%= component[:template_link] %>" class="govuk-link">
26
+ <%= component[:template_lines] %>
27
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> template</span>
28
+ </a>
41
29
  </strong>
42
30
  <% end %>
43
31
  </td>
44
32
  <td class="govuk-table__cell">
45
- <% if component[:print_stylesheet] %>
33
+ <% if component[:stylesheet_exists] %>
46
34
  <strong class="govuk-tag govuk-tag--green">
47
- <a href="<%= component[:print_stylesheet] %>" class="govuk-link">Yes</a>
35
+ <a href="<%= component[:stylesheet_link] %>" class="govuk-link">
36
+ <%= component[:stylesheet_lines] %>
37
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> stylesheet</span>
38
+ </a>
48
39
  </strong>
49
40
  <% end %>
50
41
  </td>
51
42
  <td class="govuk-table__cell">
52
- <% if component[:javascript] %>
43
+ <% if component[:print_stylesheet_exists] %>
44
+ <strong class="govuk-tag govuk-tag--green">Yes</strong>
45
+ <% end %>
46
+ </td>
47
+ <td class="govuk-table__cell">
48
+ <% if component[:javascript_exists] %>
53
49
  <strong class="govuk-tag govuk-tag--green">
54
- <a href="<%= component[:javascript] %>" class="govuk-link">Yes</a>
50
+ <a href="<%= component[:javascript_link] %>" class="govuk-link">
51
+ <%= component[:javascript_lines] %>
52
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> javascript</span>
53
+ </a>
55
54
  </strong>
56
55
  <% end %>
57
56
  </td>
58
57
  <td class="govuk-table__cell">
59
- <% if component[:tests] %>
58
+ <% if component[:test_exists] %>
60
59
  <strong class="govuk-tag govuk-tag--green">
61
- <a href="<%= component[:tests] %>" class="govuk-link">Yes</a>
60
+ <a href="<%= component[:test_link] %>" class="govuk-link">
61
+ <%= component[:test_lines] %>
62
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> test</span>
63
+ </a>
62
64
  </strong>
63
65
  <% end %>
64
66
  </td>
65
67
  <td class="govuk-table__cell">
66
- <% if component[:js_tests] %>
68
+ <% if component[:javascript_test_exists] %>
67
69
  <strong class="govuk-tag govuk-tag--green">
68
- <a href="<%= component[:js_tests] %>" class="govuk-link">Yes</a>
70
+ <a href="<%= component[:javascript_test_link] %>" class="govuk-link">
71
+ <%= component[:javascript_test_lines] %>
72
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> javascript test</span>
73
+ </a>
69
74
  </strong>
70
75
  <% end %>
71
76
  </td>
72
77
  <td class="govuk-table__cell">
73
- <% if component[:helper] %>
78
+ <% if component[:helper_exists] %>
74
79
  <strong class="govuk-tag govuk-tag--green">
75
- <a href="<%= component[:helper] %>" class="govuk-link">Yes</a>
80
+ <a href="<%= component[:helper_link] %>" class="govuk-link">
81
+ <%= component[:helper_lines] %>
82
+ <span class="govuk-visually-hidden">lines of code in <%= component[:name] %> helper</span>
83
+ </a>
76
84
  </strong>
77
85
  <% end %>
78
86
  </td>
@@ -10,7 +10,7 @@
10
10
  <% component_items = [] %>
11
11
 
12
12
  <% component_files = capture do %>
13
- <%= render partial: "component_contents", locals: { components: @components[:component_listing] } %>
13
+ <%= render partial: "component_contents" %>
14
14
  <% end %>
15
15
 
16
16
  <%
@@ -29,8 +29,8 @@
29
29
  css_classes = %w(gem-c-cookie-banner govuk-clearfix)
30
30
  css_classes << "gem-c-cookie-banner--services" if services_cookies
31
31
  %>
32
- <div id="<%= id %>" class="<%= css_classes.join(' ') %>" data-module="cookie-banner" role="region" aria-label="cookie banner" data-nosnippet>
33
- <div class="govuk-cookie-banner js-banner-wrapper" role="region" aria-label="<%= title %>">
32
+ <div id="<%= id %>" class="<%= css_classes.join(' ') %>" data-module="cookie-banner" data-nosnippet role="region" aria-label="<%= title %>">
33
+ <div class="govuk-cookie-banner js-banner-wrapper">
34
34
  <div class="gem-c-cookie-banner__message govuk-cookie-banner__message govuk-width-container">
35
35
  <div class="govuk-grid-row">
36
36
  <div class="govuk-grid-column-two-thirds">
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "34.1.0".freeze
2
+ VERSION = "34.1.1".freeze
3
3
  end
@@ -78,6 +78,7 @@ declare namespace axe {
78
78
  }
79
79
  | {
80
80
  exclude: Selector | SelectorList;
81
+ include?: Selector | SelectorList;
81
82
  };
82
83
  type ElementContext = Selector | SelectorList | ContextObject;
83
84
 
@@ -1,4 +1,4 @@
1
- /*! axe v4.6.0
1
+ /*! axe v4.6.1
2
2
  * Copyright (c) 2022 Deque Systems, Inc.
3
3
  *
4
4
  * Your use of this Source Code Form is subject to the terms of the Mozilla Public
@@ -22,7 +22,7 @@
22
22
  }, _typeof(obj);
23
23
  }
24
24
  var axe = axe || {};
25
- axe.version = '4.6.0';
25
+ axe.version = '4.6.1';
26
26
  if (typeof define === 'function' && define.amd) {
27
27
  define('axe-core', [], function() {
28
28
  return axe;