content_block_tools 0.5.3 → 0.6.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 +8 -0
- data/README.md +3 -3
- data/lib/content_block_tools/content_block.rb +3 -5
- data/lib/content_block_tools/content_block_reference.rb +3 -3
- data/lib/content_block_tools/presenters/base_presenter.rb +19 -10
- data/lib/content_block_tools/presenters/contact_presenter.rb +4 -0
- data/lib/content_block_tools/version.rb +1 -1
- data/lib/content_block_tools.rb +0 -2
- metadata +1 -3
- data/lib/content_block_tools/presenters/email_address_presenter.rb +0 -14
- data/lib/content_block_tools/presenters/postal_address_presenter.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c89dc222cfb30a2a3ab8263c0203fc06fb59f5c19140b49104fa76e3a55ebf76
|
4
|
+
data.tar.gz: 750d97c98bea404136dd7ab33416409cd9cb352ae587268c405c8e22236d984c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed10a2a905af5a7747f8222d2ed9c815140371651ed2e0d9082d68c4b3ac333b1f6dc7d7c20cf6f2f4bfb376ab5896143d549760cb43eb0f01a8e2dc5520f4d4
|
7
|
+
data.tar.gz: 1eb7eb43cfbcf21cddd296d4cc1dd7985cd6b3d3ceba02bf7bab78bcbc7ce4c2aee976eabd685b2f16b39b38632c224c03c2b8909c7d70e2178550aabbce7632
|
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.6.0
|
11
|
+
|
12
|
+
- Support rendering nested blocks ([45](https://github.com/alphagov/govuk_content_block_tools/pull/45))
|
13
|
+
|
14
|
+
## 0.5.4
|
15
|
+
|
16
|
+
- Remove old email_address and postal_address types ([38](https://github.com/alphagov/govuk_content_block_tools/pull/38))
|
17
|
+
|
10
18
|
## 0.5.3
|
11
19
|
|
12
20
|
- Add spacing to contact item titles ([35](https://github.com/alphagov/govuk_content_block_tools/pull/35))
|
data/README.md
CHANGED
@@ -19,13 +19,13 @@ or add it to your Gemfile
|
|
19
19
|
To find embed code in a block of text, use `ContentBlockReference.find_all_in_document`:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
content = "Hello - here is a embed code {{embed:
|
22
|
+
content = "Hello - here is a embed code {{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}"
|
23
23
|
ContentBlockReference.find_all_in_document(content)
|
24
24
|
# =>
|
25
25
|
#[#<data ContentBlockTools::ContentBlockReference
|
26
|
-
# document_type="
|
26
|
+
# document_type="content_block_pension",
|
27
27
|
# content_id="be24ee44-b636-4a3e-b979-0da27b4a8e62",
|
28
|
-
# embed_code="{{embed:
|
28
|
+
# embed_code="{{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}">]
|
29
29
|
```
|
30
30
|
|
31
31
|
### Rendering a content block
|
@@ -23,7 +23,7 @@ module ContentBlockTools
|
|
23
23
|
# will be used to render the content block. All supported document_types are documented in
|
24
24
|
# {ContentBlockTools::ContentBlockReference::SUPPORTED_DOCUMENT_TYPES}
|
25
25
|
# @example
|
26
|
-
# content_block.document_type #=> "
|
26
|
+
# content_block.document_type #=> "content_block_pension"
|
27
27
|
# @return [String] the document type
|
28
28
|
# @api public
|
29
29
|
#
|
@@ -37,15 +37,13 @@ module ContentBlockTools
|
|
37
37
|
# @!attribute [r] embed_code
|
38
38
|
# The embed_code used for a block containing optional field name
|
39
39
|
# @example
|
40
|
-
# content_block_reference.embed_code #=> "{{embed:
|
41
|
-
# content_block_reference.embed_code #=> "{{embed:
|
40
|
+
# content_block_reference.embed_code #=> "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}"
|
41
|
+
# content_block_reference.embed_code #=> "{{embed:content_block_contact:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}}"
|
42
42
|
# @return [String]
|
43
43
|
class ContentBlock < Data
|
44
44
|
# A lookup of presenters for particular content block types
|
45
45
|
CONTENT_PRESENTERS = {
|
46
46
|
"content_block_contact" => ContentBlockTools::Presenters::ContactPresenter,
|
47
|
-
"content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
|
48
|
-
"content_block_postal_address" => ContentBlockTools::Presenters::PostalAddressPresenter,
|
49
47
|
"content_block_pension" => ContentBlockTools::Presenters::PensionPresenter,
|
50
48
|
}.freeze
|
51
49
|
|
@@ -9,7 +9,7 @@ module ContentBlockTools
|
|
9
9
|
# will be used to render the content block. All supported document_types are documented in
|
10
10
|
# {ContentBlockTools::ContentBlockReference::SUPPORTED_DOCUMENT_TYPES}
|
11
11
|
# @example
|
12
|
-
# content_block_reference.document_type #=> "
|
12
|
+
# content_block_reference.document_type #=> "content_block_pension"
|
13
13
|
# @return [String] the document type
|
14
14
|
# @api public
|
15
15
|
#
|
@@ -24,11 +24,11 @@ module ContentBlockTools
|
|
24
24
|
# @!attribute [r] embed_code
|
25
25
|
# The embed_code used for a block
|
26
26
|
# @example
|
27
|
-
# content_block_reference.embed_code #=> "{{embed:
|
27
|
+
# content_block_reference.embed_code #=> "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}"
|
28
28
|
# @return [String]
|
29
29
|
class ContentBlockReference < Data
|
30
30
|
# An array of the supported document types
|
31
|
-
SUPPORTED_DOCUMENT_TYPES = %w[contact
|
31
|
+
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_pension content_block_contact].freeze
|
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
|
@@ -10,6 +10,9 @@ module ContentBlockTools
|
|
10
10
|
# A lookup of presenters for particular fields - can be overridden in a subclass
|
11
11
|
FIELD_PRESENTERS = {}.freeze
|
12
12
|
|
13
|
+
# A lookup of presenters for particular blocks - can be overridden in a subclass
|
14
|
+
BLOCK_PRESENTERS = {}.freeze
|
15
|
+
|
13
16
|
def self.has_embedded_objects(*object_types)
|
14
17
|
@embedded_objects = object_types
|
15
18
|
|
@@ -59,26 +62,28 @@ module ContentBlockTools
|
|
59
62
|
# {#content}
|
60
63
|
def content
|
61
64
|
ContentBlockTools.logger.info("Getting content for content block #{content_block.content_id}")
|
62
|
-
|
63
|
-
content_for_fields
|
64
|
-
else
|
65
|
-
default_content
|
66
|
-
end
|
65
|
+
field_names.present? ? content_for_field_names : default_content
|
67
66
|
end
|
68
67
|
|
69
68
|
def default_content
|
70
69
|
content_block.title
|
71
70
|
end
|
72
71
|
|
73
|
-
def
|
72
|
+
def content_for_field_names
|
74
73
|
content = content_block.details.deep_symbolize_keys.dig(*field_names)
|
74
|
+
|
75
75
|
if content.blank?
|
76
76
|
ContentBlockTools.logger.warn("Content not found for content block #{content_block.content_id} and fields #{field_names}")
|
77
|
-
content_block.embed_code
|
78
|
-
else
|
79
|
-
presenter = field_presenter || ContentBlockTools::Presenters::FieldPresenters::BasePresenter
|
80
|
-
presenter.new(content).render
|
77
|
+
return content_block.embed_code
|
81
78
|
end
|
79
|
+
|
80
|
+
presenter = if content.is_a?(Hash)
|
81
|
+
block_presenter || ContentBlockTools::Presenters::BlockPresenters::BasePresenter
|
82
|
+
else
|
83
|
+
field_presenter || ContentBlockTools::Presenters::FieldPresenters::BasePresenter
|
84
|
+
end
|
85
|
+
|
86
|
+
presenter.new(content).render
|
82
87
|
end
|
83
88
|
|
84
89
|
def field_names
|
@@ -95,6 +100,10 @@ module ContentBlockTools
|
|
95
100
|
@field_presenter ||= field_names ? self.class::FIELD_PRESENTERS[field_names.last] : nil
|
96
101
|
end
|
97
102
|
|
103
|
+
def block_presenter
|
104
|
+
@block_presenter ||= field_names ? self.class::BLOCK_PRESENTERS[field_names.first] : nil
|
105
|
+
end
|
106
|
+
|
98
107
|
def base_tag
|
99
108
|
field_names ? :span : self.class::BASE_TAG_TYPE
|
100
109
|
end
|
@@ -9,6 +9,10 @@ module ContentBlockTools
|
|
9
9
|
email_address: ContentBlockTools::Presenters::FieldPresenters::Contact::EmailAddressPresenter,
|
10
10
|
}.freeze
|
11
11
|
|
12
|
+
BLOCK_PRESENTERS = {
|
13
|
+
addresses: ContentBlockTools::Presenters::BlockPresenters::Contact::AddressPresenter,
|
14
|
+
}.freeze
|
15
|
+
|
12
16
|
has_embedded_objects :addresses, :email_addresses, :telephones, :contact_forms
|
13
17
|
|
14
18
|
private
|
data/lib/content_block_tools.rb
CHANGED
@@ -14,8 +14,6 @@ require "content_block_tools/presenters/block_presenters/contact/telephone_prese
|
|
14
14
|
|
15
15
|
require "content_block_tools/presenters/base_presenter"
|
16
16
|
require "content_block_tools/presenters/contact_presenter"
|
17
|
-
require "content_block_tools/presenters/email_address_presenter"
|
18
|
-
require "content_block_tools/presenters/postal_address_presenter"
|
19
17
|
require "content_block_tools/presenters/pension_presenter"
|
20
18
|
|
21
19
|
require "content_block_tools/content_block"
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -112,11 +112,9 @@ files:
|
|
112
112
|
- lib/content_block_tools/presenters/block_presenters/contact/email_address_presenter.rb
|
113
113
|
- lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb
|
114
114
|
- lib/content_block_tools/presenters/contact_presenter.rb
|
115
|
-
- lib/content_block_tools/presenters/email_address_presenter.rb
|
116
115
|
- lib/content_block_tools/presenters/field_presenters/base_presenter.rb
|
117
116
|
- lib/content_block_tools/presenters/field_presenters/contact/email_address_presenter.rb
|
118
117
|
- lib/content_block_tools/presenters/pension_presenter.rb
|
119
|
-
- lib/content_block_tools/presenters/postal_address_presenter.rb
|
120
118
|
- lib/content_block_tools/version.rb
|
121
119
|
homepage: https://github.com/alphagov/content_block_tools
|
122
120
|
licenses:
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ContentBlockTools
|
2
|
-
module Presenters
|
3
|
-
class EmailAddressPresenter < BasePresenter
|
4
|
-
private
|
5
|
-
|
6
|
-
def content
|
7
|
-
content_tag(:a,
|
8
|
-
content_block.details[:email_address],
|
9
|
-
class: "govuk-link",
|
10
|
-
href: "mailto:#{content_block.details[:email_address]}")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module ContentBlockTools
|
2
|
-
module Presenters
|
3
|
-
class PostalAddressPresenter < BasePresenter
|
4
|
-
private
|
5
|
-
|
6
|
-
def default_content
|
7
|
-
"#{content_block.details[:line_1]}, #{content_block.details[:town_or_city]}, #{content_block.details[:postcode]}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|