content_block_tools 0.9.0 → 0.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: 565c412328ad54e9e45ca5ce473e6876147543cf88900dafde91083042c6b0ab
4
- data.tar.gz: 8de3aab0cbfb65213cf1dceadd420ebdd1c006d6f9e715963bb6e49383617b1b
3
+ metadata.gz: 076d610c0146672c70d0b2d7971b6917c87fc395599ff546e0f50a0fe6817bf5
4
+ data.tar.gz: 3027bd4756b5246363b8ad1f220d9ec6da2e3c30dd79d3b1716ac568146be0fa
5
5
  SHA512:
6
- metadata.gz: ffda22c0d89798cea8b029ee90c2bc65564ab25fe7de67047251aafd53b01b1a7f127bc5c4af9deebba2e21e968767380dbde01993d9d9143394f7e0308ad5a4
7
- data.tar.gz: '07429aa7168f233ca8935cf7c20c4e30221bdf0a1970f4376ffa30214e5bd09307509f331e97fd86e30d8babe94c7e4242c5a2cfe757dc0bfacf00a4362e351b'
6
+ metadata.gz: 31ebe02a43ba3a92b7f5c18717dc7e9b889aba02fd453d68f7bd71a494d82af835c182eebd8ff54abeed544dc0983016ef1abf659b356faca233d1ca8da3e8dc
7
+ data.tar.gz: 1dd7eeeaa7aaba5f6ff1c7ca485eb4ed131dd604845dce282c700318f1314b281989d9993074e55f0dd12ba17e0324372a36acd9f508cfb506c53a6862c3a74a
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.10.0
11
+
12
+ - Add content block titles to individual contact blocks ([60](https://github.com/alphagov/govuk_content_block_tools/pull/60))
13
+ - Render title and description within telephone blocks ([60](https://github.com/alphagov/govuk_content_block_tools/pull/60))
14
+
10
15
  ## 0.9.0
11
16
 
12
17
  - Render addresses within a `contact` div ([58](https://github.com/alphagov/govuk_content_block_tools/pull/58))
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rubocop-govuk", "5.1.15"
32
32
 
33
33
  spec.add_dependency "actionview", ">= 6"
34
+ spec.add_dependency "govspeak", "10.4.1"
34
35
  end
@@ -0,0 +1,10 @@
1
+ module ContentBlockTools
2
+ module Govspeak
3
+ def render_govspeak(body, root_class: nil)
4
+ html = ::Govspeak::Document.new(body).to_html
5
+ Nokogiri::HTML.fragment(html).tap { |fragment|
6
+ fragment.children[0].add_class(root_class) if root_class
7
+ }.to_s.html_safe
8
+ end
9
+ end
10
+ end
@@ -75,7 +75,7 @@ module ContentBlockTools
75
75
  return content_block.embed_code
76
76
  end
77
77
 
78
- field_or_block_presenter.new(field_or_block_content, rendering_context: :field_names).render
78
+ field_or_block_presenter.new(field_or_block_content, rendering_context: :field_names, content_block:).render
79
79
  end
80
80
 
81
81
  def field_names
@@ -4,6 +4,8 @@ module ContentBlockTools
4
4
  class BasePresenter
5
5
  include ActionView::Context
6
6
  include ActionView::Helpers::TextHelper
7
+ include ContentBlockTools::Govspeak
8
+
7
9
  BASE_TAG_TYPE = :span
8
10
 
9
11
  attr_reader :item
@@ -19,16 +19,6 @@ module ContentBlockTools
19
19
  end
20
20
  end
21
21
 
22
- def wrapper(&block)
23
- if @rendering_context == :field_names
24
- content_tag(:div, class: "contact") do
25
- yield block
26
- end
27
- else
28
- yield block
29
- end
30
- end
31
-
32
22
  def class_for_field_name(field_name)
33
23
  {
34
24
  street_address: "street-address",
@@ -5,20 +5,28 @@ module ContentBlockTools
5
5
  module BlockLevelContactItem
6
6
  BASE_TAG_TYPE = :div
7
7
 
8
- def initialize(item, rendering_context: :block, **_args)
8
+ def initialize(item, content_block:, rendering_context: :block, **_args)
9
9
  @item = item
10
+ @content_block = content_block
10
11
  @rendering_context = rendering_context
11
12
  end
12
13
 
13
14
  def wrapper(&block)
14
15
  if @rendering_context == :field_names
15
16
  content_tag(:div, class: "contact") do
16
- yield block
17
+ concat title
18
+ concat yield block
17
19
  end
18
20
  else
19
21
  yield block
20
22
  end
21
23
  end
24
+
25
+ def title
26
+ content_tag(:p,
27
+ @content_block.title,
28
+ class: "govuk-!-margin-bottom-3")
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -10,6 +10,7 @@ module ContentBlockTools
10
10
  def render
11
11
  wrapper do
12
12
  content_tag(:div, class: "email-url-number") do
13
+ concat title_and_description
13
14
  concat number_list
14
15
  concat opening_hours_list if item[:opening_hours].present?
15
16
  concat call_charges_link
@@ -17,6 +18,27 @@ module ContentBlockTools
17
18
  end
18
19
  end
19
20
 
21
+ def title_and_description
22
+ items = [
23
+ (item_title if item[:title].present?),
24
+ (description if item[:description].present?),
25
+ ].compact
26
+
27
+ if items.any?
28
+ content_tag(:div, class: "govuk-!-margin-bottom-3") do
29
+ concat items.join("").html_safe
30
+ end
31
+ end
32
+ end
33
+
34
+ def item_title
35
+ content_tag(:p, item[:title], { class: "govuk-!-margin-bottom-0" })
36
+ end
37
+
38
+ def description
39
+ render_govspeak(item[:description], root_class: "govuk-!-margin-top-1 govuk-!-margin-bottom-0")
40
+ end
41
+
20
42
  def number_list
21
43
  content_tag(:ul) do
22
44
  item[:telephone_numbers].each do |number|
@@ -27,7 +27,7 @@ module ContentBlockTools
27
27
  concat content_tag(:p, content_block.title, class: "fn org")
28
28
  embedded_objects.each do |object|
29
29
  items = send(object)
30
- concat(items.map { |item| presenter_for_object_type(object).new(item).render }.join.html_safe)
30
+ concat(items.map { |item| presenter_for_object_type(object).new(item, content_block:).render }.join.html_safe)
31
31
  end
32
32
  end
33
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  require "action_view"
4
4
  require "uri"
5
+ require "govspeak"
6
+
7
+ require "content_block_tools/helpers/govspeak"
5
8
 
6
9
  require "content_block_tools/presenters/field_presenters/base_presenter"
7
10
  require "content_block_tools/presenters/field_presenters/contact/email_address_presenter"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_block_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -79,6 +79,20 @@ dependencies:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '6'
82
+ - !ruby/object:Gem::Dependency
83
+ name: govspeak
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '='
87
+ - !ruby/object:Gem::Version
88
+ version: 10.4.1
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '='
94
+ - !ruby/object:Gem::Version
95
+ version: 10.4.1
82
96
  email:
83
97
  - govuk-dev@digital.cabinet-office.gov.uk
84
98
  executables: []
@@ -105,6 +119,7 @@ files:
105
119
  - lib/content_block_tools.rb
106
120
  - lib/content_block_tools/content_block.rb
107
121
  - lib/content_block_tools/content_block_reference.rb
122
+ - lib/content_block_tools/helpers/govspeak.rb
108
123
  - lib/content_block_tools/presenters/base_presenter.rb
109
124
  - lib/content_block_tools/presenters/block_presenters/base_presenter.rb
110
125
  - lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb
@@ -135,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
150
  - !ruby/object:Gem::Version
136
151
  version: '0'
137
152
  requirements: []
138
- rubygems_version: 3.6.9
153
+ rubygems_version: 3.7.0
139
154
  specification_version: 4
140
155
  summary: A suite of tools for working with GOV.UK Content Blocks
141
156
  test_files: []