govspeak 8.3.4 → 8.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 474078f8179d567c75b47f781c5d567072a6889a79554fefb81172316828f5fc
4
- data.tar.gz: aa5a44c15285543a1749b3cf129c66eeea2cb6b58d0b98c9970bc5130320c8fb
3
+ metadata.gz: bcb8f916d4ecf2cd7dacead34261e62a22484ad59faf2abb95e7ab41bf41afd0
4
+ data.tar.gz: f581a4a55a699cfe3726ca166701bb5a368644e474d568984f9aa67bd42b4af7
5
5
  SHA512:
6
- metadata.gz: 210b4b75330ff66604483b61e0c2f5c78292ab7e3a957839af6f4fb7e5123b8649366945b01a4a03841f0924166475e28751e4e2531cfe10a125ba506b3f9ec6
7
- data.tar.gz: 5c164df64fa4ba9c0bdba31d55644550267543e2549e764cab614db0bf2a2e07cd602d571c51ecad4ec9f402e0d76be5052cb21195616be98aba8c99a843d3c7
6
+ metadata.gz: a16fda897761b036e9ab947e14edbe577c25411001f5819a2005b23cd85bc80876783c6afa6a62b96a607a89b7a8a0e0db92de4e17dc81f4af8a00b35ad23263
7
+ data.tar.gz: 601ce5bf4d18aa1553c36dba150e0c1b5a59ca3357550a8357f665d9e059e7f5ca742ede3b1d19491f93d6229d73bd0cb055d777b3fb51fba39ef99857986a83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 8.4.0
2
+
3
+ * Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
4
+ * Add support for Ruby 3.3.
5
+ * Allow acronyms within example blocks.
6
+ * Allow tables within example blocks.
7
+ * Allow acronyms within address blocks.
8
+
1
9
  ## 8.3.4
2
10
 
3
11
  * Fix tables within call to action component ([#306](https://github.com/alphagov/govspeak/pull/306))
data/README.md CHANGED
@@ -28,7 +28,7 @@ Once govspeak has been updated and version incremented then:
28
28
 
29
29
  Also, consider if:
30
30
  - [whitehall](https://github.com/alphagov/whitehall) needs updating (as custom govspeak changes are present)
31
- - [govpspeak-preview](https://github.com/alphagov/govspeak-preview) needs updating
31
+ - [govspeak-preview](https://github.com/alphagov/govspeak-preview) needs updating
32
32
 
33
33
  Any pages that use govspeak to generate Content will need to *republished* in order for the new changes to be reflected.
34
34
 
@@ -34,8 +34,8 @@ class Govspeak::HtmlSanitizer
34
34
  # currently does – i.e. to return Sanitize config without any transformers.
35
35
  # e.g. https://github.com/alphagov/hmrc-manuals-api/blob/4a83f78d0bb839520155623fd9b63b3b12a3b13a/app/validators/no_dangerous_html_in_text_fields_validator.rb#L44
36
36
  config_with_transformers = Sanitize::Config.merge(
37
- sanitize_config(allowed_elements: allowed_elements),
38
- transformers: transformers,
37
+ sanitize_config(allowed_elements:),
38
+ transformers:,
39
39
  )
40
40
 
41
41
  Sanitize.clean(@dirty_html, config_with_transformers)
@@ -48,7 +48,7 @@ class Govspeak::HtmlSanitizer
48
48
 
49
49
  Sanitize::Config.merge(
50
50
  Sanitize::Config::RELAXED,
51
- elements: elements,
51
+ elements:,
52
52
  attributes: {
53
53
  # We purposefully disable style attributes which Sanitize::Config::RELAXED allows
54
54
  :all => Sanitize::Config::RELAXED[:attributes][:all] + %w[role aria-label] - %w[style],
@@ -26,7 +26,7 @@ private
26
26
  def govspeak_to_html(sanitize:)
27
27
  Govspeak::Document.new(
28
28
  govspeak_string,
29
- sanitize: sanitize,
29
+ sanitize:,
30
30
  allowed_image_hosts: @allowed_image_hosts,
31
31
  ).to_html
32
32
  end
@@ -67,7 +67,7 @@ module Govspeak
67
67
 
68
68
  attachment_html = GovukPublishingComponents.render(
69
69
  "govuk_publishing_components/components/attachment",
70
- attachment: attachment,
70
+ attachment:,
71
71
  margin_bottom: 6,
72
72
  locale: govspeak_document.locale,
73
73
  )
@@ -86,7 +86,7 @@ module Govspeak
86
86
 
87
87
  attachment_html = GovukPublishingComponents.render(
88
88
  "govuk_publishing_components/components/attachment_link",
89
- attachment: attachment,
89
+ attachment:,
90
90
  locale: govspeak_document.locale,
91
91
  )
92
92
  el.swap(attachment_html)
@@ -51,7 +51,7 @@ module Govspeak
51
51
  MS_POWERPOINT_PRESENTATION_HUMANIZED_CONTENT_TYPE = "MS Powerpoint Presentation".freeze
52
52
 
53
53
  def file_abbr_tag(abbr, title)
54
- content_tag(:abbr, abbr, title: title)
54
+ content_tag(:abbr, abbr, title:)
55
55
  end
56
56
 
57
57
  def humanized_content_type(file_extension)
@@ -34,7 +34,7 @@ module Govspeak
34
34
  lines = []
35
35
  lines << "<figcaption>"
36
36
  lines << %(<p>#{caption}</p>) if caption.present?
37
- lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit: credit)}</p>) if credit.present?
37
+ lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit:)}</p>) if credit.present?
38
38
  lines << "</figcaption>"
39
39
  lines.join
40
40
  end
@@ -17,7 +17,7 @@ module Govspeak
17
17
  def t(*args)
18
18
  options = args.last.is_a?(Hash) ? args.last.dup : {}
19
19
  key = args.shift
20
- I18n.t!(key, **options.merge(locale: locale))
20
+ I18n.t!(key, **options.merge(locale:))
21
21
  end
22
22
 
23
23
  def format_with_html_line_breaks(string)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "8.3.4".freeze
2
+ VERSION = "8.4.0".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -98,7 +98,7 @@ module Govspeak
98
98
  end
99
99
 
100
100
  def extracted_links(website_root: nil)
101
- Govspeak::LinkExtractor.new(self, website_root: website_root).call
101
+ Govspeak::LinkExtractor.new(self, website_root:).call
102
102
  end
103
103
 
104
104
  def extract_contact_content_ids
@@ -292,10 +292,17 @@ module Govspeak
292
292
  wrap_with_div("place", "$P", Govspeak::Document)
293
293
  wrap_with_div("information", "$I", Govspeak::Document)
294
294
  wrap_with_div("additional-information", "$AI")
295
- wrap_with_div("example", "$E", Govspeak::Document)
295
+
296
+ extension("example", surrounded_by("$E")) do |body|
297
+ <<~BODY
298
+ <div class="example" markdown="1">
299
+ #{body.strip.gsub(/\A^\|/, "\n|").gsub(/\|$\Z/, "|\n")}
300
+ </div>
301
+ BODY
302
+ end
296
303
 
297
304
  extension("address", surrounded_by("$A")) do |body|
298
- %(\n<div class="address"><div class="adr org fn"><p>\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n)
305
+ %(\n<div class="address"><div class="adr org fn"><p markdown="1">\n#{body.sub("\n", '').gsub("\n", '<br />')}\n</p></div></div>\n)
299
306
  end
300
307
 
301
308
  extension("legislative list", /#{NEW_PARAGRAPH_LOOKBEHIND}\$LegislativeList\s*$(.*?)\$EndLegislativeList/m) do |body|
@@ -310,7 +317,7 @@ module Govspeak
310
317
 
311
318
  extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body|
312
319
  body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/) do
313
- "<li>#{Govspeak::Document.new(Regexp.last_match(2).strip, attachments: attachments).to_html}</li>\n"
320
+ "<li>#{Govspeak::Document.new(Regexp.last_match(2).strip, attachments:).to_html}</li>\n"
314
321
  end
315
322
  %(<ol class="steps">\n#{body}</ol>)
316
323
  end
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class GovspeakAttachmentLinkTest < Minitest::Test
4
4
  def render_govspeak(govspeak, attachments = [])
5
- Govspeak::Document.new(govspeak, attachments: attachments).to_html
5
+ Govspeak::Document.new(govspeak, attachments:).to_html
6
6
  end
7
7
 
8
8
  test "renders an empty string for attachment link that is not found" do
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class GovspeakAttachmentTest < Minitest::Test
4
4
  def render_govspeak(govspeak, attachments = [])
5
- Govspeak::Document.new(govspeak, attachments: attachments).to_html
5
+ Govspeak::Document.new(govspeak, attachments:).to_html
6
6
  end
7
7
 
8
8
  test "renders an empty string for attachment link that is not found" do
@@ -11,7 +11,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
11
11
  end
12
12
 
13
13
  def render_govspeak(govspeak, attachments = [])
14
- Govspeak::Document.new(govspeak, attachments: attachments).to_html
14
+ Govspeak::Document.new(govspeak, attachments:).to_html
15
15
  end
16
16
 
17
17
  def compress_html(html)
@@ -11,7 +11,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
11
11
  end
12
12
 
13
13
  def render_govspeak(govspeak, attachments = [])
14
- Govspeak::Document.new(govspeak, attachments: attachments).to_html
14
+ Govspeak::Document.new(govspeak, attachments:).to_html
15
15
  end
16
16
 
17
17
  test "renders an empty string for an inline attachment not found" do
@@ -118,7 +118,7 @@ class GovspeakTest < Minitest::Test
118
118
  " do
119
119
  assert_text_output "Start now JSA"
120
120
  assert_html_output %(
121
- <p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="govuk-button" draggable="false" href="https://www.apply-for-new-style-jsa.dwp.gov.uk/?lang=cy"><span> Start now <abbr title="Jobseeker's Allowance">JSA</abbr></span><svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" focusable="false" aria-hidden="true"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
121
+ <p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="govuk-button" data-ga4-attributes='{"event_name":"navigation","type":"start button"}' draggable="false" href="https://www.apply-for-new-style-jsa.dwp.gov.uk/?lang=cy"><span> Start now <abbr title="Jobseeker's Allowance">JSA</abbr></span><svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" focusable="false" aria-hidden="true"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
122
122
  )
123
123
  end
124
124
  end
@@ -393,6 +393,19 @@ Teston
393
393
  assert_text_output "street road"
394
394
  end
395
395
 
396
+ test_given_govspeak "
397
+ $A
398
+ street with ACRONYM
399
+ road
400
+ $A
401
+
402
+ *[ACRONYM]: This is the acronym explanation" do
403
+ assert_html_output %(
404
+ <div class="address"><div class="adr org fn"><p>
405
+ street with <abbr title="This is the acronym explanation">ACRONYM</abbr><br>road<br>
406
+ </p></div></div>)
407
+ end
408
+
396
409
  test_given_govspeak "
397
410
  $P
398
411
  $I
@@ -1247,6 +1260,47 @@ Teston
1247
1260
  )
1248
1261
  end
1249
1262
 
1263
+ test_given_govspeak "
1264
+ $E
1265
+ This is an ACRONYM.
1266
+ $E
1267
+
1268
+ *[ACRONYM]: This is the acronym explanation
1269
+ " do
1270
+ assert_html_output %(
1271
+ <div class="example">
1272
+ <p>This is an <abbr title="This is the acronym explanation">ACRONYM</abbr>.</p>
1273
+ </div>
1274
+ )
1275
+ end
1276
+
1277
+ test_given_govspeak "
1278
+ $E
1279
+ |Heading 1|Heading 2|
1280
+ |-|-|
1281
+ |information|more information|
1282
+ $E" do
1283
+ assert_html_output %(
1284
+ <div class="example">
1285
+
1286
+ <table>
1287
+ <thead>
1288
+ <tr>
1289
+ <th scope="col">Heading 1</th>
1290
+ <th scope="col">Heading 2</th>
1291
+ </tr>
1292
+ </thead>
1293
+ <tbody>
1294
+ <tr>
1295
+ <td>information</td>
1296
+ <td>more information</td>
1297
+ </tr>
1298
+ </tbody>
1299
+ </table>
1300
+
1301
+ </div>)
1302
+ end
1303
+
1250
1304
  test_given_govspeak "
1251
1305
  $LegislativeList
1252
1306
  * 1. Item 1[^1] with an ACRONYM
@@ -55,7 +55,7 @@ module GovspeakTestHelper
55
55
  lines = text.split "\n"
56
56
  digits = Math.log10(lines.size + 2).ceil
57
57
  lines.map
58
- .with_index { |line, i| sprintf("%<number>#{digits}d: %<line>s", number: i + 1, line: line) }
58
+ .with_index { |line, i| sprintf("%<number>#{digits}d: %<line>s", number: i + 1, line:) }
59
59
  .join("\n")
60
60
  end
61
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.4
4
+ version: 8.4.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: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 7.2.2
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '6'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 7.2.2
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: addressable
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +39,7 @@ dependencies:
33
39
  version: 2.3.8
34
40
  - - "<"
35
41
  - !ruby/object:Gem::Version
36
- version: '3'
42
+ version: 2.8.8
37
43
  type: :runtime
38
44
  prerelease: false
39
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +49,7 @@ dependencies:
43
49
  version: 2.3.8
44
50
  - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: '3'
52
+ version: 2.8.8
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: govuk_publishing_components
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +57,9 @@ dependencies:
51
57
  - - ">="
52
58
  - !ruby/object:Gem::Version
53
59
  version: '35.1'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: 43.5.1
54
63
  type: :runtime
55
64
  prerelease: false
56
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,6 +67,9 @@ dependencies:
58
67
  - - ">="
59
68
  - !ruby/object:Gem::Version
60
69
  version: '35.1'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: 43.5.1
61
73
  - !ruby/object:Gem::Dependency
62
74
  name: htmlentities
63
75
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +91,9 @@ dependencies:
79
91
  - - ">="
80
92
  - !ruby/object:Gem::Version
81
93
  version: '0.7'
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.14.7
82
97
  type: :runtime
83
98
  prerelease: false
84
99
  version_requirements: !ruby/object:Gem::Requirement
@@ -86,6 +101,9 @@ dependencies:
86
101
  - - ">="
87
102
  - !ruby/object:Gem::Version
88
103
  version: '0.7'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: 1.14.7
89
107
  - !ruby/object:Gem::Dependency
90
108
  name: kramdown
91
109
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +111,9 @@ dependencies:
93
111
  - - ">="
94
112
  - !ruby/object:Gem::Version
95
113
  version: 2.3.1
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: 2.4.1
96
117
  type: :runtime
97
118
  prerelease: false
98
119
  version_requirements: !ruby/object:Gem::Requirement
@@ -100,6 +121,9 @@ dependencies:
100
121
  - - ">="
101
122
  - !ruby/object:Gem::Version
102
123
  version: 2.3.1
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: 2.4.1
103
127
  - !ruby/object:Gem::Dependency
104
128
  name: nokogiri
105
129
  requirement: !ruby/object:Gem::Requirement
@@ -190,14 +214,14 @@ dependencies:
190
214
  requirements:
191
215
  - - '='
192
216
  - !ruby/object:Gem::Version
193
- version: 4.14.0
217
+ version: 5.0.2
194
218
  type: :development
195
219
  prerelease: false
196
220
  version_requirements: !ruby/object:Gem::Requirement
197
221
  requirements:
198
222
  - - '='
199
223
  - !ruby/object:Gem::Version
200
- version: 4.14.0
224
+ version: 5.0.2
201
225
  - !ruby/object:Gem::Dependency
202
226
  name: simplecov
203
227
  requirement: !ruby/object:Gem::Requirement
@@ -319,14 +343,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
319
343
  requirements:
320
344
  - - ">="
321
345
  - !ruby/object:Gem::Version
322
- version: '3.0'
346
+ version: 3.1.4
323
347
  required_rubygems_version: !ruby/object:Gem::Requirement
324
348
  requirements:
325
349
  - - ">="
326
350
  - !ruby/object:Gem::Version
327
351
  version: '0'
328
352
  requirements: []
329
- rubygems_version: 3.5.5
353
+ rubygems_version: 3.5.21
330
354
  signing_key:
331
355
  specification_version: 4
332
356
  summary: Markup language for single domain