content_block_tools 0.3.0 → 0.4.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/.github/workflows/autorelease.yml +2 -0
- data/.github/workflows/ci.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/content_block_tools.gemspec +2 -2
- data/lib/content_block_tools/content_block.rb +9 -1
- data/lib/content_block_tools/content_block_reference.rb +4 -2
- data/lib/content_block_tools/presenters/base_presenter.rb +23 -1
- data/lib/content_block_tools/presenters/postal_address_presenter.rb +11 -0
- data/lib/content_block_tools/version.rb +1 -1
- data/lib/content_block_tools.rb +1 -0
- metadata +6 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d0b492495818ff1ae3a52098b3386bb9f5665fa2c8aca6b260d244305d9f8d6
|
4
|
+
data.tar.gz: 4c67d72795c6345aab7619d81213293c537a7d95bb7b8fa015f8c6d1d1ff6ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68ea93d11e33b68f51c0a4893d95266cf46fcf09ab5faaff2487a83ee40c4790045610f9d055a21da9bb7d59cf266b36c9b35b397f5bbec393b6bf9778e364db
|
7
|
+
data.tar.gz: 9dae479a604a0be374db8bd8267e62c231c00e4f2da39e20d7e60de9131d7580fe4035bd1518fe9b4a94ebb6f2ed25315dc86872b9241e2f76884cd3d539ab9e
|
data/.github/workflows/ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,16 @@
|
|
7
7
|
useful summary for people upgrading their application, not a replication
|
8
8
|
of the commit log.
|
9
9
|
|
10
|
+
## 0.4.0
|
11
|
+
|
12
|
+
* BREAKING: allow support for field names in block's embed code. new ContentBlocks now require an embed code argument. (
|
13
|
+
[17]
|
14
|
+
(https://github.com/alphagov/govuk_content_block_tools/pull/17))
|
15
|
+
|
16
|
+
## 0.3.1
|
17
|
+
|
18
|
+
* Support any Rails version `>= 6` ([#10](https://github.com/alphagov/govuk_content_block_tools/pull/10))
|
19
|
+
|
10
20
|
## 0.3.0
|
11
21
|
|
12
22
|
* Symbolise details hash ([#8](https://github.com/alphagov/content_block_tools/pull/8))
|
data/content_block_tools.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_development_dependency "rake", "13.2.1"
|
29
29
|
spec.add_development_dependency "rspec", "3.13.0"
|
30
|
-
spec.add_development_dependency "rubocop-govuk", "5.0.
|
30
|
+
spec.add_development_dependency "rubocop-govuk", "5.0.3"
|
31
31
|
|
32
|
-
spec.add_dependency "actionview", ">= 6"
|
32
|
+
spec.add_dependency "actionview", ">= 6"
|
33
33
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ContentBlockTools
|
2
|
-
ContentBlock = Data.define(:content_id, :title, :document_type, :details)
|
2
|
+
ContentBlock = Data.define(:content_id, :title, :document_type, :details, :embed_code)
|
3
3
|
|
4
4
|
# Defines a Content Block
|
5
5
|
#
|
@@ -33,10 +33,18 @@ module ContentBlockTools
|
|
33
33
|
# content_block.details #=> { email_address: "foo@example.com" }
|
34
34
|
# @return [Hash] the details
|
35
35
|
# @api public
|
36
|
+
#
|
37
|
+
# @!attribute [r] embed_code
|
38
|
+
# The embed_code used for a block containing optional field name
|
39
|
+
# @example
|
40
|
+
# content_block_reference.embed_code #=> "{{embed:content_block_email_address:2b92cade-549c-4449-9796-e7a3957f3a86}}"
|
41
|
+
# content_block_reference.embed_code #=> "{{embed:content_block_postal_address:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}}"
|
42
|
+
# @return [String]
|
36
43
|
class ContentBlock < Data
|
37
44
|
# A lookup of presenters for particular content block types
|
38
45
|
CONTENT_PRESENTERS = {
|
39
46
|
"content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
|
47
|
+
"content_block_postal_address" => ContentBlockTools::Presenters::PostalAddressPresenter,
|
40
48
|
}.freeze
|
41
49
|
|
42
50
|
# Calls the appropriate presenter class to return a HTML representation of a content
|
@@ -26,11 +26,13 @@ module ContentBlockTools
|
|
26
26
|
# @return [String]
|
27
27
|
class ContentBlockReference < Data
|
28
28
|
# An array of the supported document types
|
29
|
-
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze
|
29
|
+
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address content_block_postal_address].freeze
|
30
30
|
# The regex used to find UUIDs
|
31
31
|
UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
|
32
|
+
# The regex to find optional field names after the UUID, begins with '/'
|
33
|
+
FIELD_REGEX = /(\/.*)?/
|
32
34
|
# The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document}
|
33
|
-
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/
|
35
|
+
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}#{FIELD_REGEX}}})/
|
34
36
|
|
35
37
|
class << self
|
36
38
|
# Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX`
|
@@ -29,21 +29,43 @@ module ContentBlockTools
|
|
29
29
|
content_block: "",
|
30
30
|
document_type: content_block.document_type,
|
31
31
|
content_id: content_block.content_id,
|
32
|
+
field_names: field_names&.join(","),
|
32
33
|
},
|
33
34
|
)
|
34
35
|
end
|
35
36
|
|
36
37
|
private
|
37
38
|
|
39
|
+
attr_reader :content_block
|
40
|
+
|
38
41
|
# The default representation of the content block - this can be overridden in a subclass
|
42
|
+
# by overriding the content, default_content or content_for_fields methods
|
39
43
|
#
|
40
44
|
# @return [string] A representation of the content block to be wrapped in the base_tag in
|
41
45
|
# {#content}
|
42
46
|
def content
|
47
|
+
if field_names.present?
|
48
|
+
content_for_fields
|
49
|
+
else
|
50
|
+
default_content
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def default_content
|
43
55
|
content_block.title
|
44
56
|
end
|
45
57
|
|
46
|
-
|
58
|
+
def content_for_fields
|
59
|
+
content_block.details.dig(*field_names)
|
60
|
+
end
|
61
|
+
|
62
|
+
def field_names
|
63
|
+
embed_code_match = ContentBlockReference::EMBED_REGEX.match(content_block.embed_code)
|
64
|
+
if embed_code_match.present?
|
65
|
+
all_fields = embed_code_match[4]&.reverse&.chomp("/")&.reverse
|
66
|
+
all_fields&.split("/")&.map(&:to_sym)
|
67
|
+
end
|
68
|
+
end
|
47
69
|
end
|
48
70
|
end
|
49
71
|
end
|
@@ -0,0 +1,11 @@
|
|
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
|
data/lib/content_block_tools.rb
CHANGED
@@ -5,6 +5,7 @@ require "uri"
|
|
5
5
|
|
6
6
|
require "content_block_tools/presenters/base_presenter"
|
7
7
|
require "content_block_tools/presenters/email_address_presenter"
|
8
|
+
require "content_block_tools/presenters/postal_address_presenter"
|
8
9
|
|
9
10
|
require "content_block_tools/content_block"
|
10
11
|
require "content_block_tools/content_block_reference"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-04 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rake
|
@@ -44,14 +43,14 @@ dependencies:
|
|
44
43
|
requirements:
|
45
44
|
- - '='
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.0.
|
46
|
+
version: 5.0.3
|
48
47
|
type: :development
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
51
|
- - '='
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.0.
|
53
|
+
version: 5.0.3
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
55
|
name: actionview
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,9 +58,6 @@ dependencies:
|
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '6'
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 7.2.2
|
65
61
|
type: :runtime
|
66
62
|
prerelease: false
|
67
63
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -69,10 +65,6 @@ dependencies:
|
|
69
65
|
- - ">="
|
70
66
|
- !ruby/object:Gem::Version
|
71
67
|
version: '6'
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 7.2.2
|
75
|
-
description:
|
76
68
|
email:
|
77
69
|
- govuk-dev@digital.cabinet-office.gov.uk
|
78
70
|
executables: []
|
@@ -100,12 +92,12 @@ files:
|
|
100
92
|
- lib/content_block_tools/content_block_reference.rb
|
101
93
|
- lib/content_block_tools/presenters/base_presenter.rb
|
102
94
|
- lib/content_block_tools/presenters/email_address_presenter.rb
|
95
|
+
- lib/content_block_tools/presenters/postal_address_presenter.rb
|
103
96
|
- lib/content_block_tools/version.rb
|
104
97
|
homepage: https://github.com/alphagov/content_block_tools
|
105
98
|
licenses:
|
106
99
|
- MIT
|
107
100
|
metadata: {}
|
108
|
-
post_install_message:
|
109
101
|
rdoc_options: []
|
110
102
|
require_paths:
|
111
103
|
- lib
|
@@ -120,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
112
|
- !ruby/object:Gem::Version
|
121
113
|
version: '0'
|
122
114
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
124
|
-
signing_key:
|
115
|
+
rubygems_version: 3.6.3
|
125
116
|
specification_version: 4
|
126
117
|
summary: A suite of tools for working with GOV.UK Content Blocks
|
127
118
|
test_files: []
|