govuk_publishing_components 29.15.2 → 29.15.3

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: dc8afcd723e5dd4096349ddfbce6a967b852d9525f46bb3a1b078c11ab0b5b41
4
- data.tar.gz: b2c550b431ad6892bdee23afa7f2e83315e52725007d16149f20ce9a0ef29e7a
3
+ metadata.gz: 1093c2ff6d40fae820a8b90e7a349d7e8dd78b10fca660453365343d7968749c
4
+ data.tar.gz: 3607d6e31004a9697a60a6c7075124b085b2c7a592c6f159e9540fa9ed7c0ad6
5
5
  SHA512:
6
- metadata.gz: 0bd443616d7ab532ec0f2fe36549782986c3cb5bdbab636bdeec40ff595b7873b006d432f75c16f33311dda1c78b7e4533a4376ad52f19a8d1bf07b882dc03cd
7
- data.tar.gz: 3f64655cddd38bf346a6ab3dd8c69917a70b3de614ad0d4f73b16b28f777b3c7901b466fe8479d0c7abc8205f0b123469f35c3f97f44ab3fdb6456cde97883f1
6
+ metadata.gz: 126afbff6dcbcab4a12c6551ab3546c2727841a9454df9a2eafae820bf8dcb483ad578b041e3250f085b3ba34534eabbb80727715f706391fdc2530d975da97a
7
+ data.tar.gz: ea8bdcc6c1f05fc3f469de5fe182ff304ea58e228ad9caf8c89ecf8f66cc8ad8c279a5ff4d5556f09fbed75f88cd5cbd5cc46c21afc2dd1249befcbe16af8dd6
@@ -10,7 +10,7 @@
10
10
  if (window.dataLayer) {
11
11
  var data = {
12
12
  event: 'page_view',
13
- page: {
13
+ page_view: {
14
14
  location: this.getLocation(),
15
15
  referrer: this.getReferrer(),
16
16
  title: this.getTitle(),
@@ -9,6 +9,7 @@ module GovukPublishingComponents
9
9
  @component_locations = {}
10
10
  @gem_style_references = []
11
11
  @jquery_references = []
12
+ @helper_references = {}
12
13
 
13
14
  if application_found
14
15
  templates = Dir["#{path}/app/views/**/*.erb"]
@@ -69,6 +70,7 @@ module GovukPublishingComponents
69
70
  gem_style_references: @gem_style_references.flatten.uniq.sort,
70
71
  jquery_references: @jquery_references.flatten.uniq.sort,
71
72
  component_locations: @component_locations,
73
+ helper_references: @helper_references,
72
74
  }
73
75
  end
74
76
 
@@ -95,6 +97,8 @@ module GovukPublishingComponents
95
97
  components_found << find_match(find, src, type)
96
98
  end
97
99
 
100
+ get_helper_references(file, src) if %w[ruby templates].include?(type)
101
+
98
102
  if type == "javascripts"
99
103
  jquery_references = find_code_references(file, src, /\$\(/)
100
104
  @jquery_references << jquery_references if jquery_references
@@ -109,6 +113,20 @@ module GovukPublishingComponents
109
113
  components_found.flatten.uniq.sort
110
114
  end
111
115
 
116
+ def get_helper_references(file, src)
117
+ helper_use = find_match(/GovukPublishingComponents::(?:AppHelpers|Presenters)::[a-zA-Z]+/, src, "helper")
118
+ if helper_use.any?
119
+ helper_use.each do |helper|
120
+ class_name = helper.gsub(/GovukPublishingComponents::(AppHelpers)?(Presenters)?::+/, "")
121
+ helper_sym = class_name.to_sym
122
+ @helper_references[helper_sym] = [] unless @helper_references[helper_sym]
123
+ @helper_references[helper_sym] << clean_file_path(file)
124
+ @helper_references[helper_sym].uniq!
125
+ @helper_references[helper_sym].sort!
126
+ end
127
+ end
128
+ end
129
+
112
130
  # looks for components in the given src of a file
113
131
  # returns an array of component names or an empty array
114
132
  def find_match(find, src, type)
@@ -22,6 +22,7 @@ module GovukPublishingComponents
22
22
  @gem_data = gem_data
23
23
  @applications_data = sort_results(results)
24
24
  @gem_data[:components_by_application] = get_components_by_application || []
25
+ @gem_data[:helpers_used_by_applications] = get_helpers_used_by_applications || []
25
26
  end
26
27
  end
27
28
 
@@ -107,6 +108,7 @@ module GovukPublishingComponents
107
108
  gem_style_references: result[:gem_style_references],
108
109
  jquery_references: result[:jquery_references],
109
110
  component_locations: result[:component_locations],
111
+ helper_references: result[:helper_references],
110
112
  }
111
113
  else
112
114
  data << {
@@ -269,7 +271,7 @@ module GovukPublishingComponents
269
271
  locations = locations.flatten
270
272
 
271
273
  results << {
272
- component: component_name,
274
+ name: component_name,
273
275
  count: locations.length,
274
276
  locations: locations,
275
277
  }
@@ -277,5 +279,35 @@ module GovukPublishingComponents
277
279
 
278
280
  results if found_something
279
281
  end
282
+
283
+ # returns data of components gem helpers used in applications
284
+ def get_helpers_used_by_applications
285
+ results = []
286
+
287
+ @applications_data.each do |application|
288
+ next unless application[:application_found] && !application[:helper_references].blank?
289
+
290
+ application[:helper_references].each do |key, value|
291
+ location = {
292
+ name: application[:name],
293
+ locations: value,
294
+ }
295
+
296
+ match = results.find { |x| x[:name] == key }
297
+ if match
298
+ match[:locations] << location
299
+ match[:count] = match[:count] + 1
300
+ else
301
+ results << {
302
+ name: key,
303
+ count: 1,
304
+ locations: [location],
305
+ }
306
+ end
307
+ end
308
+ end
309
+
310
+ results
311
+ end
280
312
  end
281
313
  end
@@ -56,56 +56,19 @@
56
56
  }
57
57
  %>
58
58
 
59
- <% if @other_applications %>
60
- <% components_by_application = capture do %>
61
- <% if @components[:components_by_application].any? %>
62
- <dl class="govuk-summary-list">
63
- <% @components[:components_by_application].each do |component| %>
64
- <div class="govuk-summary-list__row">
65
- <dt class="govuk-summary-list__key">
66
- <%= component[:component] %> (<%= pluralize(component[:count], 'use') %>)
67
- </dt>
68
- <dd class="govuk-summary-list__value">
69
- <% component[:locations].each do |application| %>
70
- <% github_link = 'https://github.com/alphagov/' + application[:name] + '/blob/main/' %>
71
- <details class="govuk-details govuk-!-margin-bottom-2" data-module="govuk-details">
72
- <summary class="govuk-details__summary">
73
- <span class="govuk-details__summary-text">
74
- <%= application[:name] %> (<%= application[:locations].length %>)
75
- </span>
76
- </summary>
77
- <div class="govuk-details__text">
78
- <ul class="govuk-list govuk-list--bullet">
79
- <% application[:locations].each do |location| %>
80
- <li>
81
- <a href="<%= github_link %><%= location %>" class="govuk-link"><%= location %></a>
82
- </li>
83
- <% end %>
84
- </ul>
85
- </div>
86
- </details>
87
- <% end %>
88
- </dd>
89
- </div>
90
- <% end %>
91
- </dl>
92
- <% end %>
93
- <% end %>
59
+ <%= render 'items_in_applications',
60
+ heading: 'Components by application',
61
+ summary: 'Shows which applications use each component',
62
+ content: @components[:components_by_application],
63
+ items: component_items
64
+ %>
94
65
 
95
- <%
96
- component_items << {
97
- heading: {
98
- text: "Components by application",
99
- },
100
- summary: {
101
- text: "Shows which applications use each component",
102
- },
103
- content: {
104
- html: components_by_application
105
- },
106
- }
107
- %>
108
- <% end %>
66
+ <%= render 'items_in_applications',
67
+ heading: 'Helpers by application',
68
+ summary: 'Shows any applications that use helper classes from the components gem',
69
+ content: @components[:helpers_used_by_applications],
70
+ items: component_items
71
+ %>
109
72
 
110
73
  <%= render "govuk_publishing_components/components/accordion", {
111
74
  items: component_items
@@ -0,0 +1,50 @@
1
+ <% if @other_applications %>
2
+ <% accordion_content = capture do %>
3
+ <% if content.any? %>
4
+ <dl class="govuk-summary-list">
5
+ <% content.each do |item| %>
6
+ <div class="govuk-summary-list__row">
7
+ <dt class="govuk-summary-list__key">
8
+ <%= item[:name] %> (<%= pluralize(item[:count], 'use') %>)
9
+ </dt>
10
+ <dd class="govuk-summary-list__value">
11
+ <% item[:locations].each do |application| %>
12
+ <% github_link = 'https://github.com/alphagov/' + application[:name] + '/blob/main/' %>
13
+ <details class="govuk-details govuk-!-margin-bottom-2" data-module="govuk-details">
14
+ <summary class="govuk-details__summary">
15
+ <span class="govuk-details__summary-text">
16
+ <%= application[:name] %> (<%= application[:locations].length %>)
17
+ </span>
18
+ </summary>
19
+ <div class="govuk-details__text">
20
+ <ul class="govuk-list govuk-list--bullet">
21
+ <% application[:locations].each do |location| %>
22
+ <li>
23
+ <a href="<%= github_link %><%= location %>" class="govuk-link"><%= location %></a>
24
+ </li>
25
+ <% end %>
26
+ </ul>
27
+ </div>
28
+ </details>
29
+ <% end %>
30
+ </dd>
31
+ </div>
32
+ <% end %>
33
+ </dl>
34
+ <% end %>
35
+ <% end %>
36
+
37
+ <%
38
+ items << {
39
+ heading: {
40
+ text: heading,
41
+ },
42
+ summary: {
43
+ text: summary,
44
+ },
45
+ content: {
46
+ html: accordion_content
47
+ },
48
+ }
49
+ %>
50
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "29.15.2".freeze
2
+ VERSION = "29.15.3".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: 29.15.2
4
+ version: 29.15.3
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: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -646,6 +646,7 @@ files:
646
646
  - app/views/govuk_publishing_components/audit/_applications.html.erb
647
647
  - app/views/govuk_publishing_components/audit/_component_contents.html.erb
648
648
  - app/views/govuk_publishing_components/audit/_components.html.erb
649
+ - app/views/govuk_publishing_components/audit/_items_in_applications.html.erb
649
650
  - app/views/govuk_publishing_components/audit/show.html.erb
650
651
  - app/views/govuk_publishing_components/component_guide/_application_stylesheet.html.erb
651
652
  - app/views/govuk_publishing_components/component_guide/component_doc/_call.html.erb