content_block_tools 0.11.0 → 0.12.1
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 +8 -0
- data/lib/content_block_tools/content_block_reference.rb +22 -2
- data/lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb +14 -2
- data/lib/content_block_tools/presenters/block_presenters/contact/block_level_contact_item.rb +7 -1
- data/lib/content_block_tools/presenters/block_presenters/contact/email_address_presenter.rb +21 -7
- data/lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb +22 -3
- data/lib/content_block_tools/presenters/contact_presenter.rb +2 -0
- data/lib/content_block_tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c58a0d3ef7154dbb64562eb49e195b35d092aa8253ae4a78281ac82969a0d2
|
4
|
+
data.tar.gz: b30e824dc93f731ce4f76feb81d4893405214c735c1c54988ddf45f3f6c7a20d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7cb23a7de08bd50f54066cccd6e2d3869030745e896d62e8f4d6b8aa48886971a1c313d7328de45d42457250752af7fd018049feda48f4c315d943867423b69
|
7
|
+
data.tar.gz: 63ac67b402438f97f09655c96be96a561e5e59c566a19ead87e8c42e55365fec94b5e8ddbefb368d3e10e68d63c271104acaf50a55de98cb96992a73ca959ff8
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@
|
|
7
7
|
useful summary for people upgrading their application, not a replication
|
8
8
|
of the commit log.
|
9
9
|
|
10
|
+
## 0.12.1
|
11
|
+
|
12
|
+
- Fix when content block codes include special dashes ([64](https://github.com/alphagov/govuk_content_block_tools/pull/64))
|
13
|
+
|
14
|
+
## 0.12.0
|
15
|
+
|
16
|
+
- Add missing fields for contact object ([62](https://github.com/alphagov/govuk_content_block_tools/pull/62))
|
17
|
+
|
10
18
|
## 0.11.0
|
11
19
|
|
12
20
|
- Update address and contact presenter to match model changes([61](https://github.com/alphagov/govuk_content_block_tools/pull/61))
|
@@ -32,9 +32,9 @@ module ContentBlockTools
|
|
32
32
|
# The regex used to find UUIDs
|
33
33
|
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
34
34
|
# The regex used to find content ID aliases
|
35
|
-
CONTENT_ID_ALIAS_REGEX = /[a-z0-9
|
35
|
+
CONTENT_ID_ALIAS_REGEX = /[a-z0-9-–—]+/
|
36
36
|
# The regex to find optional field names after the UUID, begins with '/'
|
37
|
-
FIELD_REGEX = /(\/[a-z0-9_
|
37
|
+
FIELD_REGEX = /(\/[a-z0-9_\-–—\/]*)?/
|
38
38
|
# The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document}
|
39
39
|
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):(#{UUID_REGEX}|#{CONTENT_ID_ALIAS_REGEX})#{FIELD_REGEX}}})/
|
40
40
|
|
@@ -52,10 +52,30 @@ module ContentBlockTools
|
|
52
52
|
# @return [Array<ContentBlockReference>] An array of content block references
|
53
53
|
def find_all_in_document(document)
|
54
54
|
document.scan(ContentBlockReference::EMBED_REGEX).map do |match|
|
55
|
+
match = prepare_match(match)
|
55
56
|
ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
|
56
57
|
ContentBlockReference.new(document_type: match[1], identifier: match[2], embed_code: match[0])
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# This replaces an en / em dashes in content block references with double or triple dashes. This can occur
|
64
|
+
# because Kramdown (the markdown parser that Govspeak is based on) replaces double dashes with en dashes and
|
65
|
+
# triple dashes with em dashes
|
66
|
+
def prepare_match(match)
|
67
|
+
[
|
68
|
+
replace_dashes(match[0]),
|
69
|
+
match[1],
|
70
|
+
replace_dashes(match[2]),
|
71
|
+
match[3],
|
72
|
+
]
|
73
|
+
end
|
74
|
+
|
75
|
+
def replace_dashes(value)
|
76
|
+
value&.gsub("–", "--")
|
77
|
+
&.gsub("—", "---")
|
78
|
+
end
|
59
79
|
end
|
60
80
|
end
|
61
81
|
end
|
@@ -9,13 +9,19 @@ module ContentBlockTools
|
|
9
9
|
|
10
10
|
def render
|
11
11
|
wrapper do
|
12
|
-
|
13
|
-
|
12
|
+
output = []
|
13
|
+
|
14
|
+
output << content_tag(:p, class: "adr") do
|
15
|
+
%i[title street_address town_or_city state_or_county postal_code country].map { |field|
|
14
16
|
next if item[field].blank?
|
15
17
|
|
16
18
|
content_tag(:span, item[field], { class: class_for_field_name(field) })
|
17
19
|
}.compact_blank.join(",<br/>").html_safe
|
18
20
|
end
|
21
|
+
|
22
|
+
output << render_govspeak(item[:description]) if item[:description].present?
|
23
|
+
|
24
|
+
output.join.html_safe
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
@@ -28,6 +34,12 @@ module ContentBlockTools
|
|
28
34
|
country: "country-name",
|
29
35
|
}[field_name]
|
30
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def show_title_in_field_names_context?
|
41
|
+
false
|
42
|
+
end
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
data/lib/content_block_tools/presenters/block_presenters/contact/block_level_contact_item.rb
CHANGED
@@ -14,7 +14,7 @@ module ContentBlockTools
|
|
14
14
|
def wrapper(&block)
|
15
15
|
if @rendering_context == :field_names
|
16
16
|
content_tag(:div, class: "contact") do
|
17
|
-
concat title
|
17
|
+
concat title if show_title_in_field_names_context?
|
18
18
|
concat yield block
|
19
19
|
end
|
20
20
|
else
|
@@ -27,6 +27,12 @@ module ContentBlockTools
|
|
27
27
|
@content_block.title,
|
28
28
|
class: "govuk-!-margin-bottom-3")
|
29
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def show_title_in_field_names_context?
|
34
|
+
true
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
32
38
|
end
|
@@ -10,16 +10,30 @@ module ContentBlockTools
|
|
10
10
|
def render
|
11
11
|
wrapper do
|
12
12
|
content_tag(:div, class: "email-url-number") do
|
13
|
-
|
14
|
-
|
15
|
-
concat content_tag(:a,
|
16
|
-
item[:email_address],
|
17
|
-
class: "email",
|
18
|
-
href: "mailto:#{item[:email_address]}")
|
19
|
-
end
|
13
|
+
concat email
|
14
|
+
concat render_govspeak(item[:description]) if item[:description].present?
|
20
15
|
end
|
21
16
|
end
|
22
17
|
end
|
18
|
+
|
19
|
+
def email
|
20
|
+
content_tag(:p) do
|
21
|
+
concat content_tag(:span, item[:title])
|
22
|
+
concat content_tag(:a,
|
23
|
+
item[:email_address],
|
24
|
+
class: "email",
|
25
|
+
href: "mailto:#{item[:email_address]}#{query_params}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def query_params
|
30
|
+
params = {
|
31
|
+
subject: item[:subject],
|
32
|
+
body: item[:body],
|
33
|
+
}.compact.map { |k, v| "#{k}=#{v}" }.join("&")
|
34
|
+
|
35
|
+
"?#{params}" if params.present?
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
25
39
|
end
|
@@ -12,6 +12,8 @@ module ContentBlockTools
|
|
12
12
|
content_tag(:div, class: "email-url-number") do
|
13
13
|
concat title_and_description
|
14
14
|
concat number_list
|
15
|
+
concat video_relay_service
|
16
|
+
concat bsl_details
|
15
17
|
concat opening_hours_list if item[:opening_hours].present?
|
16
18
|
concat call_charges_link
|
17
19
|
end
|
@@ -54,6 +56,21 @@ module ContentBlockTools
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
def video_relay_service
|
60
|
+
video_relay_service = item[:video_relay_service] || {}
|
61
|
+
|
62
|
+
if video_relay_service[:show]
|
63
|
+
content = "#{video_relay_service[:prefix]} #{video_relay_service[:telephone_number]}"
|
64
|
+
render_govspeak(content, root_class: "govuk-!-margin-bottom-0")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def bsl_details
|
69
|
+
bsl_guidance = item[:bsl_guidance] || {}
|
70
|
+
|
71
|
+
render_govspeak(bsl_guidance[:value], root_class: "govuk-!-margin-bottom-0") if bsl_guidance[:show]
|
72
|
+
end
|
73
|
+
|
57
74
|
def opening_hours_list
|
58
75
|
content_tag(:ul) do
|
59
76
|
item[:opening_hours].each do |item|
|
@@ -67,12 +84,14 @@ module ContentBlockTools
|
|
67
84
|
end
|
68
85
|
|
69
86
|
def call_charges_link
|
70
|
-
|
87
|
+
call_charges = item[:call_charges] || {}
|
88
|
+
|
89
|
+
if call_charges[:show_call_charges_info_url]
|
71
90
|
content_tag(:p) do
|
72
91
|
concat content_tag(:a,
|
73
|
-
|
92
|
+
call_charges[:label],
|
74
93
|
class: "govuk-link",
|
75
|
-
href:
|
94
|
+
href: call_charges[:call_charges_info_url])
|
76
95
|
end
|
77
96
|
end
|
78
97
|
end
|
@@ -2,6 +2,7 @@ module ContentBlockTools
|
|
2
2
|
module Presenters
|
3
3
|
class ContactPresenter < BasePresenter
|
4
4
|
include ActionView::Helpers::TextHelper
|
5
|
+
include ContentBlockTools::Govspeak
|
5
6
|
|
6
7
|
BASE_TAG_TYPE = :div
|
7
8
|
|
@@ -25,6 +26,7 @@ module ContentBlockTools
|
|
25
26
|
content_tag(:div, class: "content") do
|
26
27
|
content_tag(:div, class: "vcard contact-inner") do
|
27
28
|
concat content_tag(:p, content_block.title, class: "fn org")
|
29
|
+
concat render_govspeak(content_block.details[:description]) if content_block.details[:description]
|
28
30
|
embedded_objects.each do |object|
|
29
31
|
items = send(object)
|
30
32
|
concat(items.map { |item| presenter_for_object_type(object).new(item, content_block:).render }.join.html_safe)
|