govspeak 10.9.1 → 10.10.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: f2c13b7f32254dc8d017f51863396dd427d933bbe1bf20710c333a07a55cdc85
4
- data.tar.gz: 79944b9d3bbab9cac674c67d21202818c187caae73e2e0a6a53f95d48f56c463
3
+ metadata.gz: 3d2fa22c7671ca33aa517fac4cb898eba4823aaa9175d4ec14afb4a74598967b
4
+ data.tar.gz: a5e301aef894df2901032f38d260f886b488c7c4064e9e006c29505c3b22cd85
5
5
  SHA512:
6
- metadata.gz: 31e666ce9b971df656924f020272517a54a76188c0391b65c63911755d74341704ba745c9bf775f8fa6d3627c63de877edf0f030c20d39a91badf4630506a1c0
7
- data.tar.gz: 6901ecdef2a0a1203d323f81ee9a4e59215af88645a1648117a1c982261b226acd9c80ddd3031c394023664596677c54747f6e7f1743056a41575a12bd59ba0b
6
+ metadata.gz: 957046ca3c77b2c58857148a8b48c6e380c2d81ef5563053a934970ff9f883fd002b4868187338cf2f8b9e28b7e4563c197dddcec1e7d87ab32045946152a514
7
+ data.tar.gz: 6e0dd1d24b5b3cfad0656f0ff649bf0656da5a83c14cdcce61a3c384d76f2c5f64c7c813e8d741fca4a4bb486928c067485b2b9284ea5687b6e7c8de0615f02e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.10.0
4
+
5
+ * feature: Add cards to govspeak [PR #489](https://github.com/alphagov/govspeak/pull/489)
6
+
3
7
  ## 10.9.1
4
8
 
5
9
  * Update dependencies
data/README.md CHANGED
@@ -697,6 +697,67 @@ which outputs
697
697
  </a>
698
698
  ```
699
699
 
700
+ ### Cards
701
+
702
+ Adds cards using the cards component from the components gem, using the [auto layout](https://components.publishing.service.gov.uk/component-guide/cards/auto_layout).
703
+
704
+ #### Examples
705
+
706
+ The most basic card.
707
+
708
+ ```
709
+ {cards}[Benefits](https://www.gov.uk/browse/benefits){/cards}
710
+ ```
711
+
712
+ which outputs
713
+
714
+ ```html
715
+ <div class="gem-c-cards gem-c-cards--auto-layout">
716
+ <ul class="gem-c-cards__list">
717
+ <li class="gem-c-cards__list-item">
718
+ <div class="gem-c-cards__list-item-wrapper">
719
+ <h3 class="gem-c-cards__sub-heading govuk-heading-s">
720
+ <a class="govuk-link gem-c-cards__link gem-print-force-link-styles" href="http://www.gov.uk/browse/benefits">Benefits</a>
721
+ </h3>
722
+ </div>
723
+ </li>
724
+ </ul>
725
+ </div>
726
+ ```
727
+
728
+ To include a description on the card, include after the link.
729
+
730
+ ```
731
+ {cards}[Benefits](https://www.gov.uk/browse/benefits) Includes eligibility, appeals, tax credits and Universal Credit{/cards}
732
+ ```
733
+
734
+ which outputs
735
+
736
+ ```html
737
+ <div class="gem-c-cards gem-c-cards--auto-layout">
738
+ <ul class="gem-c-cards__list">
739
+ <li class="gem-c-cards__list-item">
740
+ <div class="gem-c-cards__list-item-wrapper">
741
+ <h3 class="gem-c-cards__sub-heading govuk-heading-s">
742
+ <a class="govuk-link gem-c-cards__link gem-print-force-link-styles" href="http://www.gov.uk/browse/benefits">Benefits</a>
743
+ </h3>
744
+ <p class="govuk-body gem-c-cards__description">Includes eligibility, appeals, tax credits and Universal Credit</p>
745
+ </div>
746
+ </li>
747
+ </ul>
748
+ </div>
749
+ ```
750
+
751
+ To output more than one card, repeat the link pattern.
752
+
753
+ ```
754
+ {cards}
755
+ [Benefits](https://www.gov.uk/browse/benefits) Includes eligibility, appeals, tax credits and Universal Credit
756
+ [Births, deaths, marriages and care](https://www.gov.uk/browse/births-deaths-marriages) Parenting, civil partnerships, divorce and Lasting Power of Attorney
757
+ {/cards}
758
+ ```
759
+
760
+
700
761
  ## Licence
701
762
 
702
763
  [MIT License](LICENCE)
@@ -14,6 +14,7 @@ class Govspeak::HtmlValidator
14
14
  def valid?
15
15
  dirty_html = govspeak_to_html(sanitize: false)
16
16
  clean_html = govspeak_to_html(sanitize: true)
17
+
17
18
  normalise_html(dirty_html) == normalise_html(clean_html)
18
19
  end
19
20
 
@@ -147,6 +147,30 @@ module Govspeak
147
147
  end
148
148
  end
149
149
 
150
+ extension("use gem component for cards") do |document|
151
+ document.css(".cards").map do |cards|
152
+ links = cards.css(".card").map do |card|
153
+ {
154
+ link: {
155
+ path: card["href"],
156
+ text: card.css(".text").inner_html.html_safe,
157
+ },
158
+ description: card.css(".description").inner_html.html_safe,
159
+ }
160
+ end
161
+
162
+ cards_html = GovukPublishingComponents.render(
163
+ "govuk_publishing_components/components/cards", {
164
+ items: links,
165
+ columns: "auto",
166
+ margin_bottom: 6,
167
+ }
168
+ ).squish.gsub("> <", "><").gsub!(/\s+/, " ")
169
+
170
+ cards.swap(cards_html)
171
+ end
172
+ end
173
+
150
174
  extension("use custom footnotes") do |document|
151
175
  document.css("a.footnote").map do |el|
152
176
  footnote_number = el[:href].gsub(/\D/, "")
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "10.9.1".freeze
2
+ VERSION = "10.10.0".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -202,6 +202,22 @@ module Govspeak
202
202
  %(\n<a role="button" draggable="false" class="#{button_classes}" href="#{href}" #{data_attribute}>#{text}</a>\n)
203
203
  end
204
204
 
205
+ extension("cards", %r$^{cards}(.*?){/cards}$m) do |body|
206
+ links = body.scan(/\s*\[([^\]]+)\]\(([^)]+)\)([^{\[$*\#]*)\s*/)
207
+ cards = ""
208
+
209
+ links.each do |text, href, description|
210
+ cards << "
211
+ <a class='card' href='#{href.strip}'>
212
+ <span class='text'>#{text.strip}</span>
213
+ <span class='description'>#{description.strip}</span>
214
+ </a>
215
+ "
216
+ end
217
+
218
+ "<div class='cards'>#{cards}</div>"
219
+ end
220
+
205
221
  extension("highlight-answer") do |body|
206
222
  %(\n\n<div class="highlight-answer">
207
223
  #{Govspeak::Document.new(body.strip, locale: @locale).to_html}</div>\n)
@@ -0,0 +1,54 @@
1
+ require "test_helper"
2
+ require "govspeak_test_helper"
3
+
4
+ require "ostruct"
5
+
6
+ class GovspeakTest < Minitest::Test
7
+ include GovspeakTestHelper
8
+
9
+ test_given_govspeak "{cards}[Benefits](https://www.gov.uk/browse/benefits){/cards}" do
10
+ assert_html_selector ".gem-c-cards.gem-c-cards--auto-layout"
11
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
12
+ assert_text_output "Benefits"
13
+ end
14
+
15
+ # The same as above but with line breaks
16
+ test_given_govspeak "{cards}\n\n\n[Benefits](https://www.gov.uk/browse/benefits)\n\n\n{/cards}" do
17
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
18
+ assert_text_output "Benefits"
19
+ end
20
+
21
+ test_given_govspeak "{cards}\n[Benefits](https://www.gov.uk/browse/benefits)\n[Births, deaths, marriages and care](https://www.gov.uk/browse/births-deaths-marriages)\n{/cards}" do
22
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
23
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/births-deaths-marriages"]'
24
+ assert_text_output "Benefits Births, deaths, marriages and care"
25
+ end
26
+
27
+ test_given_govspeak "{cards}[Benefits](https://www.gov.uk/browse/benefits) This is a description{/cards}" do
28
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
29
+ assert_html_selector ".gem-c-cards__description"
30
+ assert_text_output "Benefits This is a description"
31
+ end
32
+
33
+ # The same as above but with line breaks
34
+ test_given_govspeak "{cards}\n\n[Benefits](https://www.gov.uk/browse/benefits)\n\nThis is a description\n\n{/cards}" do
35
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
36
+ assert_text_output "Benefits This is a description"
37
+ end
38
+
39
+ test_given_govspeak "{cards}\n\n[Benefits](https://www.gov.uk/browse/benefits)\n\nThis is a description? With punctuation! - of course, this isn't a real example, real ones wouldn't \"quote\" like this\n\n{/cards}" do
40
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
41
+ assert_text_output "Benefits This is a description? With punctuation! - of course, this isn't a real example, real ones wouldn't \"quote\" like this"
42
+ end
43
+
44
+ test_given_govspeak "{cards}\n
45
+ [Benefits](https://www.gov.uk/browse/benefits)\n
46
+ This is a description\n
47
+ containing line breaks\n
48
+ [Births, deaths, marriages and care](https://www.gov.uk/browse/births-deaths-marriages)\n
49
+ {/cards}" do
50
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/benefits"]'
51
+ assert_html_selector 'a.gem-c-cards__link[href="https://www.gov.uk/browse/births-deaths-marriages"]'
52
+ assert_text_output "Benefits This is a description containing line breaks Births, deaths, marriages and care"
53
+ end
54
+ 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: 10.9.1
4
+ version: 10.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -86,7 +86,7 @@ dependencies:
86
86
  version: '0.7'
87
87
  - - "<"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.14.9
89
+ version: 1.15.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: '0.7'
97
97
  - - "<"
98
98
  - !ruby/object:Gem::Version
99
- version: 1.14.9
99
+ version: 1.15.3
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: kramdown
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -227,14 +227,14 @@ dependencies:
227
227
  requirements:
228
228
  - - '='
229
229
  - !ruby/object:Gem::Version
230
- version: 5.2.0
230
+ version: 5.2.1
231
231
  type: :development
232
232
  prerelease: false
233
233
  version_requirements: !ruby/object:Gem::Requirement
234
234
  requirements:
235
235
  - - '='
236
236
  - !ruby/object:Gem::Version
237
- version: 5.2.0
237
+ version: 5.2.1
238
238
  - !ruby/object:Gem::Dependency
239
239
  name: simplecov
240
240
  requirement: !ruby/object:Gem::Requirement
@@ -333,6 +333,7 @@ files:
333
333
  - test/govspeak_attachments_image_test.rb
334
334
  - test/govspeak_attachments_inline_test.rb
335
335
  - test/govspeak_button_test.rb
336
+ - test/govspeak_cards_test.rb
336
337
  - test/govspeak_contacts_test.rb
337
338
  - test/govspeak_devolved_content_test.rb
338
339
  - test/govspeak_extract_contact_content_ids_test.rb
@@ -369,7 +370,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
369
370
  - !ruby/object:Gem::Version
370
371
  version: '0'
371
372
  requirements: []
372
- rubygems_version: 4.0.10
373
+ rubygems_version: 4.0.15
373
374
  specification_version: 4
374
375
  summary: Markup language for single domain
375
376
  test_files:
@@ -379,6 +380,7 @@ test_files:
379
380
  - test/govspeak_attachments_image_test.rb
380
381
  - test/govspeak_attachments_inline_test.rb
381
382
  - test/govspeak_button_test.rb
383
+ - test/govspeak_cards_test.rb
382
384
  - test/govspeak_contacts_test.rb
383
385
  - test/govspeak_devolved_content_test.rb
384
386
  - test/govspeak_extract_contact_content_ids_test.rb