govuk_publishing_components 8.1.0 → 8.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/component_guide/application.scss +10 -0
  3. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +9 -5
  4. data/app/assets/stylesheets/govuk_publishing_components/_all_components_print.scss +3 -2
  5. data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +12 -0
  6. data/app/assets/stylesheets/govuk_publishing_components/components/_phase-banner.scss +7 -0
  7. data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +77 -0
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_title.scss +46 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss +2 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/print/_title.scss +7 -0
  11. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +9 -9
  12. data/app/models/govuk_publishing_components/component_doc.rb +32 -20
  13. data/app/models/govuk_publishing_components/{component_doc_resolver.rb → component_docs.rb} +2 -27
  14. data/app/models/govuk_publishing_components/component_example.rb +4 -4
  15. data/app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb +1 -8
  16. data/app/views/govuk_publishing_components/component_guide/component_doc/_component_output.html.erb +7 -0
  17. data/app/views/govuk_publishing_components/component_guide/component_doc/_preview.html.erb +7 -0
  18. data/app/views/govuk_publishing_components/component_guide/example.html.erb +1 -1
  19. data/app/views/govuk_publishing_components/component_guide/index.html.erb +1 -1
  20. data/app/views/govuk_publishing_components/component_guide/show.html.erb +2 -2
  21. data/app/views/govuk_publishing_components/components/_government_navigation.html.erb +53 -0
  22. data/app/views/govuk_publishing_components/components/_lead_paragraph.html.erb +13 -0
  23. data/app/views/govuk_publishing_components/components/_machine_readable_metadata.html.erb +21 -1
  24. data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +22 -0
  25. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +58 -0
  26. data/app/views/govuk_publishing_components/components/_title.html.erb +23 -0
  27. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +1 -0
  28. data/app/views/govuk_publishing_components/components/docs/government_navigation.yml +18 -0
  29. data/app/views/govuk_publishing_components/components/docs/inverse_header.yml +10 -10
  30. data/app/views/govuk_publishing_components/components/docs/lead_paragraph.yml +22 -0
  31. data/app/views/govuk_publishing_components/components/docs/meta_tags.yml +1 -0
  32. data/app/views/govuk_publishing_components/components/docs/phase_banner.yml +21 -0
  33. data/app/views/govuk_publishing_components/components/docs/previous_and_next_navigation.yml +64 -0
  34. data/app/views/govuk_publishing_components/components/docs/title.yml +63 -0
  35. data/lib/govuk_publishing_components.rb +1 -0
  36. data/lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb +72 -0
  37. data/lib/govuk_publishing_components/presenters/machine_readable/news_article_schema.rb +16 -0
  38. data/lib/govuk_publishing_components/presenters/machine_readable/page.rb +47 -0
  39. data/lib/govuk_publishing_components/presenters/sanitisation.rb +13 -0
  40. data/lib/govuk_publishing_components/presenters/schema_org.rb +13 -101
  41. data/lib/govuk_publishing_components/version.rb +1 -1
  42. metadata +23 -3
@@ -0,0 +1,63 @@
1
+ name: Page title
2
+ description: A page title with optional context label
3
+ body: |
4
+ This contains an optional parameter for average title length. The two valid
5
+ values for this parameter are 'medium' or 'long'. Medium titles are titles
6
+ where the average is around 30 characters or less. Long titles would have
7
+ an average length of nearer 50 characters or more.
8
+
9
+ On average the titles on government bits of content are 50 characters. The
10
+ average for bits of general guidance are nearer 27 characters long.
11
+ accessibility_criteria: |
12
+ The page title must:
13
+
14
+ - be part of a correct heading structure for a page
15
+ - be semantically represented as a heading
16
+ - convey the heading level
17
+ shared_accessibility_criteria:
18
+ - link
19
+ examples:
20
+ default:
21
+ data:
22
+ title: My page title
23
+ with_context:
24
+ data:
25
+ context: Publication
26
+ title: My page title
27
+ with_context_link:
28
+ description: |
29
+ It’s unclear if links in the context of a title are useful and are being clicked by users. Data attributes are included to track this behaviour.
30
+
31
+ Context links are used on [topic pages](https://www.gov.uk/topic/business-tax/vat) where there is also a breadcrumb.
32
+ data:
33
+ context:
34
+ text: Publication
35
+ href: '/link'
36
+ data:
37
+ some_tracking_parameter: 'tracking-param'
38
+ title: My page title
39
+ long_title_with_context:
40
+ data:
41
+ context: Publication
42
+ title: My page title which is often really long and verbose and has lots of extra words it doesn't need
43
+ average_title_length: long
44
+ in_html_publication:
45
+ description: Page titles are used in HTML Publications ([see example](https://www.gov.uk/government/publications/fees-for-civil-and-family-courts/court-fees-for-the-high-court-county-court-and-family-court))
46
+ data:
47
+ context: Publication
48
+ title: HTML publication page title
49
+ inverse: true
50
+ margin_bottom: 0
51
+ context:
52
+ dark_background: true
53
+ in_html_publication_with_context_link:
54
+ description: Page titles are used in HTML Publications ([see example](https://www.gov.uk/government/publications/fees-for-civil-and-family-courts/court-fees-for-the-high-court-county-court-and-family-court))
55
+ data:
56
+ context:
57
+ text: Publication
58
+ href: '/link'
59
+ title: HTML publication page title
60
+ inverse: true
61
+ margin_bottom: 0
62
+ context:
63
+ dark_background: true
@@ -14,6 +14,7 @@ require "govuk_publishing_components/presenters/rummager_taxonomy_sidebar_links"
14
14
  require "govuk_publishing_components/presenters/curated_taxonomy_sidebar_links"
15
15
  require "govuk_publishing_components/presenters/content_item"
16
16
  require "govuk_publishing_components/presenters/translation_nav_helper"
17
+ require "govuk_publishing_components/presenters/sanitisation"
17
18
  require "govuk_publishing_components/presenters/subscription_links_helper"
18
19
  require "govuk_publishing_components/presenters/schema_org"
19
20
  require "govuk_publishing_components/presenters/heading_helper"
@@ -0,0 +1,72 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class ArticleSchema
4
+ attr_reader :page
5
+
6
+ def initialize(page)
7
+ @page = page
8
+ end
9
+
10
+ def structured_data
11
+ # http://schema.org/Article
12
+ {
13
+ "@context" => "http://schema.org",
14
+ "@type" => "Article",
15
+ "mainEntityOfPage" => {
16
+ "@type" => "WebPage",
17
+ "@id" => page.canonical_url,
18
+ },
19
+ "headline" => page.title,
20
+ "datePublished" => page.content_item["first_published_at"],
21
+ "dateModified" => page.content_item["public_updated_at"],
22
+ "description" => page.description,
23
+ "publisher" => {
24
+ "@type" => "Organization",
25
+ "name" => "GOV.UK",
26
+ "url" => "https://www.gov.uk",
27
+ }
28
+ }.merge(image_schema).merge(author_schema).merge(body)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :presenter
34
+
35
+ # Not all formats have a `body` - some have their content split over
36
+ # multiple fields. In this case we'll skip the `articleBody` field
37
+ def body
38
+ return {} unless page.body
39
+
40
+ {
41
+ "articleBody" => page.body
42
+ }
43
+ end
44
+
45
+ def image_schema
46
+ return {} unless page.has_image?
47
+
48
+ {
49
+ "image" => [
50
+ page.image_url
51
+ ]
52
+ }
53
+ end
54
+
55
+ def author_schema
56
+ return {} unless publishing_organisation
57
+
58
+ {
59
+ "author" => {
60
+ "@type" => "Organization",
61
+ "name" => publishing_organisation["title"],
62
+ "url" => Plek.current.website_root + publishing_organisation["base_path"],
63
+ }
64
+ }
65
+ end
66
+
67
+ def publishing_organisation
68
+ page.content_item.dig("links", "primary_publishing_organisation").to_a.first
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class NewsArticleSchema
4
+ def initialize(page)
5
+ @page = page
6
+ end
7
+
8
+ def structured_data
9
+ # http://schema.org/NewsArticle
10
+ data = ArticleSchema.new(@page).structured_data
11
+ data["@type"] = "NewsArticle"
12
+ data
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class Page
4
+ attr_reader :local_assigns
5
+
6
+ def initialize(local_assigns)
7
+ @local_assigns = local_assigns
8
+ end
9
+
10
+ def schema
11
+ local_assigns.fetch(:schema)
12
+ end
13
+
14
+ def canonical_url
15
+ local_assigns[:canonical_url] || (Plek.current.website_root + content_item["base_path"])
16
+ end
17
+
18
+ def body
19
+ local_assigns[:body] || content_item["details"]["body"]
20
+ end
21
+
22
+ def title
23
+ local_assigns[:title] || content_item["title"]
24
+ end
25
+
26
+ def description
27
+ content_item["description"]
28
+ end
29
+
30
+ def has_image?
31
+ content_item.dig("details", "image").present?
32
+ end
33
+
34
+ def image_url
35
+ content_item.dig("details", "image", "url")
36
+ end
37
+
38
+ def image_alt_text
39
+ content_item.dig("details", "image", "alt_text")
40
+ end
41
+
42
+ def content_item
43
+ local_assigns[:content_item]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ # @private
4
+ class Sanitisation
5
+ # Use `sub` on a potentially unsafe string. This method will sanitize
6
+ # the method first, do the replacement, and mark the result as HTML safe.
7
+ def self.sub_safely(string, pattern, replacement)
8
+ escaped_text = ERB::Util.html_escape_once(string.strip)
9
+ escaped_text.sub(pattern, replacement).html_safe
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,111 +1,23 @@
1
+ require 'govuk_publishing_components/presenters/machine_readable/page'
2
+ require 'govuk_publishing_components/presenters/machine_readable/article_schema'
3
+ require 'govuk_publishing_components/presenters/machine_readable/news_article_schema'
4
+
1
5
  module GovukPublishingComponents
2
6
  module Presenters
3
7
  class SchemaOrg
4
- def initialize(local_assigns)
5
- @local_assigns = local_assigns
8
+ attr_reader :page
9
+
10
+ def initialize(page)
11
+ @page = page
6
12
  end
7
13
 
8
14
  def structured_data
9
- if @local_assigns.fetch(:schema) == :article
10
- ArticleSchema.new(@local_assigns).structured_data
11
- elsif @local_assigns.fetch(:schema) == :news_article
12
- NewsArticleSchema.new(@local_assigns).structured_data
15
+ if page.schema == :article
16
+ ArticleSchema.new(page).structured_data
17
+ elsif page.schema == :news_article
18
+ NewsArticleSchema.new(page).structured_data
13
19
  else
14
- raise "#{@local_assigns.fetch(:schema)} is not supported"
15
- end
16
- end
17
-
18
- class NewsArticleSchema
19
- def initialize(local_assigns)
20
- @local_assigns = local_assigns
21
- end
22
-
23
- def structured_data
24
- # http://schema.org/NewsArticle
25
- data = ArticleSchema.new(@local_assigns).structured_data
26
- data["@type"] = "NewsArticle"
27
- data
28
- end
29
- end
30
-
31
- class ArticleSchema
32
- attr_reader :content_item, :canonical_url, :local_assigns
33
-
34
- def initialize(local_assigns)
35
- @local_assigns = local_assigns
36
-
37
- @content_item = local_assigns[:content_item]
38
- @canonical_url = local_assigns[:canonical_url]
39
- @custom_body = local_assigns[:body]
40
- end
41
-
42
- def structured_data
43
- # http://schema.org/Article
44
- {
45
- "@context" => "http://schema.org",
46
- "@type" => "Article",
47
- "mainEntityOfPage" => {
48
- "@type" => "WebPage",
49
- "@id" => canonical_url || page_url_from_content_item,
50
- },
51
- "headline" => local_assigns[:title] || content_item["title"],
52
- "datePublished" => content_item["first_published_at"],
53
- "dateModified" => content_item["public_updated_at"],
54
- "description" => content_item["description"],
55
- "publisher" => {
56
- "@type" => "Organization",
57
- "name" => "GOV.UK",
58
- "url" => "https://www.gov.uk",
59
- }
60
- }.merge(image_schema).merge(author_schema).merge(body)
61
- end
62
-
63
- private
64
-
65
- attr_reader :presenter
66
-
67
- # Not all formats have a `body` - some have their content split over
68
- # multiple fields. In this case we'll skip the `articleBody` field
69
- def body
70
- return {} unless @custom_body || content_item["details"]["body"]
71
-
72
- {
73
- "articleBody" => @custom_body || content_item["details"]["body"]
74
- }
75
- end
76
-
77
- def image_schema
78
- return {} unless image
79
-
80
- {
81
- "image" => [
82
- image["url"],
83
- ]
84
- }
85
- end
86
-
87
- def author_schema
88
- return {} unless publishing_organisation
89
-
90
- {
91
- "author" => {
92
- "@type" => "Organization",
93
- "name" => publishing_organisation["title"],
94
- "url" => Plek.current.website_root + publishing_organisation["base_path"],
95
- }
96
- }
97
- end
98
-
99
- def publishing_organisation
100
- content_item.dig("links", "primary_publishing_organisation").to_a.first
101
- end
102
-
103
- def page_url_from_content_item
104
- Plek.current.website_root + content_item["base_path"]
105
- end
106
-
107
- def image
108
- content_item.dig("details", "image")
20
+ raise "#{page.schema} is not supported"
109
21
  end
110
22
  end
111
23
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '8.1.0'.freeze
2
+ VERSION = '8.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.2.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-05-16 00:00:00.000000000 Z
11
+ date: 2018-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -336,6 +336,9 @@ files:
336
336
  - app/assets/stylesheets/govuk_publishing_components/components/_input.scss
337
337
  - app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss
338
338
  - app/assets/stylesheets/govuk_publishing_components/components/_label.scss
339
+ - app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss
340
+ - app/assets/stylesheets/govuk_publishing_components/components/_phase-banner.scss
341
+ - app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss
339
342
  - app/assets/stylesheets/govuk_publishing_components/components/_radio.scss
340
343
  - app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss
341
344
  - app/assets/stylesheets/govuk_publishing_components/components/_search.scss
@@ -346,6 +349,7 @@ files:
346
349
  - app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss
347
350
  - app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss
348
351
  - app/assets/stylesheets/govuk_publishing_components/components/_taxonomy-navigation.scss
352
+ - app/assets/stylesheets/govuk_publishing_components/components/_title.scss
349
353
  - app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss
350
354
  - app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss
351
355
  - app/assets/stylesheets/govuk_publishing_components/components/helpers/_px-to-em.scss
@@ -358,15 +362,17 @@ files:
358
362
  - app/assets/stylesheets/govuk_publishing_components/components/print/_feedback.scss
359
363
  - app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss
360
364
  - app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss
365
+ - app/assets/stylesheets/govuk_publishing_components/components/print/_title.scss
361
366
  - app/controllers/govuk_publishing_components/application_controller.rb
362
367
  - app/controllers/govuk_publishing_components/component_guide_controller.rb
363
368
  - app/helpers/govuk_publishing_components/application_helper.rb
364
369
  - app/models/govuk_publishing_components/component_doc.rb
365
- - app/models/govuk_publishing_components/component_doc_resolver.rb
370
+ - app/models/govuk_publishing_components/component_docs.rb
366
371
  - app/models/govuk_publishing_components/component_example.rb
367
372
  - app/models/govuk_publishing_components/shared_accessibility_criteria.rb
368
373
  - app/views/govuk_publishing_components/component_guide/component_doc/_call.html.erb
369
374
  - app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb
375
+ - app/views/govuk_publishing_components/component_guide/component_doc/_component_output.html.erb
370
376
  - app/views/govuk_publishing_components/component_guide/component_doc/_preview.html.erb
371
377
  - app/views/govuk_publishing_components/component_guide/example.html.erb
372
378
  - app/views/govuk_publishing_components/component_guide/index.html.erb
@@ -381,12 +387,16 @@ files:
381
387
  - app/views/govuk_publishing_components/components/_error_summary.html.erb
382
388
  - app/views/govuk_publishing_components/components/_feedback.html.erb
383
389
  - app/views/govuk_publishing_components/components/_fieldset.html.erb
390
+ - app/views/govuk_publishing_components/components/_government_navigation.html.erb
384
391
  - app/views/govuk_publishing_components/components/_heading.html.erb
385
392
  - app/views/govuk_publishing_components/components/_input.html.erb
386
393
  - app/views/govuk_publishing_components/components/_inverse_header.html.erb
387
394
  - app/views/govuk_publishing_components/components/_label.html.erb
395
+ - app/views/govuk_publishing_components/components/_lead_paragraph.html.erb
388
396
  - app/views/govuk_publishing_components/components/_machine_readable_metadata.html.erb
389
397
  - app/views/govuk_publishing_components/components/_meta_tags.html.erb
398
+ - app/views/govuk_publishing_components/components/_phase_banner.html.erb
399
+ - app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
390
400
  - app/views/govuk_publishing_components/components/_radio.html.erb
391
401
  - app/views/govuk_publishing_components/components/_related_navigation.html.erb
392
402
  - app/views/govuk_publishing_components/components/_search.html.erb
@@ -397,6 +407,7 @@ files:
397
407
  - app/views/govuk_publishing_components/components/_subscription-links.html.erb
398
408
  - app/views/govuk_publishing_components/components/_success_alert.html.erb
399
409
  - app/views/govuk_publishing_components/components/_taxonomy_navigation.html.erb
410
+ - app/views/govuk_publishing_components/components/_title.html.erb
400
411
  - app/views/govuk_publishing_components/components/_translation-nav.html.erb
401
412
  - app/views/govuk_publishing_components/components/docs/back_link.yml
402
413
  - app/views/govuk_publishing_components/components/docs/breadcrumbs.yml
@@ -407,12 +418,16 @@ files:
407
418
  - app/views/govuk_publishing_components/components/docs/error_summary.yml
408
419
  - app/views/govuk_publishing_components/components/docs/feedback.yml
409
420
  - app/views/govuk_publishing_components/components/docs/fieldset.yml
421
+ - app/views/govuk_publishing_components/components/docs/government_navigation.yml
410
422
  - app/views/govuk_publishing_components/components/docs/heading.yml
411
423
  - app/views/govuk_publishing_components/components/docs/input.yml
412
424
  - app/views/govuk_publishing_components/components/docs/inverse_header.yml
413
425
  - app/views/govuk_publishing_components/components/docs/label.yml
426
+ - app/views/govuk_publishing_components/components/docs/lead_paragraph.yml
414
427
  - app/views/govuk_publishing_components/components/docs/machine_readable_metadata.yml
415
428
  - app/views/govuk_publishing_components/components/docs/meta_tags.yml
429
+ - app/views/govuk_publishing_components/components/docs/phase_banner.yml
430
+ - app/views/govuk_publishing_components/components/docs/previous_and_next_navigation.yml
416
431
  - app/views/govuk_publishing_components/components/docs/radio.yml
417
432
  - app/views/govuk_publishing_components/components/docs/related_navigation.yml
418
433
  - app/views/govuk_publishing_components/components/docs/search.yml
@@ -423,6 +438,7 @@ files:
423
438
  - app/views/govuk_publishing_components/components/docs/subscription-links.yml
424
439
  - app/views/govuk_publishing_components/components/docs/success_alert.yml
425
440
  - app/views/govuk_publishing_components/components/docs/taxonomy_navigation.yml
441
+ - app/views/govuk_publishing_components/components/docs/title.yml
426
442
  - app/views/govuk_publishing_components/components/docs/translation-nav.yml
427
443
  - app/views/govuk_publishing_components/components/related_navigation/_section.html.erb
428
444
  - app/views/layouts/govuk_publishing_components/application.html.erb
@@ -448,10 +464,14 @@ files:
448
464
  - lib/govuk_publishing_components/presenters/contextual_navigation.rb
449
465
  - lib/govuk_publishing_components/presenters/curated_taxonomy_sidebar_links.rb
450
466
  - lib/govuk_publishing_components/presenters/heading_helper.rb
467
+ - lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
468
+ - lib/govuk_publishing_components/presenters/machine_readable/news_article_schema.rb
469
+ - lib/govuk_publishing_components/presenters/machine_readable/page.rb
451
470
  - lib/govuk_publishing_components/presenters/meta_tags.rb
452
471
  - lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb
453
472
  - lib/govuk_publishing_components/presenters/related_navigation_helper.rb
454
473
  - lib/govuk_publishing_components/presenters/rummager_taxonomy_sidebar_links.rb
474
+ - lib/govuk_publishing_components/presenters/sanitisation.rb
455
475
  - lib/govuk_publishing_components/presenters/schema_org.rb
456
476
  - lib/govuk_publishing_components/presenters/services.rb
457
477
  - lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb