govspeak 8.5.1 → 8.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +0 -28
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +1 -14
- metadata +2 -9
- data/lib/govspeak/content_block.rb +0 -15
- data/lib/govspeak/content_block_extractor.rb +0 -17
- data/lib/govspeak/presenters/content_block_presenter.rb +0 -32
- data/test/content_block_extractor_test.rb +0 -59
- data/test/govspeak_content_blocks_test.rb +0 -98
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdccda451ed897f8e9dcdc5b845116287f98bb610694119b6726933b7ed333bc
|
4
|
+
data.tar.gz: '01086d9d20ea2b65b35a5f73f59eaf05c20a342709e0cb8e8a7fc3c405848f0b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b34067b3f5b8959f3df01d930ab18d905b4adbeb054651d1f6b3a4b4e1f995963bc2f5b861c3f638b2f9b63664ea800f1e0f25126daaeefab8d5503baac6e74
|
7
|
+
data.tar.gz: c50604d92a25d02f0a05024d3e35e79fa4c9e7aacd996270d216dd0ccb3c3a284bffdbfae2334c583f410340ea3cf91b865e74a3dc6d79337f3caf74d863623a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -608,34 +608,6 @@ will output
|
|
608
608
|
</div>
|
609
609
|
```
|
610
610
|
|
611
|
-
### Content blocks
|
612
|
-
|
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
|
-
|
615
|
-
```
|
616
|
-
{{embed:content_block_email_address:d308f561-e5ee-45b5-90b2-3ac36a23fad9}}
|
617
|
-
```
|
618
|
-
|
619
|
-
with options provided
|
620
|
-
|
621
|
-
```
|
622
|
-
{
|
623
|
-
content_blocks: [
|
624
|
-
{
|
625
|
-
content_id: "d308f561-e5ee-45b5-90b2-3ac36a23fad9",
|
626
|
-
title: "Government Digital Service",
|
627
|
-
details: { email_address: "test@example.com" },
|
628
|
-
}
|
629
|
-
]
|
630
|
-
}
|
631
|
-
```
|
632
|
-
|
633
|
-
will output
|
634
|
-
|
635
|
-
```html
|
636
|
-
<span class="embed_content_block_email_address" id="embed_d308f561-e5ee-45b5-90b2-3ac36a23fad9">test@example.com</span>
|
637
|
-
```
|
638
|
-
|
639
611
|
### Button
|
640
612
|
|
641
613
|
An accessible way to add button links into content, that can also allow cross domain tracking with [Google Analytics](https://support.google.com/analytics/answer/7372977?hl=en)
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -14,14 +14,11 @@ 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/content_block_extractor"
|
18
|
-
require "govspeak/content_block"
|
19
17
|
require "govspeak/post_processor"
|
20
18
|
require "govspeak/link_extractor"
|
21
19
|
require "govspeak/template_renderer"
|
22
20
|
require "govspeak/presenters/attachment_presenter"
|
23
21
|
require "govspeak/presenters/contact_presenter"
|
24
|
-
require "govspeak/presenters/content_block_presenter"
|
25
22
|
require "govspeak/presenters/h_card_presenter"
|
26
23
|
require "govspeak/presenters/image_presenter"
|
27
24
|
require "govspeak/presenters/attachment_image_presenter"
|
@@ -40,7 +37,7 @@ module Govspeak
|
|
40
37
|
@extensions = []
|
41
38
|
|
42
39
|
attr_accessor :images
|
43
|
-
attr_reader :attachments, :contacts, :links, :locale
|
40
|
+
attr_reader :attachments, :contacts, :links, :locale
|
44
41
|
|
45
42
|
def self.to_html(source, options = {})
|
46
43
|
new(source, options).to_html
|
@@ -60,7 +57,6 @@ module Govspeak
|
|
60
57
|
@attachments = Array.wrap(options.delete(:attachments))
|
61
58
|
@links = Array.wrap(options.delete(:links))
|
62
59
|
@contacts = Array.wrap(options.delete(:contacts))
|
63
|
-
@content_blocks = Array.wrap(options.delete(:content_blocks))
|
64
60
|
@locale = options.fetch(:locale, "en")
|
65
61
|
@options = { input: PARSER_CLASS_NAME,
|
66
62
|
sanitize: true,
|
@@ -259,15 +255,6 @@ module Govspeak
|
|
259
255
|
render_image(AttachmentImagePresenter.new(attachment))
|
260
256
|
end
|
261
257
|
|
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 }
|
266
|
-
next "" unless embed
|
267
|
-
|
268
|
-
ContentBlockPresenter.new(embed).render
|
269
|
-
end
|
270
|
-
|
271
258
|
# As of version 1.12.0 of Kramdown the block elements (div & figcaption)
|
272
259
|
# inside this html block will have it's < > converted into HTML Entities
|
273
260
|
# when ever this code is used inside block level elements.
|
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.
|
4
|
+
version: 8.6.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-10-
|
11
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -250,8 +250,6 @@ files:
|
|
250
250
|
- config/address_formats.yml
|
251
251
|
- lib/govspeak.rb
|
252
252
|
- lib/govspeak/blockquote_extra_quote_remover.rb
|
253
|
-
- lib/govspeak/content_block.rb
|
254
|
-
- lib/govspeak/content_block_extractor.rb
|
255
253
|
- lib/govspeak/header_extractor.rb
|
256
254
|
- lib/govspeak/html_sanitizer.rb
|
257
255
|
- lib/govspeak/html_validator.rb
|
@@ -260,7 +258,6 @@ files:
|
|
260
258
|
- lib/govspeak/presenters/attachment_image_presenter.rb
|
261
259
|
- lib/govspeak/presenters/attachment_presenter.rb
|
262
260
|
- lib/govspeak/presenters/contact_presenter.rb
|
263
|
-
- lib/govspeak/presenters/content_block_presenter.rb
|
264
261
|
- lib/govspeak/presenters/h_card_presenter.rb
|
265
262
|
- lib/govspeak/presenters/image_presenter.rb
|
266
263
|
- lib/govspeak/structured_header_extractor.rb
|
@@ -309,14 +306,12 @@ files:
|
|
309
306
|
- locales/zh-tw.yml
|
310
307
|
- locales/zh.yml
|
311
308
|
- test/blockquote_extra_quote_remover_test.rb
|
312
|
-
- test/content_block_extractor_test.rb
|
313
309
|
- test/govspeak_attachment_link_test.rb
|
314
310
|
- test/govspeak_attachment_test.rb
|
315
311
|
- test/govspeak_attachments_image_test.rb
|
316
312
|
- test/govspeak_attachments_inline_test.rb
|
317
313
|
- test/govspeak_button_test.rb
|
318
314
|
- test/govspeak_contacts_test.rb
|
319
|
-
- test/govspeak_content_blocks_test.rb
|
320
315
|
- test/govspeak_extract_contact_content_ids_test.rb
|
321
316
|
- test/govspeak_footnote_test.rb
|
322
317
|
- test/govspeak_images_bang_test.rb
|
@@ -355,14 +350,12 @@ specification_version: 4
|
|
355
350
|
summary: Markup language for single domain
|
356
351
|
test_files:
|
357
352
|
- test/blockquote_extra_quote_remover_test.rb
|
358
|
-
- test/content_block_extractor_test.rb
|
359
353
|
- test/govspeak_attachment_link_test.rb
|
360
354
|
- test/govspeak_attachment_test.rb
|
361
355
|
- test/govspeak_attachments_image_test.rb
|
362
356
|
- test/govspeak_attachments_inline_test.rb
|
363
357
|
- test/govspeak_button_test.rb
|
364
358
|
- test/govspeak_contacts_test.rb
|
365
|
-
- test/govspeak_content_blocks_test.rb
|
366
359
|
- test/govspeak_extract_contact_content_ids_test.rb
|
367
360
|
- test/govspeak_footnote_test.rb
|
368
361
|
- test/govspeak_images_bang_test.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Govspeak
|
2
|
-
class ContentBlock
|
3
|
-
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze
|
4
|
-
UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
|
5
|
-
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/
|
6
|
-
|
7
|
-
attr_reader :document_type, :content_id, :embed_code
|
8
|
-
|
9
|
-
def initialize(document_type:, content_id:, embed_code:)
|
10
|
-
@document_type = document_type
|
11
|
-
@content_id = content_id
|
12
|
-
@embed_code = embed_code
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Govspeak
|
2
|
-
class ContentBlockExtractor
|
3
|
-
def initialize(document)
|
4
|
-
@document = document
|
5
|
-
end
|
6
|
-
|
7
|
-
def content_references
|
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
|
-
}.uniq
|
11
|
-
end
|
12
|
-
|
13
|
-
def content_ids
|
14
|
-
@content_ids ||= content_references.map(&:content_id)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "action_view"
|
2
|
-
require "htmlentities"
|
3
|
-
|
4
|
-
module Govspeak
|
5
|
-
class ContentBlockPresenter
|
6
|
-
include ActionView::Helpers::TagHelper
|
7
|
-
|
8
|
-
attr_reader :embed
|
9
|
-
|
10
|
-
def initialize(embed)
|
11
|
-
@embed = ActiveSupport::HashWithIndifferentAccess.new(embed)
|
12
|
-
end
|
13
|
-
|
14
|
-
def content_id
|
15
|
-
embed[:content_id]
|
16
|
-
end
|
17
|
-
|
18
|
-
def document_type
|
19
|
-
embed[:document_type]
|
20
|
-
end
|
21
|
-
|
22
|
-
def render
|
23
|
-
body = if document_type == "content_block_email_address"
|
24
|
-
embed.dig(:details, :email_address)
|
25
|
-
else
|
26
|
-
embed[:title]
|
27
|
-
end
|
28
|
-
|
29
|
-
content_tag(:span, body, class: "embed embed-#{document_type}", id: "embed_#{content_id}")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ContentBlockExtractorTest < Minitest::Test
|
4
|
-
extend Minitest::Spec::DSL
|
5
|
-
|
6
|
-
describe "ContentBlockExtractor" do
|
7
|
-
subject { Govspeak::ContentBlockExtractor.new(document) }
|
8
|
-
|
9
|
-
describe "when there is no embedded content" do
|
10
|
-
let(:document) { "foo" }
|
11
|
-
|
12
|
-
describe "#content_references" do
|
13
|
-
it "returns an empty array" do
|
14
|
-
assert_equal [], subject.content_references
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#content_ids" do
|
19
|
-
it "returns an empty array" do
|
20
|
-
assert_equal [], subject.content_ids
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "when there is embedded content" do
|
26
|
-
let(:contact_uuid) { SecureRandom.uuid }
|
27
|
-
let(:content_block_email_address_uuid) { SecureRandom.uuid }
|
28
|
-
|
29
|
-
let(:document) do
|
30
|
-
"""
|
31
|
-
{{embed:contact:#{contact_uuid}}}
|
32
|
-
{{embed:content_block_email_address:#{content_block_email_address_uuid}}}
|
33
|
-
"""
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#content_references" do
|
37
|
-
it "returns all references" do
|
38
|
-
result = subject.content_references
|
39
|
-
|
40
|
-
assert_equal 2, result.count
|
41
|
-
|
42
|
-
assert_equal "contact", result[0].document_type
|
43
|
-
assert_equal contact_uuid, result[0].content_id
|
44
|
-
assert_equal "{{embed:contact:#{contact_uuid}}}", result[0].embed_code
|
45
|
-
|
46
|
-
assert_equal "content_block_email_address", result[1].document_type
|
47
|
-
assert_equal content_block_email_address_uuid, result[1].content_id
|
48
|
-
assert_equal "{{embed:content_block_email_address:#{content_block_email_address_uuid}}}", result[1].embed_code
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#content_ids" do
|
53
|
-
it "returns all uuids as an array" do
|
54
|
-
assert_equal [contact_uuid, content_block_email_address_uuid], subject.content_ids
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class GovspeakContentBlocksTest < Minitest::Test
|
4
|
-
extend Minitest::Spec::DSL
|
5
|
-
|
6
|
-
def compress_html(html)
|
7
|
-
html.gsub(/[\n\r]+\s*/, "")
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:content_id) { SecureRandom.uuid }
|
11
|
-
|
12
|
-
it "renders an email address when present in options[:embeds]" do
|
13
|
-
content_block = {
|
14
|
-
content_id:,
|
15
|
-
document_type: "content_block_email_address",
|
16
|
-
title: "foo",
|
17
|
-
details: {
|
18
|
-
email_address: "foo@example.com",
|
19
|
-
},
|
20
|
-
}
|
21
|
-
govspeak = "{{embed:content_block_email_address:#{content_id}}}"
|
22
|
-
|
23
|
-
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
24
|
-
|
25
|
-
expected = "<p><span class=\"embed embed-content_block_email_address\" id=\"embed_#{content_id}\">#{content_block[:details][:email_address]}</span></p>"
|
26
|
-
|
27
|
-
assert_equal compress_html(expected), compress_html(rendered)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "renders the title when the document type is a contact" do
|
31
|
-
content_block = {
|
32
|
-
content_id:,
|
33
|
-
document_type: "contact",
|
34
|
-
title: "foo",
|
35
|
-
}
|
36
|
-
govspeak = "{{embed:contact:#{content_id}}}"
|
37
|
-
|
38
|
-
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
39
|
-
|
40
|
-
expected = "<p><span class=\"embed embed-contact\" id=\"embed_#{content_id}\">#{content_block[:title]}</span></p>"
|
41
|
-
|
42
|
-
assert_equal compress_html(expected), compress_html(rendered)
|
43
|
-
end
|
44
|
-
|
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
|
-
|
52
|
-
govspeak = "{{embed:contact:#{content_id}}}"
|
53
|
-
|
54
|
-
rendered = Govspeak::Document.new(govspeak, content_blocks: [content_block]).to_html
|
55
|
-
|
56
|
-
assert_equal compress_html(""), compress_html(rendered)
|
57
|
-
end
|
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
|
-
|
67
|
-
it "supports multiple embeds" do
|
68
|
-
content_blocks = [
|
69
|
-
{
|
70
|
-
content_id: SecureRandom.uuid,
|
71
|
-
document_type: "contact",
|
72
|
-
title: "foo",
|
73
|
-
},
|
74
|
-
{
|
75
|
-
content_id: SecureRandom.uuid,
|
76
|
-
document_type: "content_block_email_address",
|
77
|
-
title: "foo",
|
78
|
-
details: {
|
79
|
-
email_address: "foo@example.com",
|
80
|
-
},
|
81
|
-
},
|
82
|
-
]
|
83
|
-
|
84
|
-
govspeak = %(Here is a contact: {{embed:contact:#{content_blocks[0][:content_id]}}}
|
85
|
-
|
86
|
-
Here is an email address: {{embed:content_block_email_address:#{content_blocks[1][:content_id]}}}
|
87
|
-
)
|
88
|
-
|
89
|
-
rendered = Govspeak::Document.new(govspeak, content_blocks:).to_html
|
90
|
-
|
91
|
-
expected = """
|
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>
|
94
|
-
"""
|
95
|
-
|
96
|
-
assert_equal compress_html(expected), compress_html(rendered)
|
97
|
-
end
|
98
|
-
end
|