govspeak 5.8.0 → 5.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac38fd3a1d6da3054f961380d76d362ad637aab0dd9593667a7657777ff10339
4
- data.tar.gz: 6e8e0430a8a6ee72e67374b90e70a695ff8f1c710d10ce61849b5af10e9a4db9
3
+ metadata.gz: aefa5ca742f032b154510d7a90ca70e4cb26adb803811ed4aac9377d07ea21ff
4
+ data.tar.gz: 6fdb391bb18c3b90c07f5d52a75758edc82711848da11578aab725eae6b556d7
5
5
  SHA512:
6
- metadata.gz: b3727ecd02a709c0db38b5881de8cb34846d627fbae0c0543da05462b250dfd1fb21bd3f5b07351be73dcc5bd8e447e7215e9a3693c59bce001559a978e7d6b5
7
- data.tar.gz: 7a190b06732cb113838ddff93eec9c34e5c3785568f8025781b8d8da9d6100a9da6bef64a190669217867dc6a55ed143757316b7a9538434dca19abda4dfb55f
6
+ metadata.gz: 2af64448e8f05a2e7aff9da5f81e252ff4ad5d466b8c9e7eba24114f937993f99ba0e8e59b1481c6fb1dba6dd6b438ec28e5735380b3d4879355a8eba20d4809
7
+ data.tar.gz: f4a4dbb952b94c994c8697d52b8a905bf457a98883ef8d23a8f661528f719632f28acb0c1cbcc1e7a26195340dafce0e2e7bac950f8e89eb0e4f675fea7af291
@@ -1,3 +1,7 @@
1
+ ## 5.9.0
2
+
3
+ * Add image credits to embedded images
4
+
1
5
  ## 5.8.0
2
6
 
3
7
  * Add new `Image:image-id` extension and deprecate `embed:attachments:image:content-id`
data/README.md CHANGED
@@ -473,6 +473,7 @@ with options provided
473
473
  {
474
474
  alt_text: "Some alt text",
475
475
  caption: "An optional caption",
476
+ credit: "An optional credit",
476
477
  url: "http://example.com/lovely-landscape.jpg",
477
478
  id: "filename.png",
478
479
  }
@@ -485,7 +486,10 @@ will output a image section
485
486
  <figure class="image embedded">
486
487
  <div class="img">
487
488
  <img src="http://example.com/lovely-landscape.jpg" alt="Some alt text">
488
- <figcaption>An optional caption</figcaption>
489
+ <figcaption>
490
+ <p>An optional caption</p>
491
+ <p>Image credit: An optional credit</p>
492
+ </figcaption>
489
493
  </div>
490
494
  </figure>
491
495
  ```
@@ -269,7 +269,7 @@ module Govspeak
269
269
  lines = []
270
270
  lines << %{<figure#{id_attr} class="image embedded">}
271
271
  lines << %{<div class="img"><img src="#{encode(image.url)}" alt="#{encode(image.alt_text)}"></div>}
272
- lines << %{<figcaption>#{encode(image.caption)}</figcaption>} if image.caption
272
+ lines << image.figcaption_html if image.figcaption?
273
273
  lines << '</figure>'
274
274
  lines.join
275
275
  end
@@ -18,8 +18,20 @@ module Govspeak
18
18
  nil
19
19
  end
20
20
 
21
+ def credit
22
+ nil
23
+ end
24
+
21
25
  def id
22
26
  attachment.id
23
27
  end
28
+
29
+ def figcaption?
30
+ false
31
+ end
32
+
33
+ def figcaption_html
34
+ nil
35
+ end
24
36
  end
25
37
  end
@@ -18,8 +18,25 @@ module Govspeak
18
18
  (image.respond_to?(:caption) ? image.caption : image[:caption]).to_s.strip.presence
19
19
  end
20
20
 
21
+ def credit
22
+ (image.respond_to?(:credit) ? image.credit : image[:credit]).to_s.strip.presence
23
+ end
24
+
21
25
  def id
22
26
  nil
23
27
  end
28
+
29
+ def figcaption?
30
+ caption.present? || credit.present?
31
+ end
32
+
33
+ def figcaption_html
34
+ lines = []
35
+ lines << '<figcaption>'
36
+ lines << %{<p>#{caption}</p>} if caption.present?
37
+ lines << %{<p>#{I18n.t('govspeak.image.figure.credit', credit: credit)}</p>} if credit.present?
38
+ lines << '</figcaption>'
39
+ lines.join
40
+ end
24
41
  end
25
42
  end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "5.8.0".freeze
2
+ VERSION = "5.9.0".freeze
3
3
  end
@@ -24,3 +24,6 @@ en:
24
24
  contact:
25
25
  email: Email
26
26
  contact_form: Contact form
27
+ image:
28
+ figure:
29
+ credit: "Image credit: %{credit}"
@@ -7,12 +7,13 @@ class GovspeakImagesBangTest < Minitest::Test
7
7
  include GovspeakTestHelper
8
8
 
9
9
  class Image
10
- attr_reader :alt_text, :url, :caption
10
+ attr_reader :alt_text, :url, :caption, :credit
11
11
 
12
12
  def initialize(attrs = {})
13
13
  @alt_text = attrs[:alt_text] || "my alt"
14
14
  @url = attrs[:url] || "http://example.com/image.jpg"
15
15
  @caption = attrs[:caption]
16
+ @credit = attrs[:credit]
16
17
  end
17
18
  end
18
19
 
@@ -51,7 +52,7 @@ class GovspeakImagesBangTest < Minitest::Test
51
52
  assert_html_output(
52
53
  %{<figure class="image embedded">} +
53
54
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
54
- %{<figcaption>My Caption &amp; so on</figcaption>} +
55
+ %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
55
56
  %{</figure>}
56
57
  )
57
58
  end
@@ -66,4 +67,39 @@ class GovspeakImagesBangTest < Minitest::Test
66
67
  )
67
68
  end
68
69
  end
70
+
71
+ test "¡¡n syntax adds image credit if given" do
72
+ given_govspeak "!!1", images: [Image.new(credit: 'My Credit & so on')] do
73
+ assert_html_output(
74
+ %{<figure class="image embedded">} +
75
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
76
+ %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
77
+ %{</figure>}
78
+ )
79
+ end
80
+ end
81
+
82
+ test "!!n syntax ignores a blank credit" do
83
+ given_govspeak "!!1", images: [Image.new(credit: ' ')] do
84
+ assert_html_output(
85
+ %{<figure class="image embedded">} +
86
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
87
+ %{</figure>}
88
+ )
89
+ end
90
+ end
91
+
92
+ test "!!n syntax adds image caption and credit if given" do
93
+ given_govspeak "!!1", images: [Image.new(caption: 'My Caption & so on', credit: 'My Credit & so on')] do
94
+ assert_html_output(
95
+ %{<figure class="image embedded">} +
96
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
97
+ %{<figcaption>} +
98
+ %{<p>My Caption &amp; so on</p>\n} +
99
+ %{<p>Image credit: My Credit &amp; so on</p>} +
100
+ %{</figcaption>} +
101
+ %{</figure>}
102
+ )
103
+ end
104
+ end
69
105
  end
@@ -43,7 +43,7 @@ class GovspeakImagesTest < Minitest::Test
43
43
  assert_html_output(
44
44
  %{<figure class="image embedded">} +
45
45
  %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
46
- %{<figcaption>My Caption &amp; so on</figcaption>} +
46
+ %{<figcaption><p>My Caption &amp; so on</p></figcaption>} +
47
47
  %{</figure>}
48
48
  )
49
49
  end
@@ -58,4 +58,39 @@ class GovspeakImagesTest < Minitest::Test
58
58
  )
59
59
  end
60
60
  end
61
+
62
+ test "Image:image-id syntax adds image credit if given" do
63
+ given_govspeak "[Image:image-id]", images: [build_image(credit: 'My Credit & so on')] do
64
+ assert_html_output(
65
+ %{<figure class="image embedded">} +
66
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
67
+ %{<figcaption><p>Image credit: My Credit &amp; so on</p></figcaption>} +
68
+ %{</figure>}
69
+ )
70
+ end
71
+ end
72
+
73
+ test "Image:image-id syntax ignores a blank credit" do
74
+ given_govspeak "[Image:image-id]", images: [build_image(credit: ' ')] do
75
+ assert_html_output(
76
+ %{<figure class="image embedded">} +
77
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>} +
78
+ %{</figure>}
79
+ )
80
+ end
81
+ end
82
+
83
+ test "Image:image-id syntax adds image caption and credit if given" do
84
+ given_govspeak "[Image:image-id]", images: [build_image(caption: 'My Caption & so on', credit: 'My Credit & so on')] do
85
+ assert_html_output(
86
+ %{<figure class="image embedded">} +
87
+ %{<div class="img"><img src="http://example.com/image.jpg" alt="my alt"></div>\n} +
88
+ %{<figcaption>} +
89
+ %{<p>My Caption &amp; so on</p>\n} +
90
+ %{<p>Image credit: My Credit &amp; so on</p>} +
91
+ %{</figcaption>} +
92
+ %{</figure>}
93
+ )
94
+ end
95
+ end
61
96
  end
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: 5.8.0
4
+ version: 5.9.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: 2018-12-13 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -365,21 +365,21 @@ signing_key:
365
365
  specification_version: 4
366
366
  summary: Markup language for single domain
367
367
  test_files:
368
- - test/test_helper.rb
369
- - test/govspeak_button_test.rb
370
- - test/govspeak_test.rb
371
- - test/html_validator_test.rb
372
- - test/govspeak_contacts_test.rb
373
- - test/govspeak_test_helper.rb
374
368
  - test/blockquote_extra_quote_remover_test.rb
369
+ - test/govspeak_test_helper.rb
370
+ - test/govspeak_structured_headers_test.rb
375
371
  - test/govspeak_attachments_image_test.rb
372
+ - test/govspeak_attachments_test.rb
373
+ - test/test_helper.rb
374
+ - test/govspeak_attachments_inline_test.rb
376
375
  - test/html_sanitizer_test.rb
377
- - test/govspeak_link_test.rb
378
- - test/govspeak_extract_contact_content_ids_test.rb
379
- - test/govspeak_structured_headers_test.rb
380
- - test/govspeak_images_test.rb
381
- - test/presenters/h_card_presenter_test.rb
376
+ - test/govspeak_button_test.rb
382
377
  - test/govspeak_images_bang_test.rb
378
+ - test/govspeak_images_test.rb
379
+ - test/html_validator_test.rb
380
+ - test/govspeak_extract_contact_content_ids_test.rb
381
+ - test/govspeak_test.rb
383
382
  - test/govspeak_link_extractor_test.rb
384
- - test/govspeak_attachments_test.rb
385
- - test/govspeak_attachments_inline_test.rb
383
+ - test/govspeak_link_test.rb
384
+ - test/govspeak_contacts_test.rb
385
+ - test/presenters/h_card_presenter_test.rb