content_block_tools 0.9.0 → 0.11.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/content_block_tools.gemspec +1 -0
- data/lib/content_block_tools/helpers/govspeak.rb +10 -0
- data/lib/content_block_tools/presenters/base_presenter.rb +1 -1
- data/lib/content_block_tools/presenters/block_presenters/base_presenter.rb +2 -0
- data/lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb +3 -13
- data/lib/content_block_tools/presenters/block_presenters/contact/block_level_contact_item.rb +10 -2
- data/lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb +22 -0
- data/lib/content_block_tools/presenters/contact_presenter.rb +1 -1
- data/lib/content_block_tools/version.rb +1 -1
- data/lib/content_block_tools.rb +3 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c52e34cc23cba69ff684cf24401cd78982eca8566ecbf7003f4d95b09ecf5e4c
|
4
|
+
data.tar.gz: ac0ab24be15c2a8485fb7364e68c63afcef338a1038050caaaf2d1b838169c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dc783c3a7697d8d7b52fd3067b0c33238666f237664735e97efcbd26ee17bb69e50e03a7629bce0afd7ac23d50270250b3cab07ce055fcb8be52adb44571ae7
|
7
|
+
data.tar.gz: 8464890505ccea65c1da3557a8838e156f86e39f105e86c53c534cb37cdf16e50adbbb16db9d17b1ffcddd21190dd9227843634b9599578ebf430108f156c1f2
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,15 @@
|
|
7
7
|
useful summary for people upgrading their application, not a replication
|
8
8
|
of the commit log.
|
9
9
|
|
10
|
+
## 0.11.0
|
11
|
+
|
12
|
+
- Update address and contact presenter to match model changes([61](https://github.com/alphagov/govuk_content_block_tools/pull/61))
|
13
|
+
|
14
|
+
## 0.10.0
|
15
|
+
|
16
|
+
- Add content block titles to individual contact blocks ([60](https://github.com/alphagov/govuk_content_block_tools/pull/60))
|
17
|
+
- Render title and description within telephone blocks ([60](https://github.com/alphagov/govuk_content_block_tools/pull/60))
|
18
|
+
|
10
19
|
## 0.9.0
|
11
20
|
|
12
21
|
- Render addresses within a `contact` div ([58](https://github.com/alphagov/govuk_content_block_tools/pull/58))
|
data/content_block_tools.gemspec
CHANGED
@@ -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
|
@@ -10,7 +10,7 @@ module ContentBlockTools
|
|
10
10
|
def render
|
11
11
|
wrapper do
|
12
12
|
content_tag(:p, class: "adr") do
|
13
|
-
%i[street_address
|
13
|
+
%i[street_address town_or_city state_or_county postal_code country].map { |field|
|
14
14
|
next if item[field].blank?
|
15
15
|
|
16
16
|
content_tag(:span, item[field], { class: class_for_field_name(field) })
|
@@ -19,21 +19,11 @@ 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",
|
35
|
-
|
36
|
-
|
25
|
+
town_or_city: "locality",
|
26
|
+
state_or_county: "region",
|
37
27
|
postal_code: "postal-code",
|
38
28
|
country: "country-name",
|
39
29
|
}[field_name]
|
data/lib/content_block_tools/presenters/block_presenters/contact/block_level_contact_item.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/content_block_tools.rb
CHANGED
@@ -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.
|
4
|
+
version: 0.11.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.
|
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: []
|