govspeak 4.0.0 → 5.0.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 +8 -0
- data/README.md +12 -0
- data/bin/govspeak +8 -0
- data/lib/govspeak.rb +51 -23
- data/lib/govspeak/cli.rb +51 -0
- data/lib/govspeak/post_processor.rb +26 -0
- data/lib/govspeak/version.rb +1 -1
- data/lib/presenters/attachment_presenter.rb +102 -57
- data/lib/presenters/contact_presenter.rb +22 -0
- data/lib/{govspeak/extension → templates}/attachment.html.erb +7 -15
- data/lib/templates/contact.html.erb +2 -2
- data/lib/templates/inline_attachment.html.erb +6 -0
- data/test/govspeak_attachments_image_test.rb +108 -0
- data/test/govspeak_attachments_inline_test.rb +172 -0
- data/test/govspeak_attachments_test.rb +411 -0
- data/test/govspeak_contacts_test.rb +10 -6
- data/test/govspeak_link_test.rb +45 -0
- data/test/govspeak_test.rb +21 -90
- metadata +47 -7
- data/lib/govspeak/extension/inline_attachment.html.erb +0 -4
@@ -1,13 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
|
-
require 'ostruct'
|
5
4
|
|
6
5
|
class GovspeakContactsTest < Minitest::Test
|
7
6
|
|
8
7
|
def build_contact(attrs={})
|
9
|
-
|
10
|
-
has_postal_address?: attrs.fetch(:has_postal_address?, true),
|
8
|
+
{
|
11
9
|
id: attrs.fetch(:id, 123456),
|
12
10
|
content_id: attrs.fetch(:content_id, "4f3383e4-48a2-4461-a41d-f85ea8b89ba0"),
|
13
11
|
title: attrs.fetch(:title, "Government Digital Service"),
|
@@ -20,10 +18,10 @@ class GovspeakContactsTest < Minitest::Test
|
|
20
18
|
email: attrs.fetch(:email, "people@digital.cabinet-office.gov.uk"),
|
21
19
|
contact_form_url: attrs.fetch(:contact_form_url, ""),
|
22
20
|
contact_numbers: attrs.fetch(:contact_numbers,
|
23
|
-
[
|
21
|
+
[{ label: "helpdesk", number: "+4412345 67890" }]),
|
24
22
|
comments: attrs.fetch(:comments, ""),
|
25
23
|
worldwide_organisation_path: attrs.fetch(:worldwide_organisation_path, nil),
|
26
|
-
|
24
|
+
}
|
27
25
|
end
|
28
26
|
|
29
27
|
def compress_html(html)
|
@@ -77,7 +75,13 @@ class GovspeakContactsTest < Minitest::Test
|
|
77
75
|
end
|
78
76
|
|
79
77
|
test "contact with no postal address omits the address info" do
|
80
|
-
contact = build_contact(
|
78
|
+
contact = build_contact(
|
79
|
+
recipient: nil,
|
80
|
+
street_address: nil,
|
81
|
+
locality: nil,
|
82
|
+
region: nil,
|
83
|
+
postal_code: nil,
|
84
|
+
)
|
81
85
|
govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
|
82
86
|
rendered = Govspeak::Document.new(govspeak, { contacts: [contact] }).to_html
|
83
87
|
expected_html_output = %{
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GovspeakLinkTest < Minitest::Test
|
6
|
+
test "embedded link with link provided" do
|
7
|
+
link = {
|
8
|
+
content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
|
9
|
+
url: "https://www.example.com/",
|
10
|
+
title: "Example website"
|
11
|
+
}
|
12
|
+
govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
|
13
|
+
rendered = Govspeak::Document.new(govspeak, links: link).to_html
|
14
|
+
expected = %r{<a href="https://www.example.com/">Example website</a>}
|
15
|
+
assert_match(expected, rendered)
|
16
|
+
end
|
17
|
+
|
18
|
+
test "embedded link with markdown title" do
|
19
|
+
link = {
|
20
|
+
content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
|
21
|
+
url: "https://www.example.com/",
|
22
|
+
title: "**Example website**"
|
23
|
+
}
|
24
|
+
govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
|
25
|
+
rendered = Govspeak::Document.new(govspeak, links: link).to_html
|
26
|
+
expected = %r{<a href="https://www.example.com/"><strong>Example website</strong></a>}
|
27
|
+
assert_match(expected, rendered)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "embedded link with url not provided" do
|
31
|
+
link = {
|
32
|
+
content_id: "e510f1c1-4862-4333-889c-8d3acd443fbf",
|
33
|
+
title: "Example website",
|
34
|
+
}
|
35
|
+
govspeak = "[embed:link:e510f1c1-4862-4333-889c-8d3acd443fbf]"
|
36
|
+
rendered = Govspeak::Document.new(govspeak, links: link).to_html
|
37
|
+
assert_match("Example website", rendered)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "embedded link without link object" do
|
41
|
+
govspeak = "[embed:link:0726637c-8c66-47ad-834a-d815cbf51e0e]"
|
42
|
+
rendered = Govspeak::Document.new(govspeak).to_html
|
43
|
+
assert_match("", rendered)
|
44
|
+
end
|
45
|
+
end
|
data/test/govspeak_test.rb
CHANGED
@@ -634,22 +634,22 @@ $CTA
|
|
634
634
|
test "can reference attached images using !!n" do
|
635
635
|
images = [OpenStruct.new(alt_text: 'my alt', url: "http://example.com/image.jpg")]
|
636
636
|
given_govspeak "!!1", images do
|
637
|
-
assert_html_output
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
637
|
+
assert_html_output(
|
638
|
+
%{<figure class="image embedded">} +
|
639
|
+
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
|
640
|
+
%{</figure>}
|
641
|
+
)
|
642
642
|
end
|
643
643
|
end
|
644
644
|
|
645
645
|
test "alt text of referenced images is escaped" do
|
646
646
|
images = [OpenStruct.new(alt_text: %Q{my alt '&"<>}, url: "http://example.com/image.jpg")]
|
647
647
|
given_govspeak "!!1", images do
|
648
|
-
assert_html_output
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
648
|
+
assert_html_output(
|
649
|
+
%{<figure class="image embedded">} +
|
650
|
+
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt '&"<>"></div>} +
|
651
|
+
%{</figure>}
|
652
|
+
)
|
653
653
|
end
|
654
654
|
end
|
655
655
|
|
@@ -663,23 +663,23 @@ test "alt text of referenced images is escaped" do
|
|
663
663
|
test "adds image caption if given" do
|
664
664
|
images = [OpenStruct.new(alt_text: "my alt", url: "http://example.com/image.jpg", caption: 'My Caption & so on')]
|
665
665
|
given_govspeak "!!1", images do
|
666
|
-
assert_html_output
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
666
|
+
assert_html_output(
|
667
|
+
%{<figure class="image embedded">} +
|
668
|
+
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
|
669
|
+
%{<figcaption>My Caption & so on</figcaption>} +
|
670
|
+
%{</figure>}
|
671
|
+
)
|
672
672
|
end
|
673
673
|
end
|
674
674
|
|
675
675
|
test "ignores a blank caption" do
|
676
676
|
images = [OpenStruct.new(alt_text: "my alt", url: "http://example.com/image.jpg", caption: ' ')]
|
677
677
|
given_govspeak "!!1", images do
|
678
|
-
assert_html_output
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
678
|
+
assert_html_output(
|
679
|
+
%{<figure class="image embedded">} +
|
680
|
+
%{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
|
681
|
+
%{</figure>}
|
682
|
+
)
|
683
683
|
end
|
684
684
|
end
|
685
685
|
|
@@ -874,73 +874,4 @@ Or so we thought.}
|
|
874
874
|
|
|
875
875
|
end
|
876
876
|
end
|
877
|
-
|
878
|
-
test "inline attachment" do
|
879
|
-
attachment = OpenStruct.new(
|
880
|
-
content_id: "2b4d92f3-f8cd-4284-aaaa-25b3a640d26c",
|
881
|
-
id: 456,
|
882
|
-
)
|
883
|
-
govspeak = "[embed:attachments:inline:2b4d92f3-f8cd-4284-aaaa-25b3a640d26c]"
|
884
|
-
rendered = Govspeak::Document.new(govspeak, {attachments: attachment}).to_html
|
885
|
-
assert_match(/<span id=\"attachment_456\" class=\"attachment-inline\">/, rendered)
|
886
|
-
end
|
887
|
-
|
888
|
-
test "attachment" do
|
889
|
-
attachment = OpenStruct.new(
|
890
|
-
url: "www.test.com",
|
891
|
-
content_id: "2b4d92f3-f8cd-4284-aaaa-25b3a640d26c",
|
892
|
-
id: 123,
|
893
|
-
opendocument?: true,
|
894
|
-
order_url: "www.test.com",
|
895
|
-
price: 12.3,
|
896
|
-
csv?: true,
|
897
|
-
unnumbered_command_paper?: true,
|
898
|
-
isbn: 'isbn-123',
|
899
|
-
)
|
900
|
-
govspeak = "[embed:attachments:2b4d92f3-f8cd-4284-aaaa-25b3a640d26c]"
|
901
|
-
rendered = Govspeak::Document.new(govspeak, {attachments: attachment}).to_html
|
902
|
-
assert_match(/<section class=\"attachment embedded\">/, rendered)
|
903
|
-
assert_match(/<div class=\"attachment-thumb\">/, rendered)
|
904
|
-
assert_match(/attachment-123-accessibility-help/, rendered)
|
905
|
-
assert_match(/If you use assistive technology/, rendered)
|
906
|
-
assert_match(/<p class=\"opendocument-help\">/, rendered)
|
907
|
-
assert_match(/<span class=\"price\">£12.30/, rendered)
|
908
|
-
assert_match(/<span class=\"preview\">/, rendered)
|
909
|
-
assert_match(/<span class=\"unnumbered-paper\">/, rendered)
|
910
|
-
assert_match(/<span class=\"references\">/, rendered)
|
911
|
-
end
|
912
|
-
|
913
|
-
test "attachment that isn't provided" do
|
914
|
-
govspeak = "[embed:attachments:906ac8b7-850d-45c6-98e0-9525c680f891]"
|
915
|
-
rendered = Govspeak::Document.new(govspeak).to_html
|
916
|
-
assert_match("", rendered)
|
917
|
-
end
|
918
|
-
|
919
|
-
test "embedded link with link provided" do
|
920
|
-
link = OpenStruct.new(
|
921
|
-
content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
|
922
|
-
url: "https://www.example.com/",
|
923
|
-
title: "Example website"
|
924
|
-
)
|
925
|
-
govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
|
926
|
-
rendered = Govspeak::Document.new(govspeak, {links: link}).to_html
|
927
|
-
expected = %r{<a href="https://www.example.com/">Example website</a>}
|
928
|
-
assert_match(expected, rendered)
|
929
|
-
end
|
930
|
-
|
931
|
-
test "embedded link with link not provided" do
|
932
|
-
link = OpenStruct.new(
|
933
|
-
content_id: "e510f1c1-4862-4333-889c-8d3acd443fbf",
|
934
|
-
title: "Example website",
|
935
|
-
)
|
936
|
-
govspeak = "[embed:link:e510f1c1-4862-4333-889c-8d3acd443fbf]"
|
937
|
-
rendered = Govspeak::Document.new(govspeak, {links: link}).to_html
|
938
|
-
assert_match("Example website", rendered)
|
939
|
-
end
|
940
|
-
|
941
|
-
test "embedded link without link object" do
|
942
|
-
govspeak = "[embed:link:0726637c-8c66-47ad-834a-d815cbf51e0e]"
|
943
|
-
rendered = Govspeak::Document.new(govspeak).to_html
|
944
|
-
assert_match("", rendered)
|
945
|
-
end
|
946
877
|
end
|
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:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Griffiths
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-09-
|
12
|
+
date: 2016-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: kramdown
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.12.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.
|
27
|
+
version: 1.12.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: htmlentities
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +129,20 @@ dependencies:
|
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '6.7'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: commander
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.4'
|
139
|
+
type: :runtime
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.4'
|
132
146
|
- !ruby/object:Gem::Dependency
|
133
147
|
name: rake
|
134
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,13 +213,28 @@ dependencies:
|
|
199
213
|
- - ">="
|
200
214
|
- !ruby/object:Gem::Version
|
201
215
|
version: '0'
|
216
|
+
- !ruby/object:Gem::Dependency
|
217
|
+
name: pry-byebug
|
218
|
+
requirement: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
type: :development
|
224
|
+
prerelease: false
|
225
|
+
version_requirements: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
202
230
|
description: |-
|
203
231
|
A set of extensions to markdown layered on top of the kramdown
|
204
232
|
library for use in the UK Government Single Domain project
|
205
233
|
email:
|
206
234
|
- ben@alphagov.co.uk
|
207
235
|
- james.stewart@digital.cabinet-office.gov.uk
|
208
|
-
executables:
|
236
|
+
executables:
|
237
|
+
- govspeak
|
209
238
|
extensions: []
|
210
239
|
extra_rdoc_files: []
|
211
240
|
files:
|
@@ -213,10 +242,10 @@ files:
|
|
213
242
|
- Gemfile
|
214
243
|
- README.md
|
215
244
|
- Rakefile
|
245
|
+
- bin/govspeak
|
216
246
|
- lib/govspeak.rb
|
217
247
|
- lib/govspeak/blockquote_extra_quote_remover.rb
|
218
|
-
- lib/govspeak/
|
219
|
-
- lib/govspeak/extension/inline_attachment.html.erb
|
248
|
+
- lib/govspeak/cli.rb
|
220
249
|
- lib/govspeak/header_extractor.rb
|
221
250
|
- lib/govspeak/html_sanitizer.rb
|
222
251
|
- lib/govspeak/html_validator.rb
|
@@ -226,11 +255,18 @@ files:
|
|
226
255
|
- lib/govspeak/version.rb
|
227
256
|
- lib/kramdown/parser/kramdown_with_automatic_external_links.rb
|
228
257
|
- lib/presenters/attachment_presenter.rb
|
258
|
+
- lib/presenters/contact_presenter.rb
|
229
259
|
- lib/presenters/h_card_presenter.rb
|
260
|
+
- lib/templates/attachment.html.erb
|
230
261
|
- lib/templates/contact.html.erb
|
262
|
+
- lib/templates/inline_attachment.html.erb
|
231
263
|
- lib/with_deep_merge.rb
|
232
264
|
- test/blockquote_extra_quote_remover_test.rb
|
265
|
+
- test/govspeak_attachments_image_test.rb
|
266
|
+
- test/govspeak_attachments_inline_test.rb
|
267
|
+
- test/govspeak_attachments_test.rb
|
233
268
|
- test/govspeak_contacts_test.rb
|
269
|
+
- test/govspeak_link_test.rb
|
234
270
|
- test/govspeak_structured_headers_test.rb
|
235
271
|
- test/govspeak_test.rb
|
236
272
|
- test/govspeak_test_helper.rb
|
@@ -268,8 +304,12 @@ test_files:
|
|
268
304
|
- test/blockquote_extra_quote_remover_test.rb
|
269
305
|
- test/govspeak_test.rb
|
270
306
|
- test/test_helper.rb
|
307
|
+
- test/govspeak_attachments_test.rb
|
271
308
|
- test/presenters/h_card_presenter_test.rb
|
309
|
+
- test/govspeak_attachments_inline_test.rb
|
272
310
|
- test/with_deep_merge_test.rb
|
311
|
+
- test/govspeak_attachments_image_test.rb
|
273
312
|
- test/html_sanitizer_test.rb
|
274
313
|
- test/html_validator_test.rb
|
275
314
|
- test/govspeak_structured_headers_test.rb
|
315
|
+
- test/govspeak_link_test.rb
|