govspeak 6.5.2 → 6.5.3

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: eaa4aea2a5ad557426d34d0d17ef75ae5d538862cc293ad6d6403a663797667f
4
- data.tar.gz: 3950f3fdd4bc77f5b00ceb5bede0ffca988f2c910739ee0906fa49431be95ae0
3
+ metadata.gz: 753ae3784f7f2ea1afcba0ab048130ea81a12d18e6b83297c0044a029b9a7f96
4
+ data.tar.gz: 66b4612a2f7f821e94b5e0b5bc1a2471e40cc171506337f4c76dd3c95c087921
5
5
  SHA512:
6
- metadata.gz: 90a7401f005a80646a8390723c04b4e2754d39b42559189d70aab1c1214223b62e805f6cb640b4c1acc3dd37401fe059849884af56f533295fa4b24af760f7f8
7
- data.tar.gz: 18f85c38c237de6fc51b62b15c69b7bf236e0957c218e8ee246ba7fd572102231b129f6728461b5b9e57f2884107a0c419327e8ce522e8c70fe38fd3c4b1f066
6
+ metadata.gz: 979a24087e5278d5c5c045f02bbd65bd2b9265ba255af4d00de3697d44af9024330973d477177aacf117ac3cfa5210c209bc545117d4a1731e9b0b2cdfd4fbb9
7
+ data.tar.gz: b6e1a3e1d72f7c83b747cdc204b32efc7824dbea550cd9bdc3d965cd685952ff1dee44066dd9d3215c04f050abe8647b30584a3fca7d43c181a3d2eed2ae4b9b
@@ -1,8 +1,13 @@
1
+ ## 6.5.3
2
+
3
+ * Use button component for buttons (PR#176)
4
+
1
5
  ## 6.5.2
2
6
 
3
7
  * Allow `data` attributes on `div` tags (PR#173)
4
8
 
5
9
  ## 6.5.1
10
+
6
11
  * Change unicode testing characters after external gem change
7
12
  * Move from govuk-lint to rubocop-govuk
8
13
  * Allow version 6 of actionview
data/README.md CHANGED
@@ -619,8 +619,7 @@ will output
619
619
 
620
620
  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)
621
621
 
622
- This button component is [extended from static](http://govuk-static.herokuapp.com/component-guide/button) for [use in govspeak](http://govuk-static.herokuapp.com/component-guide/govspeak/button)
623
- Note: Ideally we'd use the original component directly but this currently isnt possible
622
+ This button component uses the component from the [components gem](https://components.publishing.service.gov.uk/component-guide/button) for use in govspeak.
624
623
 
625
624
  You must use the [link](https://daringfireball.net/projects/markdown/syntax#link) syntax within the button tags.
626
625
 
@@ -635,7 +634,7 @@ To get the most basic button.
635
634
  which outputs
636
635
 
637
636
  ```html
638
- <a role="button" class="button" href="https://gov.uk/random">
637
+ <a role="button" class="gem-c-button govuk-button" href="https://gov.uk/random">
639
638
  Continue
640
639
  </a>
641
640
  ```
@@ -649,8 +648,9 @@ To turn a button into a ['Start now' button](https://www.gov.uk/service-manual/d
649
648
  which outputs
650
649
 
651
650
  ```html
652
- <a role="button" class="button button-start" href="https://gov.uk/random">
651
+ <a role="button" class="gem-c-button govuk-button govuk-button--start" href="https://gov.uk/random">
653
652
  Start Now
653
+ <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg>
654
654
  </a>
655
655
  ```
656
656
 
@@ -667,12 +667,13 @@ which outputs
667
667
  ```html
668
668
  <a
669
669
  role="button"
670
- class="button button-start"
670
+ class="gem-c-button govuk-button govuk-button--start"
671
671
  href="https://example.com/external-service/start-now"
672
672
  data-module="cross-domain-tracking"
673
673
  data-tracking-code="UA-XXXXXX-Y"
674
674
  data-tracking-name="govspeakButtonTracker"
675
675
  >
676
676
  Start Now
677
+ <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg>
677
678
  </a>
678
679
  ```
@@ -161,10 +161,10 @@ module Govspeak
161
161
  {\/button} # match ending bracket
162
162
  (?:\r|\n|$) # non-capturing match to make sure end of line and linebreak
163
163
  }x) { |attributes, text, href|
164
- button_classes = "button"
165
- button_classes << " button-start" if attributes =~ /start/
164
+ button_classes = "govuk-button"
166
165
  /cross-domain-tracking:(?<cross_domain_tracking>.[^\s*]+)/ =~ attributes
167
166
  data_attribute = ""
167
+ data_attribute << " data-start='true'" if attributes =~ /start/
168
168
  if cross_domain_tracking
169
169
  data_attribute << " data-module='cross-domain-tracking'"
170
170
  data_attribute << " data-tracking-code='#{cross_domain_tracking.strip}'"
@@ -51,10 +51,12 @@ class Govspeak::HtmlSanitizer
51
51
  def sanitize_config
52
52
  Sanitize::Config.merge(
53
53
  Sanitize::Config::RELAXED,
54
- elements: Sanitize::Config::RELAXED[:elements] + %w[govspeak-embed-attachment govspeak-embed-attachment-link],
54
+ elements: Sanitize::Config::RELAXED[:elements] + %w[govspeak-embed-attachment govspeak-embed-attachment-link svg path],
55
55
  attributes: {
56
56
  :all => Sanitize::Config::RELAXED[:attributes][:all] + %w[role aria-label],
57
57
  "a" => Sanitize::Config::RELAXED[:attributes]["a"] + [:data],
58
+ "svg" => Sanitize::Config::RELAXED[:attributes][:all] + %w[xmlns width height viewbox focusable],
59
+ "path" => Sanitize::Config::RELAXED[:attributes][:all] + %w[fill d],
58
60
  "div" => [:data],
59
61
  "th" => Sanitize::Config::RELAXED[:attributes]["th"] + %w[style],
60
62
  "td" => Sanitize::Config::RELAXED[:attributes]["td"] + %w[style],
@@ -100,6 +100,24 @@ module Govspeak
100
100
  end
101
101
  end
102
102
 
103
+ extension("use gem component for buttons") do |document|
104
+ document.css(".govuk-button").map do |el|
105
+ button_html = GovukPublishingComponents.render(
106
+ "govuk_publishing_components/components/button",
107
+ text: el.content,
108
+ href: el["href"],
109
+ start: el["data-start"],
110
+ data_attributes: {
111
+ module: el["data-module"],
112
+ "tracking-code": el["data-tracking-code"],
113
+ "tracking-name": el["data-tracking-name"],
114
+ },
115
+ ).squish.gsub("> <", "><").gsub!(/\s+/, " ")
116
+
117
+ el.swap(button_html)
118
+ end
119
+ end
120
+
103
121
  attr_reader :input, :govspeak_document
104
122
 
105
123
  def initialize(html, govspeak_document)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "6.5.2".freeze
2
+ VERSION = "6.5.3".freeze
3
3
  end
@@ -9,34 +9,34 @@ class GovspeakTest < Minitest::Test
9
9
  include GovspeakTestHelper
10
10
 
11
11
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
12
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
12
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
13
13
  assert_text_output "Start now"
14
14
  end
15
15
 
16
16
  # The same as above but with line breaks
17
17
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}\n\n\n[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start)\n\n\n{/button}" do
18
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
18
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
19
19
  assert_text_output "Start now"
20
20
  end
21
21
 
22
22
  test_given_govspeak "{button cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
23
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
23
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
24
24
  assert_text_output "Start now"
25
25
  end
26
26
 
27
27
  test_given_govspeak "{button start}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
28
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
28
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
29
29
  assert_text_output "Start now"
30
30
  end
31
31
 
32
32
  test_given_govspeak "{button}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
33
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
33
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
34
34
  assert_text_output "Start now"
35
35
  end
36
36
 
37
37
  # Test other text outputs
38
38
  test_given_govspeak "{button}[Something else](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
39
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Something else</a></p>'
39
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Something else</a></p>'
40
40
  assert_text_output "Something else"
41
41
  end
42
42
 
@@ -49,7 +49,7 @@ class GovspeakTest < Minitest::Test
49
49
  assert_html_output %{
50
50
  <p>Text before the button with line breaks</p>
51
51
 
52
- <p><a role="button" class="button" href="http://www.gov.uk">Start Now</a></p>
52
+ <p><a class="gem-c-button govuk-button" role="button" href="http://www.gov.uk">Start Now</a></p>
53
53
 
54
54
  <p>test after the button</p>
55
55
  }
@@ -58,17 +58,17 @@ class GovspeakTest < Minitest::Test
58
58
 
59
59
  # Test README examples
60
60
  test_given_govspeak "{button}[Continue](https://gov.uk/random){/button}" do
61
- assert_html_output '<p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>'
61
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>'
62
62
  assert_text_output "Continue"
63
63
  end
64
64
 
65
65
  test_given_govspeak "{button start}[Start Now](https://gov.uk/random){/button}" do
66
- assert_html_output '<p><a role="button" class="button button-start" href="https://gov.uk/random">Start Now</a></p>'
66
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://gov.uk/random"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
67
67
  assert_text_output "Start Now"
68
68
  end
69
69
 
70
70
  test_given_govspeak "{button start cross-domain-tracking:UA-XXXXXX-Y}[Start Now](https://example.com/external-service/start-now){/button}" do
71
- assert_html_output '<p><a role="button" class="button button-start" href="https://example.com/external-service/start-now" data-module="cross-domain-tracking" data-tracking-code="UA-XXXXXX-Y" data-tracking-name="govspeakButtonTracker">Start Now</a></p>'
71
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-XXXXXX-Y" data-tracking-name="govspeakButtonTracker" href="https://example.com/external-service/start-now"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
72
72
  assert_text_output "Start Now"
73
73
  end
74
74
 
@@ -83,21 +83,21 @@ class GovspeakTest < Minitest::Test
83
83
  # Make sure button renders when typical linebreaks are before it, seen in publishing applications
84
84
  test_given_govspeak "{button}[Line breaks](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}" do
85
85
  assert_html_output %{
86
- <p><a role="button" class="button" href="https://gov.uk/random">Line breaks</a></p>
86
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Line breaks</a></p>
87
87
 
88
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
88
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
89
89
 
90
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
90
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
91
91
  }
92
92
  end
93
93
 
94
94
  test_given_govspeak "{button}[More line breaks](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}" do
95
95
  assert_html_output %{
96
- <p><a role="button" class="button" href="https://gov.uk/random">More line breaks</a></p>
96
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">More line breaks</a></p>
97
97
 
98
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
98
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
99
99
 
100
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
100
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
101
101
  }
102
102
  end
103
103
 
@@ -122,7 +122,7 @@ class GovspeakTest < Minitest::Test
122
122
  <p>lorem lorem lorem
123
123
  lorem lorem lorem</p>
124
124
 
125
- <p><a role="button" class="button button-start" href="https://gov.uk/random">Start Now</a></p>
125
+ <p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://gov.uk/random"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
126
126
 
127
127
  <p>lorem lorem lorem
128
128
  lorem lorem lorem</p>
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: 6.5.2
4
+ version: 6.5.3
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: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -365,23 +365,23 @@ signing_key:
365
365
  specification_version: 4
366
366
  summary: Markup language for single domain
367
367
  test_files:
368
- - test/govspeak_link_extractor_test.rb
369
- - test/govspeak_structured_headers_test.rb
370
- - test/govspeak_images_bang_test.rb
371
- - test/govspeak_button_test.rb
372
- - test/govspeak_table_with_headers_test.rb
373
- - test/govspeak_extract_contact_content_ids_test.rb
374
368
  - test/blockquote_extra_quote_remover_test.rb
375
369
  - test/govspeak_test_helper.rb
376
- - test/govspeak_link_test.rb
377
- - test/govspeak_images_test.rb
370
+ - test/govspeak_structured_headers_test.rb
378
371
  - test/govspeak_attachment_link_test.rb
379
- - test/govspeak_contacts_test.rb
372
+ - test/govspeak_attachments_image_test.rb
380
373
  - test/test_helper.rb
381
- - test/html_validator_test.rb
382
- - test/html_sanitizer_test.rb
383
374
  - test/govspeak_attachments_inline_test.rb
384
- - test/govspeak_test.rb
375
+ - test/html_sanitizer_test.rb
376
+ - test/govspeak_button_test.rb
377
+ - test/govspeak_images_bang_test.rb
378
+ - test/govspeak_images_test.rb
379
+ - test/html_validator_test.rb
385
380
  - test/govspeak_attachment_test.rb
386
- - test/govspeak_attachments_image_test.rb
381
+ - test/govspeak_extract_contact_content_ids_test.rb
382
+ - test/govspeak_test.rb
383
+ - test/govspeak_link_extractor_test.rb
384
+ - test/govspeak_link_test.rb
385
+ - test/govspeak_contacts_test.rb
387
386
  - test/presenters/h_card_presenter_test.rb
387
+ - test/govspeak_table_with_headers_test.rb