govspeak 8.5.0 → 8.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23ac40c67eb46b8265549568542bc48bb0cb96fe47c8b217a1e6135789ab2134
4
- data.tar.gz: 26d7a270ab0163d056c0fefff53548727019128456deab21409ee3b3ae6e01eb
3
+ metadata.gz: bdccda451ed897f8e9dcdc5b845116287f98bb610694119b6726933b7ed333bc
4
+ data.tar.gz: '01086d9d20ea2b65b35a5f73f59eaf05c20a342709e0cb8e8a7fc3c405848f0b'
5
5
  SHA512:
6
- metadata.gz: e637261f8a573479a054e8cdcba539ed296c4c9a1d70c263ff4caea059faf80992806332922259da0d52983013a4c302a11bed5421b12534f6d1de6b105d9620
7
- data.tar.gz: fa04e11f539f372793d6420f9dcdc81964d244530f3d9e397f0587ca22fac9e66e41b85d79cd224c88f187946bddeb04f9afdfe223328240c353b060bb45fba2
6
+ metadata.gz: 2b34067b3f5b8959f3df01d930ab18d905b4adbeb054651d1f6b3a4b4e1f995963bc2f5b861c3f638b2f9b63664ea800f1e0f25126daaeefab8d5503baac6e74
7
+ data.tar.gz: c50604d92a25d02f0a05024d3e35e79fa4c9e7aacd996270d216dd0ccb3c3a284bffdbfae2334c583f410340ea3cf91b865e74a3dc6d79337f3caf74d863623a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 8.6.0
2
+
3
+ * Remove embed functionality ([#358](https://github.com/alphagov/govspeak/pull/358))
4
+
5
+ ### 8.5.1
6
+
7
+ * Rename embed-related code to `content block`
8
+ * Do not attempt to parse embed codes if `content_blocks` option is missing
9
+
1
10
  ### 8.5.0
2
11
 
3
12
  * Support embeds in Govspeak
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/embedded_content.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
- embeds: [
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)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "8.5.0".freeze
2
+ VERSION = "8.6.0".freeze
3
3
  end
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/embed_extractor"
18
- require "govspeak/embedded_content"
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/embed_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, :embeds
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
- @embeds = Array.wrap(options.delete(:embeds))
64
60
  @locale = options.fetch(:locale, "en")
65
61
  @options = { input: PARSER_CLASS_NAME,
66
62
  sanitize: true,
@@ -259,13 +255,6 @@ module Govspeak
259
255
  render_image(AttachmentImagePresenter.new(attachment))
260
256
  end
261
257
 
262
- extension("embeds", Govspeak::EmbeddedContent::EMBED_REGEX) do |_embed_code, _document_type, content_id|
263
- embed = embeds.detect { |e| e[:content_id] == content_id }
264
- next "" unless embed
265
-
266
- EmbedPresenter.new(embed).render
267
- end
268
-
269
258
  # As of version 1.12.0 of Kramdown the block elements (div & figcaption)
270
259
  # inside this html block will have it's < > converted into HTML Entities
271
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.5.0
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-21 00:00:00.000000000 Z
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/embed_extractor.rb
254
- - lib/govspeak/embedded_content.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/embed_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/embed_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_embeds_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/embed_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_embeds_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,17 +0,0 @@
1
- module Govspeak
2
- class EmbedExtractor
3
- def initialize(document)
4
- @document = document
5
- end
6
-
7
- def content_references
8
- @content_references ||= @document.scan(EmbeddedContent::EMBED_REGEX).map { |match|
9
- EmbeddedContent.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,15 +0,0 @@
1
- module Govspeak
2
- class EmbeddedContent
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,32 +0,0 @@
1
- require "action_view"
2
- require "htmlentities"
3
-
4
- module Govspeak
5
- class EmbedPresenter
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 EmbedExtractorTest < Minitest::Test
4
- extend Minitest::Spec::DSL
5
-
6
- describe "EmbedExtractor" do
7
- subject { Govspeak::EmbedExtractor.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,84 +0,0 @@
1
- require "test_helper"
2
-
3
- class GovspeakEmbedsTest < 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
- embed = {
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, embeds: [embed]).to_html
24
-
25
- expected = "<p><span class=\"embed embed-content_block_email_address\" id=\"embed_#{content_id}\">#{embed[: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
- embed = {
32
- content_id:,
33
- document_type: "contact",
34
- title: "foo",
35
- }
36
- govspeak = "{{embed:contact:#{content_id}}}"
37
-
38
- rendered = Govspeak::Document.new(govspeak, embeds: [embed]).to_html
39
-
40
- expected = "<p><span class=\"embed embed-contact\" id=\"embed_#{content_id}\">#{embed[:title]}</span></p>"
41
-
42
- assert_equal compress_html(expected), compress_html(rendered)
43
- end
44
-
45
- it "ignores missing embeds" do
46
- govspeak = "{{embed:contact:#{content_id}}}"
47
-
48
- rendered = Govspeak::Document.new(govspeak, embeds: []).to_html
49
-
50
- assert_equal compress_html(""), compress_html(rendered)
51
- end
52
-
53
- it "supports multiple embeds" do
54
- embeds = [
55
- {
56
- content_id: SecureRandom.uuid,
57
- document_type: "contact",
58
- title: "foo",
59
- },
60
- {
61
- content_id: SecureRandom.uuid,
62
- document_type: "content_block_email_address",
63
- title: "foo",
64
- details: {
65
- email_address: "foo@example.com",
66
- },
67
- },
68
- ]
69
-
70
- govspeak = %(Here is a contact: {{embed:contact:#{embeds[0][:content_id]}}}
71
-
72
- Here is an email address: {{embed:content_block_email_address:#{embeds[1][:content_id]}}}
73
- )
74
-
75
- rendered = Govspeak::Document.new(govspeak, embeds:).to_html
76
-
77
- expected = """
78
- <p>Here is a contact: <span class=\"embed embed-contact\" id=\"embed_#{embeds[0][:content_id]}\">#{embeds[0][:title]}</span></p>
79
- <p>Here is an email address: <span class=\"embed embed-content_block_email_address\" id=\"embed_#{embeds[1][:content_id]}\">#{embeds[1][:details][:email_address]}</span></p>
80
- """
81
-
82
- assert_equal compress_html(expected), compress_html(rendered)
83
- end
84
- end