govspeak 10.0.0 → 10.1.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: 4b920cf6948fc17a6bc0046c71bc4a92cde77dd1f1fab57b58be2d8a4d077ea9
4
- data.tar.gz: d60959650aae08193cfedc1ad48cf1a6e3eb65c584b825d60701c2bbdf0dae31
3
+ metadata.gz: d9ca524477e38e4b0b37849295da93aaf71e8701f6eaf280da50fcf89ccbde01
4
+ data.tar.gz: 637af4d5351f4cb1a18435b8ee5e615403cbc663981bd8d6e9d67cd4f5a86607
5
5
  SHA512:
6
- metadata.gz: bc7e37cc770324bad3ad12fadba04eeb24fcf894411b052312029753a5532e647006f417e77f3080ea88c8ff43b67ad7c1f9834a9bc14ffa9e983cc1e59f2360
7
- data.tar.gz: 9c93d9f23dfc2387b64f3280a431b28f110737b784811c31aa58a5045cb18797a0eac13fb18c3579393aa5c07054e6739ed9f9035e57b95353ee75d00acb16f8
6
+ metadata.gz: 1e69a7260c483ee4b9dff69a1be6dd733163f8bfc12777b55acbaea1e014b3ffd1c6ec0104ec4fc55141db551405b83f8980e57d912bb0f32cb6ab5ae64418a5
7
+ data.tar.gz: a71a0f62fe42ec52ea7123d1e1aad7f2d7fa54fcd45315250e74b42b4cf8fe322a34d1380a4402f5ed69cfab62474203bf5e220bbe41a7fffa65753bbd1828d8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.1.0
4
+
5
+ * Allow acronyms/abbreviations in steps ([#387](https://github.com/alphagov/govspeak/pull/387)).
6
+ * Add GA4 indexes to attachments that render a details component ([#385](https://github.com/alphagov/govspeak/pull/385))
7
+
8
+ ## 10.0.1
9
+
10
+ * Update dependencies
11
+
3
12
  ## 10.0.0
4
13
 
5
14
  * Drop support for Ruby <3.2
@@ -11,7 +20,7 @@
11
20
 
12
21
  ## 8.8.3
13
22
 
14
- * Update dependencies (actionview < 8.0.2, sanitize < 8, rubocop-govuk = 5.0.7)
23
+ * Update dependencies (actionview < 8.0.2, sanitize < 8, rubocop-govuk = 5.0.7)
15
24
 
16
25
  ## 8.8.2
17
26
 
@@ -57,6 +57,11 @@ module Govspeak
57
57
  end
58
58
 
59
59
  extension("embed attachment HTML") do |document|
60
+ # Attachments with details components need indexes set for GA4 tracking purposes
61
+ details_attachments = govspeak_document.attachments.select { |attachment| attachment[:alternative_format_contact_email] }
62
+ details_attachments_size = details_attachments.size
63
+ details_attachment_index = 0
64
+
60
65
  document.css("govspeak-embed-attachment").map do |el|
61
66
  attachment = govspeak_document.attachments.detect { |a| a[:id] == el["id"] }
62
67
 
@@ -65,11 +70,17 @@ module Govspeak
65
70
  next
66
71
  end
67
72
 
73
+ if attachment[:alternative_format_contact_email]
74
+ details_attachment_index += 1
75
+ details_ga4_attributes = { index_section: details_attachment_index, index_section_count: details_attachments_size }
76
+ end
77
+
68
78
  attachment_html = GovukPublishingComponents.render(
69
79
  "govuk_publishing_components/components/attachment",
70
80
  attachment:,
71
81
  margin_bottom: 6,
72
82
  locale: govspeak_document.locale,
83
+ details_ga4_attributes:,
73
84
  )
74
85
  el.swap(attachment_html)
75
86
  end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "10.0.0".freeze
2
+ VERSION = "10.1.0".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -317,10 +317,19 @@ module Govspeak
317
317
  end
318
318
 
319
319
  extension("numbered list", /^[ \t]*((s\d+\.\s.*(?:\n|$))+)/) do |body|
320
- body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/) do
321
- "<li>#{Govspeak::Document.new(Regexp.last_match(2).strip, attachments:).to_html}</li>\n"
320
+ li_elements = body.gsub!(/s(\d+)\.\s(.*)(?:\n|$)/).map do
321
+ element = <<~BODY
322
+ <li markdown="1">
323
+ #{Regexp.last_match(2).strip}
324
+ </li>
325
+ BODY
326
+ element.strip
322
327
  end
323
- %(<ol class="steps">\n#{body}</ol>)
328
+ <<~BODY
329
+ <ol class="steps">
330
+ #{li_elements.join("\n ")}
331
+ </ol>
332
+ BODY
324
333
  end
325
334
 
326
335
  def self.devolved_options
@@ -58,13 +58,13 @@ class GovspeakAttachmentLinkTest < Minitest::Test
58
58
 
59
59
  expected_output = <<~TEXT
60
60
  <ol class="steps">
61
- <li>
62
- <p>First item with <span class="gem-c-attachment-link">
61
+ <li>
62
+ <p>First item with <span class="gem-c-attachment-link">
63
63
  <a class="govuk-link" href="http://example.com/attachment.pdf">Attachment Title</a> </span></p>
64
- </li>
65
- <li>
66
- <p>Second item without attachment</p>
67
- </li>
64
+ </li>
65
+ <li>
66
+ <p>Second item without attachment</p>
67
+ </li>
68
68
  </ol>
69
69
  TEXT
70
70
 
@@ -52,4 +52,32 @@ class GovspeakAttachmentTest < Minitest::Test
52
52
  assert html_has_selector?(rendered, "section.gem-c-attachment")
53
53
  assert_match(/<p>some more text<\/p>/, rendered)
54
54
  end
55
+
56
+ test "renders attachments with details elements with the correct GA4 index" do
57
+ attachments = []
58
+
59
+ (1..3).each do |index|
60
+ attachments << {
61
+ id: "attachment#{index}.ods",
62
+ url: "http://example.com/attachment#{index}",
63
+ title: "Attachment Title #{index}",
64
+ alternative_format_contact_email: "example@gov.uk",
65
+ }
66
+ end
67
+
68
+ # Insert an attachment without a details element, to ensure our code to increment the index ignores these
69
+ attachments.insert(1, {
70
+ id: "attachment.pdf",
71
+ url: "http://example.com/attachment.pdf",
72
+ title: "Attachment Title",
73
+ })
74
+
75
+ rendered = render_govspeak("[Attachment:attachment1.ods]\n[Attachment:attachment.pdf]\n[Attachment:attachment2.ods]\n[Attachment:attachment3.ods]", attachments)
76
+ node = Nokogiri::HTML(rendered)
77
+ node.css(".gem-c-details").each_with_index.map do |details, index|
78
+ ga4_event = JSON.parse(details.attribute("data-ga4-event"))
79
+ assert_equal ga4_event["index_section"], index + 1
80
+ assert_equal ga4_event["index_section_count"], 3
81
+ end
82
+ end
55
83
  end
@@ -582,21 +582,38 @@ Teston
582
582
  <p>This is a test:</p>
583
583
 
584
584
  <ol class="steps">
585
+ <li>
586
+ <p>This is number 1.</p>
587
+ </li>
588
+ <li>
589
+ <p>This is number 2.</p>
590
+ </li>
591
+ <li>
592
+ <p>This is number 3.</p>
593
+ </li>
594
+ <li>
595
+ <p>This is number 4.</p>
596
+ </li>
597
+ </ol>
598
+ </div>
599
+ )
600
+ end
601
+
602
+ test_given_govspeak "
603
+ s1. This is number 1.
604
+ s2. This is number 2 with an ACRONYM.
605
+
606
+ *[ACRONYM]: This is the acronym explanation" do
607
+ assert_html_output <<~HTML
608
+ <ol class="steps">
585
609
  <li>
586
- <p>This is number 1.</p>
587
- </li>
588
- <li>
589
- <p>This is number 2.</p>
590
- </li>
591
- <li>
592
- <p>This is number 3.</p>
610
+ <p>This is number 1.</p>
593
611
  </li>
594
612
  <li>
595
- <p>This is number 4.</p>
613
+ <p>This is number 2 with an <abbr title="This is the acronym explanation">ACRONYM</abbr>.</p>
596
614
  </li>
597
- </ol>
598
- </div>
599
- )
615
+ </ol>
616
+ HTML
600
617
  end
601
618
 
602
619
  test_given_govspeak "
@@ -841,15 +858,15 @@ Teston
841
858
  " do
842
859
  assert_html_output %(
843
860
  <ol class="steps">
844
- <li>
845
- <p>zippy</p>
846
- </li>
847
- <li>
848
- <p>bungle</p>
849
- </li>
850
- <li>
851
- <p>george</p>
852
- </li>
861
+ <li>
862
+ <p>zippy</p>
863
+ </li>
864
+ <li>
865
+ <p>bungle</p>
866
+ </li>
867
+ <li>
868
+ <p>george</p>
869
+ </li>
853
870
  </ol>)
854
871
  assert_text_output "zippy bungle george"
855
872
  end
@@ -868,12 +885,12 @@ Teston
868
885
  </ul>
869
886
 
870
887
  <ol class="steps">
871
- <li>
872
- <p>step</p>
873
- </li>
874
- <li>
875
- <p>list</p>
876
- </li>
888
+ <li>
889
+ <p>step</p>
890
+ </li>
891
+ <li>
892
+ <p>list</p>
893
+ </li>
877
894
  </ol>)
878
895
  assert_text_output "unordered list step list"
879
896
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-27 00:00:00.000000000 Z
10
+ date: 2025-03-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: actionview
@@ -86,7 +86,7 @@ dependencies:
86
86
  version: '0.7'
87
87
  - - "<"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.14.7
89
+ version: 1.14.8
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: '0.7'
97
97
  - - "<"
98
98
  - !ruby/object:Gem::Version
99
- version: 1.14.7
99
+ version: 1.14.8
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: kramdown
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -213,14 +213,14 @@ dependencies:
213
213
  requirements:
214
214
  - - '='
215
215
  - !ruby/object:Gem::Version
216
- version: 5.0.7
216
+ version: 5.0.8
217
217
  type: :development
218
218
  prerelease: false
219
219
  version_requirements: !ruby/object:Gem::Requirement
220
220
  requirements:
221
221
  - - '='
222
222
  - !ruby/object:Gem::Version
223
- version: 5.0.7
223
+ version: 5.0.8
224
224
  - !ruby/object:Gem::Dependency
225
225
  name: simplecov
226
226
  requirement: !ruby/object:Gem::Requirement
@@ -349,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  - !ruby/object:Gem::Version
350
350
  version: '0'
351
351
  requirements: []
352
- rubygems_version: 3.6.3
352
+ rubygems_version: 3.6.5
353
353
  specification_version: 4
354
354
  summary: Markup language for single domain
355
355
  test_files: