govspeak 10.2.5 → 10.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/govspeak/post_processor.rb +4 -2
- data/lib/govspeak/presenters/image_presenter.rb +4 -3
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +12 -14
- data/locales/cy.yml +13 -0
- data/locales/en.yml +10 -0
- data/test/govspeak_contacts_test.rb +18 -0
- data/test/govspeak_devolved_content_test.rb +21 -0
- data/test/govspeak_footnote_test.rb +20 -0
- data/test/govspeak_images_test.rb +8 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b86000c8998edfcccee37082c8779bc99ccbbfdbc9bf28a624a64444e45aa8
|
4
|
+
data.tar.gz: 965066276488ad504054c3251606ffee542e09c5958fe1dc94c2377a43d9beff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04aee10a7928ad945b7c269f24c87301966a467b2c1131b205a810f2e13a0211ea5b44ae68c515c626ff10d349562c35cdd2f3389a70cca50ee4d27b2d621ea0
|
7
|
+
data.tar.gz: 983127e90594c5937a4178ee735d0f700e0f52025d6a1d2417fa0f5c0367ccb155e27a57fe6590627c6e23668d0942667931913d87afd74e4818f08a89b88a97
|
data/CHANGELOG.md
CHANGED
@@ -150,11 +150,13 @@ module Govspeak
|
|
150
150
|
extension("use custom footnotes") do |document|
|
151
151
|
document.css("a.footnote").map do |el|
|
152
152
|
footnote_number = el[:href].gsub(/\D/, "")
|
153
|
-
|
153
|
+
label = I18n.t("govspeak.footnote.label", locale: govspeak_document.locale)
|
154
|
+
el.inner_html = "[#{label} #{footnote_number}]"
|
154
155
|
end
|
155
156
|
document.css("[role='doc-backlink']").map do |el|
|
156
157
|
backlink_number = " #{el.css('sup')[0].content}" if el.css("sup")[0].present?
|
157
|
-
|
158
|
+
aria_label = I18n.t("govspeak.footnote.backlink_aria_label", locale: govspeak_document.locale)
|
159
|
+
el["aria-label"] = "#{aria_label}#{backlink_number}"
|
158
160
|
end
|
159
161
|
end
|
160
162
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Govspeak
|
2
2
|
class ImagePresenter
|
3
|
-
attr_reader :image
|
3
|
+
attr_reader :image, :locale
|
4
4
|
|
5
|
-
def initialize(image)
|
5
|
+
def initialize(image, locale: "en")
|
6
6
|
@image = image
|
7
|
+
@locale = locale
|
7
8
|
end
|
8
9
|
|
9
10
|
def url
|
@@ -34,7 +35,7 @@ module Govspeak
|
|
34
35
|
lines = []
|
35
36
|
lines << "<figcaption>"
|
36
37
|
lines << %(<p>#{caption}</p>) if caption.present?
|
37
|
-
lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit:)}</p>) if credit.present?
|
38
|
+
lines << %(<p>#{I18n.t('govspeak.image.figure.credit', credit:, locale:)}</p>) if credit.present?
|
38
39
|
lines << "</figcaption>"
|
39
40
|
lines.join
|
40
41
|
end
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -225,7 +225,7 @@ module Govspeak
|
|
225
225
|
image = images[image_number.to_i - 1]
|
226
226
|
next "" unless image
|
227
227
|
|
228
|
-
render_image(ImagePresenter.new(image))
|
228
|
+
render_image(ImagePresenter.new(image, locale:))
|
229
229
|
end
|
230
230
|
|
231
231
|
# DEPRECATED: use 'AttachmentLink:attachment-id' instead
|
@@ -332,20 +332,18 @@ module Govspeak
|
|
332
332
|
BODY
|
333
333
|
end
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
335
|
+
%w[scotland
|
336
|
+
england
|
337
|
+
england-wales
|
338
|
+
northern-ireland
|
339
|
+
wales
|
340
|
+
london].each do |devolved_option|
|
341
|
+
extension("devolved-#{devolved_option}", /:#{devolved_option}:(.*?):#{devolved_option}:/m) do |body|
|
342
|
+
header_content = I18n.t("govspeak.devolved.#{devolved_option}", locale:)
|
343
343
|
|
344
|
-
devolved_options.each do |k, v|
|
345
|
-
extension("devolved-#{k}", /:#{k}:(.*?):#{k}:/m) do |body|
|
346
344
|
<<~HTML
|
347
|
-
<div class="devolved-content #{
|
348
|
-
<p class="devolved-header"
|
345
|
+
<div class="devolved-content #{devolved_option}">
|
346
|
+
<p class="devolved-header">#{header_content}</p>
|
349
347
|
<div class="devolved-body">#{Govspeak::Document.new(body.strip).to_html}</div>
|
350
348
|
</div>
|
351
349
|
HTML
|
@@ -375,7 +373,7 @@ module Govspeak
|
|
375
373
|
image = images.detect { |c| c.is_a?(Hash) && c[:id] == image_id }
|
376
374
|
next "" unless image
|
377
375
|
|
378
|
-
render_image(ImagePresenter.new(image))
|
376
|
+
render_image(ImagePresenter.new(image, locale:))
|
379
377
|
end
|
380
378
|
|
381
379
|
extension("Attachment", /^\[Attachment:\s*(.*?)\s*\]/) do |attachment_id|
|
data/locales/cy.yml
CHANGED
@@ -4,3 +4,16 @@ cy:
|
|
4
4
|
contact:
|
5
5
|
contact_form: Ffurflen cysylltu
|
6
6
|
email: E-bost
|
7
|
+
devolved:
|
8
|
+
scotland: Mae'r adran hon yn berthnasol i'r Alban
|
9
|
+
england: Mae'r adran hon yn berthnasol i Loegr
|
10
|
+
england-wales: Mae'r adran hon yn berthnasol i Gymru a Lloegr
|
11
|
+
northern-ireland: Mae'r adran hon yn berthnasol i Ogledd Iwerddon
|
12
|
+
wales: Mae'r adran hon yn berthnasol i Gymru
|
13
|
+
london: Mae'r adran hon yn berthnasol i Lundain
|
14
|
+
footnote:
|
15
|
+
label: troednodyn
|
16
|
+
backlink_aria_label: ewch i ble mae hyn wedi'i gyfeirio
|
17
|
+
image:
|
18
|
+
figure:
|
19
|
+
credit: "Credyd delwedd: %{credit}"
|
data/locales/en.yml
CHANGED
@@ -4,6 +4,16 @@ en:
|
|
4
4
|
contact:
|
5
5
|
email: Email
|
6
6
|
contact_form: Contact form
|
7
|
+
devolved:
|
8
|
+
scotland: This section applies to Scotland
|
9
|
+
england: This section applies to England
|
10
|
+
england-wales: This section applies to England and Wales
|
11
|
+
northern-ireland: This section applies to Northern Ireland
|
12
|
+
wales: This section applies to Wales
|
13
|
+
london: This section applies to London
|
14
|
+
footnote:
|
15
|
+
label: footnote
|
16
|
+
backlink_aria_label: go to where this is referenced
|
7
17
|
image:
|
8
18
|
figure:
|
9
19
|
credit: "Image credit: %{credit}"
|
@@ -198,4 +198,22 @@ class GovspeakContactsTest < Minitest::Test
|
|
198
198
|
assert_match(%(<p class="comments">My description about <a href="https://www.gov.uk">https://www.gov.uk</a></p>),
|
199
199
|
compress_html(rendered))
|
200
200
|
end
|
201
|
+
|
202
|
+
test "uses localised email label when locale is not English" do
|
203
|
+
contact = build_contact
|
204
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
205
|
+
|
206
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact], locale: "cy").to_html
|
207
|
+
assert_match(%(<p class="email"><span class="type">E-bost</span>),
|
208
|
+
compress_html(rendered))
|
209
|
+
end
|
210
|
+
|
211
|
+
test "uses localised contact form label when locale is not English" do
|
212
|
+
contact = build_contact
|
213
|
+
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
214
|
+
|
215
|
+
rendered = Govspeak::Document.new(govspeak, contacts: [contact], locale: "cy").to_html
|
216
|
+
assert_match(%(<p class="contact_form_url"><span class="type">Ffurflen cysylltu</span>),
|
217
|
+
compress_html(rendered))
|
218
|
+
end
|
201
219
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "govspeak_test_helper"
|
3
|
+
|
4
|
+
class GovspeakDevolvedTest < Minitest::Test
|
5
|
+
include GovspeakTestHelper
|
6
|
+
|
7
|
+
test "uses localised heading when locale is not English" do
|
8
|
+
given_govspeak ":scotland: Rwy'n ddatganoledig iawn\n ac yn Albanaidd iawn \n:scotland:", locale: "cy" do
|
9
|
+
assert_html_output(
|
10
|
+
%(
|
11
|
+
<div class="devolved-content scotland">
|
12
|
+
<p class="devolved-header">Mae'r adran hon yn berthnasol i'r Alban</p>
|
13
|
+
<div class="devolved-body">
|
14
|
+
<p>Rwy’n ddatganoledig iawn
|
15
|
+
ac yn Albanaidd iawn</p>
|
16
|
+
</div>
|
17
|
+
</div>),
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -43,4 +43,24 @@ class GovspeakFootnoteTest < Minitest::Test
|
|
43
43
|
</div>),
|
44
44
|
)
|
45
45
|
end
|
46
|
+
|
47
|
+
test "uses localised labels when locale is not English" do
|
48
|
+
given_govspeak "
|
49
|
+
Gellir ychwanegu troednodiadau[^1].
|
50
|
+
|
51
|
+
[^1]: Ac yna wedi'i ddiffinio'n ddiweddarach.", locale: "cy" do
|
52
|
+
assert_html_output(
|
53
|
+
%(
|
54
|
+
<p>Gellir ychwanegu troednodiadau<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">[troednodyn 1]</a></sup>.</p>
|
55
|
+
|
56
|
+
<div class="footnotes" role="doc-endnotes">
|
57
|
+
<ol>
|
58
|
+
<li id="fn:1">
|
59
|
+
<p>Ac yna wedi’i ddiffinio’n ddiweddarach. <a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="ewch i ble mae hyn wedi'i gyfeirio">↩</a></p>
|
60
|
+
</li>
|
61
|
+
</ol>
|
62
|
+
</div>),
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
46
66
|
end
|
@@ -49,6 +49,14 @@ class GovspeakImagesTest < Minitest::Test
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
test "Image:image-id syntax adds image credit with localised label when locale is not English" do
|
53
|
+
given_govspeak "[Image:image-id]", { images: [build_image(credit: "Fy Nghredyd ac ati")], locale: "cy" } do
|
54
|
+
assert_html_output(
|
55
|
+
"<figure class=\"image embedded\"><div class=\"img\"><img src=\"http://example.com/image.jpg\" alt=\"my alt\"></div>\n<figcaption><p>Credyd delwedd: Fy Nghredyd ac ati</p></figcaption></figure>",
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
52
60
|
test "Image:image-id syntax ignores a blank credit" do
|
53
61
|
given_govspeak "[Image:image-id]", images: [build_image(credit: " ")] do
|
54
62
|
assert_html_output(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govspeak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -213,14 +213,14 @@ dependencies:
|
|
213
213
|
requirements:
|
214
214
|
- - '='
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
version: 5.1.
|
216
|
+
version: 5.1.14
|
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.1.
|
223
|
+
version: 5.1.14
|
224
224
|
- !ruby/object:Gem::Dependency
|
225
225
|
name: simplecov
|
226
226
|
requirement: !ruby/object:Gem::Requirement
|
@@ -317,6 +317,7 @@ files:
|
|
317
317
|
- test/govspeak_attachments_inline_test.rb
|
318
318
|
- test/govspeak_button_test.rb
|
319
319
|
- test/govspeak_contacts_test.rb
|
320
|
+
- test/govspeak_devolved_content_test.rb
|
320
321
|
- test/govspeak_extract_contact_content_ids_test.rb
|
321
322
|
- test/govspeak_footnote_test.rb
|
322
323
|
- test/govspeak_images_bang_test.rb
|
@@ -349,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
350
|
- !ruby/object:Gem::Version
|
350
351
|
version: '0'
|
351
352
|
requirements: []
|
352
|
-
rubygems_version: 3.6.
|
353
|
+
rubygems_version: 3.6.9
|
353
354
|
specification_version: 4
|
354
355
|
summary: Markup language for single domain
|
355
356
|
test_files:
|
@@ -360,6 +361,7 @@ test_files:
|
|
360
361
|
- test/govspeak_attachments_inline_test.rb
|
361
362
|
- test/govspeak_button_test.rb
|
362
363
|
- test/govspeak_contacts_test.rb
|
364
|
+
- test/govspeak_devolved_content_test.rb
|
363
365
|
- test/govspeak_extract_contact_content_ids_test.rb
|
364
366
|
- test/govspeak_footnote_test.rb
|
365
367
|
- test/govspeak_images_bang_test.rb
|