govspeak 8.5.0 → 8.5.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/govspeak/{embedded_content.rb → content_block.rb} +1 -1
- data/lib/govspeak/{embed_extractor.rb → content_block_extractor.rb} +3 -3
- data/lib/govspeak/presenters/{embed_presenter.rb → content_block_presenter.rb} +1 -1
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +10 -8
- data/test/{embed_extractor_test.rb → content_block_extractor_test.rb} +3 -3
- data/test/{govspeak_embeds_test.rb → govspeak_content_blocks_test.rb} +29 -15
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a417c917e3816a6dc8f1dd69adb0264a6b89d679fa0fe40342e853913140885
|
|
4
|
+
data.tar.gz: 666d01ec5fc952dea1a2445aca9a29662b4208b6baf68833610a33487030249a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b140b11ff35bc4698a2f0a485556c5992abde565fd9fc1bdea76d2cb9f8494956a2f5038cda47e29e14fa18dad85b0e190f403f4362c76b263c56e248f50bbdf
|
|
7
|
+
data.tar.gz: 9f4f534254cf22208c8c71016f8b35ca0dc4908a07026ff034857ec4c33b6a192389e4c110d55c0231f54f5aa3b4177e6384f4a9ae22e25d51de80afc8c57e45
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -610,7 +610,7 @@ will output
|
|
|
610
610
|
|
|
611
611
|
### Content blocks
|
|
612
612
|
|
|
613
|
-
Authors can embed different types of [supported content](https://github.com/alphagov/govspeak/blob/main/lib/govspeak/
|
|
613
|
+
Authors can embed different types of [supported content](https://github.com/alphagov/govspeak/blob/main/lib/govspeak/content_block.rb#L3) created by the Content Block Manager
|
|
614
614
|
|
|
615
615
|
```
|
|
616
616
|
{{embed:content_block_email_address:d308f561-e5ee-45b5-90b2-3ac36a23fad9}}
|
|
@@ -620,7 +620,7 @@ with options provided
|
|
|
620
620
|
|
|
621
621
|
```
|
|
622
622
|
{
|
|
623
|
-
|
|
623
|
+
content_blocks: [
|
|
624
624
|
{
|
|
625
625
|
content_id: "d308f561-e5ee-45b5-90b2-3ac36a23fad9",
|
|
626
626
|
title: "Government Digital Service",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Govspeak
|
|
2
|
-
class
|
|
2
|
+
class ContentBlock
|
|
3
3
|
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze
|
|
4
4
|
UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
|
|
5
5
|
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module Govspeak
|
|
2
|
-
class
|
|
2
|
+
class ContentBlockExtractor
|
|
3
3
|
def initialize(document)
|
|
4
4
|
@document = document
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def content_references
|
|
8
|
-
@content_references ||= @document.scan(
|
|
9
|
-
|
|
8
|
+
@content_references ||= @document.scan(ContentBlock::EMBED_REGEX).map { |match|
|
|
9
|
+
ContentBlock.new(document_type: match[1], content_id: match[2], embed_code: match[0])
|
|
10
10
|
}.uniq
|
|
11
11
|
end
|
|
12
12
|
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
|
@@ -14,14 +14,14 @@ require "govspeak/structured_header_extractor"
|
|
|
14
14
|
require "govspeak/html_validator"
|
|
15
15
|
require "govspeak/html_sanitizer"
|
|
16
16
|
require "govspeak/blockquote_extra_quote_remover"
|
|
17
|
-
require "govspeak/
|
|
18
|
-
require "govspeak/
|
|
17
|
+
require "govspeak/content_block_extractor"
|
|
18
|
+
require "govspeak/content_block"
|
|
19
19
|
require "govspeak/post_processor"
|
|
20
20
|
require "govspeak/link_extractor"
|
|
21
21
|
require "govspeak/template_renderer"
|
|
22
22
|
require "govspeak/presenters/attachment_presenter"
|
|
23
23
|
require "govspeak/presenters/contact_presenter"
|
|
24
|
-
require "govspeak/presenters/
|
|
24
|
+
require "govspeak/presenters/content_block_presenter"
|
|
25
25
|
require "govspeak/presenters/h_card_presenter"
|
|
26
26
|
require "govspeak/presenters/image_presenter"
|
|
27
27
|
require "govspeak/presenters/attachment_image_presenter"
|
|
@@ -40,7 +40,7 @@ module Govspeak
|
|
|
40
40
|
@extensions = []
|
|
41
41
|
|
|
42
42
|
attr_accessor :images
|
|
43
|
-
attr_reader :attachments, :contacts, :links, :locale, :
|
|
43
|
+
attr_reader :attachments, :contacts, :links, :locale, :content_blocks
|
|
44
44
|
|
|
45
45
|
def self.to_html(source, options = {})
|
|
46
46
|
new(source, options).to_html
|
|
@@ -60,7 +60,7 @@ module Govspeak
|
|
|
60
60
|
@attachments = Array.wrap(options.delete(:attachments))
|
|
61
61
|
@links = Array.wrap(options.delete(:links))
|
|
62
62
|
@contacts = Array.wrap(options.delete(:contacts))
|
|
63
|
-
@
|
|
63
|
+
@content_blocks = Array.wrap(options.delete(:content_blocks))
|
|
64
64
|
@locale = options.fetch(:locale, "en")
|
|
65
65
|
@options = { input: PARSER_CLASS_NAME,
|
|
66
66
|
sanitize: true,
|
|
@@ -259,11 +259,13 @@ module Govspeak
|
|
|
259
259
|
render_image(AttachmentImagePresenter.new(attachment))
|
|
260
260
|
end
|
|
261
261
|
|
|
262
|
-
extension("
|
|
263
|
-
|
|
262
|
+
extension("content blocks", Govspeak::ContentBlock::EMBED_REGEX) do |embed_code, _document_type, content_id|
|
|
263
|
+
next embed_code if content_blocks.empty?
|
|
264
|
+
|
|
265
|
+
embed = content_blocks.detect { |e| e[:content_id] == content_id }
|
|
264
266
|
next "" unless embed
|
|
265
267
|
|
|
266
|
-
|
|
268
|
+
ContentBlockPresenter.new(embed).render
|
|
267
269
|
end
|
|
268
270
|
|
|
269
271
|
# As of version 1.12.0 of Kramdown the block elements (div & figcaption)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class ContentBlockExtractorTest < Minitest::Test
|
|
4
4
|
extend Minitest::Spec::DSL
|
|
5
5
|
|
|
6
|
-
describe "
|
|
7
|
-
subject { Govspeak::
|
|
6
|
+
describe "ContentBlockExtractor" do
|
|
7
|
+
subject { Govspeak::ContentBlockExtractor.new(document) }
|
|
8
8
|
|
|
9
9
|
describe "when there is no embedded content" do
|
|
10
10
|
let(:document) { "foo" }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class GovspeakContentBlocksTest < Minitest::Test
|
|
4
4
|
extend Minitest::Spec::DSL
|
|
5
5
|
|
|
6
6
|
def compress_html(html)
|
|
@@ -10,7 +10,7 @@ class GovspeakEmbedsTest < Minitest::Test
|
|
|
10
10
|
let(:content_id) { SecureRandom.uuid }
|
|
11
11
|
|
|
12
12
|
it "renders an email address when present in options[:embeds]" do
|
|
13
|
-
|
|
13
|
+
content_block = {
|
|
14
14
|
content_id:,
|
|
15
15
|
document_type: "content_block_email_address",
|
|
16
16
|
title: "foo",
|
|
@@ -20,38 +20,52 @@ class GovspeakEmbedsTest < Minitest::Test
|
|
|
20
20
|
}
|
|
21
21
|
govspeak = "{{embed:content_block_email_address:#{content_id}}}"
|
|
22
22
|
|
|
23
|
-
rendered = Govspeak::Document.new(govspeak,
|
|
23
|
+
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
|
24
24
|
|
|
25
|
-
expected = "<p><span class=\"embed embed-content_block_email_address\" id=\"embed_#{content_id}\">#{
|
|
25
|
+
expected = "<p><span class=\"embed embed-content_block_email_address\" id=\"embed_#{content_id}\">#{content_block[:details][:email_address]}</span></p>"
|
|
26
26
|
|
|
27
27
|
assert_equal compress_html(expected), compress_html(rendered)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "renders the title when the document type is a contact" do
|
|
31
|
-
|
|
31
|
+
content_block = {
|
|
32
32
|
content_id:,
|
|
33
33
|
document_type: "contact",
|
|
34
34
|
title: "foo",
|
|
35
35
|
}
|
|
36
36
|
govspeak = "{{embed:contact:#{content_id}}}"
|
|
37
37
|
|
|
38
|
-
rendered = Govspeak::Document.new(govspeak,
|
|
38
|
+
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
|
39
39
|
|
|
40
|
-
expected = "<p><span class=\"embed embed-contact\" id=\"embed_#{content_id}\">#{
|
|
40
|
+
expected = "<p><span class=\"embed embed-contact\" id=\"embed_#{content_id}\">#{content_block[:title]}</span></p>"
|
|
41
41
|
|
|
42
42
|
assert_equal compress_html(expected), compress_html(rendered)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
it "
|
|
45
|
+
it "removes embed code if a content block cannot be found" do
|
|
46
|
+
content_block = {
|
|
47
|
+
content_id: SecureRandom.uuid,
|
|
48
|
+
document_type: "contact",
|
|
49
|
+
title: "foo",
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
govspeak = "{{embed:contact:#{content_id}}}"
|
|
47
53
|
|
|
48
|
-
rendered = Govspeak::Document.new(govspeak,
|
|
54
|
+
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
|
49
55
|
|
|
50
56
|
assert_equal compress_html(""), compress_html(rendered)
|
|
51
57
|
end
|
|
52
58
|
|
|
59
|
+
it "retains an embed code if content_blocks are not specified" do
|
|
60
|
+
govspeak = "{{embed:contact:#{content_id}}}"
|
|
61
|
+
|
|
62
|
+
rendered = Govspeak::Document.new(govspeak).to_html
|
|
63
|
+
|
|
64
|
+
assert_equal compress_html("<p>#{govspeak}</p>"), compress_html(rendered)
|
|
65
|
+
end
|
|
66
|
+
|
|
53
67
|
it "supports multiple embeds" do
|
|
54
|
-
|
|
68
|
+
content_blocks = [
|
|
55
69
|
{
|
|
56
70
|
content_id: SecureRandom.uuid,
|
|
57
71
|
document_type: "contact",
|
|
@@ -67,16 +81,16 @@ class GovspeakEmbedsTest < Minitest::Test
|
|
|
67
81
|
},
|
|
68
82
|
]
|
|
69
83
|
|
|
70
|
-
govspeak = %(Here is a contact: {{embed:contact:#{
|
|
84
|
+
govspeak = %(Here is a contact: {{embed:contact:#{content_blocks[0][:content_id]}}}
|
|
71
85
|
|
|
72
|
-
Here is an email address: {{embed:content_block_email_address:#{
|
|
86
|
+
Here is an email address: {{embed:content_block_email_address:#{content_blocks[1][:content_id]}}}
|
|
73
87
|
)
|
|
74
88
|
|
|
75
|
-
rendered = Govspeak::Document.new(govspeak,
|
|
89
|
+
rendered = Govspeak::Document.new(govspeak, content_blocks:).to_html
|
|
76
90
|
|
|
77
91
|
expected = """
|
|
78
|
-
<p>Here is a contact: <span class=\"embed embed-contact\" id=\"embed_#{
|
|
79
|
-
<p>Here is an email address: <span class=\"embed embed-content_block_email_address\" id=\"embed_#{
|
|
92
|
+
<p>Here is a contact: <span class=\"embed embed-contact\" id=\"embed_#{content_blocks[0][:content_id]}\">#{content_blocks[0][:title]}</span></p>
|
|
93
|
+
<p>Here is an email address: <span class=\"embed embed-content_block_email_address\" id=\"embed_#{content_blocks[1][:content_id]}\">#{content_blocks[1][:details][:email_address]}</span></p>
|
|
80
94
|
"""
|
|
81
95
|
|
|
82
96
|
assert_equal compress_html(expected), compress_html(rendered)
|
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.5.
|
|
4
|
+
version: 8.5.1
|
|
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-10-
|
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionview
|
|
@@ -250,8 +250,8 @@ files:
|
|
|
250
250
|
- config/address_formats.yml
|
|
251
251
|
- lib/govspeak.rb
|
|
252
252
|
- lib/govspeak/blockquote_extra_quote_remover.rb
|
|
253
|
-
- lib/govspeak/
|
|
254
|
-
- lib/govspeak/
|
|
253
|
+
- lib/govspeak/content_block.rb
|
|
254
|
+
- lib/govspeak/content_block_extractor.rb
|
|
255
255
|
- lib/govspeak/header_extractor.rb
|
|
256
256
|
- lib/govspeak/html_sanitizer.rb
|
|
257
257
|
- lib/govspeak/html_validator.rb
|
|
@@ -260,7 +260,7 @@ files:
|
|
|
260
260
|
- lib/govspeak/presenters/attachment_image_presenter.rb
|
|
261
261
|
- lib/govspeak/presenters/attachment_presenter.rb
|
|
262
262
|
- lib/govspeak/presenters/contact_presenter.rb
|
|
263
|
-
- lib/govspeak/presenters/
|
|
263
|
+
- lib/govspeak/presenters/content_block_presenter.rb
|
|
264
264
|
- lib/govspeak/presenters/h_card_presenter.rb
|
|
265
265
|
- lib/govspeak/presenters/image_presenter.rb
|
|
266
266
|
- lib/govspeak/structured_header_extractor.rb
|
|
@@ -309,14 +309,14 @@ files:
|
|
|
309
309
|
- locales/zh-tw.yml
|
|
310
310
|
- locales/zh.yml
|
|
311
311
|
- test/blockquote_extra_quote_remover_test.rb
|
|
312
|
-
- test/
|
|
312
|
+
- test/content_block_extractor_test.rb
|
|
313
313
|
- test/govspeak_attachment_link_test.rb
|
|
314
314
|
- test/govspeak_attachment_test.rb
|
|
315
315
|
- test/govspeak_attachments_image_test.rb
|
|
316
316
|
- test/govspeak_attachments_inline_test.rb
|
|
317
317
|
- test/govspeak_button_test.rb
|
|
318
318
|
- test/govspeak_contacts_test.rb
|
|
319
|
-
- test/
|
|
319
|
+
- test/govspeak_content_blocks_test.rb
|
|
320
320
|
- test/govspeak_extract_contact_content_ids_test.rb
|
|
321
321
|
- test/govspeak_footnote_test.rb
|
|
322
322
|
- test/govspeak_images_bang_test.rb
|
|
@@ -355,14 +355,14 @@ specification_version: 4
|
|
|
355
355
|
summary: Markup language for single domain
|
|
356
356
|
test_files:
|
|
357
357
|
- test/blockquote_extra_quote_remover_test.rb
|
|
358
|
-
- test/
|
|
358
|
+
- test/content_block_extractor_test.rb
|
|
359
359
|
- test/govspeak_attachment_link_test.rb
|
|
360
360
|
- test/govspeak_attachment_test.rb
|
|
361
361
|
- test/govspeak_attachments_image_test.rb
|
|
362
362
|
- test/govspeak_attachments_inline_test.rb
|
|
363
363
|
- test/govspeak_button_test.rb
|
|
364
364
|
- test/govspeak_contacts_test.rb
|
|
365
|
-
- test/
|
|
365
|
+
- test/govspeak_content_blocks_test.rb
|
|
366
366
|
- test/govspeak_extract_contact_content_ids_test.rb
|
|
367
367
|
- test/govspeak_footnote_test.rb
|
|
368
368
|
- test/govspeak_images_bang_test.rb
|