content_block_tools 0.4.5 → 0.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725d9ca90871eddcb941443e561d75eddd4f583b0820c13ce7a76fb383902f3d
|
4
|
+
data.tar.gz: e07516f4eb350605d598bf40c1ff093c1e43c1a4d874431a26c06624776e41bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd1d8d4b92d256863f0a92dd5034dc832552610455b93240ff4d49ffdc310160a2b6847e9355d7ce07ca90d803d10109a56d6644503d7893f74e0fb9260c82e
|
7
|
+
data.tar.gz: a93c861b548f16d213391bfa13658d36071f07c2bfb6972e50942b3c8338a2ba9cf03b54fd9cdf4c5c4d843f474b25db4378d33bd2d453bd0b90c9d7ef6c6028
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,13 @@
|
|
7
7
|
useful summary for people upgrading their application, not a replication
|
8
8
|
of the commit log.
|
9
9
|
|
10
|
+
## 0.5.0
|
11
|
+
|
12
|
+
- Support Content ID aliases ([27](https://github.com/alphagov/govuk_content_block_tools/pull/27))
|
13
|
+
|
14
|
+
## 0.4.6
|
15
|
+
- Remove noisy log ([25](https://github.com/alphagov/govuk_content_block_tools/pull/25))
|
16
|
+
|
10
17
|
## 0.4.5
|
11
18
|
|
12
19
|
- Add handling for incorrect field names and some logging ([24](https://github.com/alphagov/govuk_content_block_tools/pull/24))
|
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.
|
30
|
+
spec.add_development_dependency "rubocop-govuk", "5.1.4"
|
31
31
|
|
32
32
|
spec.add_dependency "actionview", ">= 6"
|
33
33
|
end
|
@@ -36,10 +36,10 @@ module ContentBlockTools
|
|
36
36
|
#
|
37
37
|
# @!attribute [r] embed_code
|
38
38
|
# The embed_code used for a block containing optional field name
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
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]
|
43
43
|
class ContentBlock < Data
|
44
44
|
# A lookup of presenters for particular content block types
|
45
45
|
CONTENT_PRESENTERS = {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ContentBlockTools
|
2
|
-
ContentBlockReference = Data.define(:document_type, :
|
2
|
+
ContentBlockReference = Data.define(:document_type, :identifier, :embed_code)
|
3
3
|
|
4
4
|
# Defines a reference pointer for a Content Block
|
5
5
|
#
|
@@ -13,10 +13,12 @@ module ContentBlockTools
|
|
13
13
|
# @return [String] the document type
|
14
14
|
# @api public
|
15
15
|
#
|
16
|
-
# @!attribute [r]
|
17
|
-
# The
|
16
|
+
# @!attribute [r] identifier
|
17
|
+
# The identifier for a block - can be a UUID or a slug. The UUID will refer to the `content_id` of a block
|
18
|
+
# within Publishing API, while the slug will refer to a block's Content ID alias.
|
18
19
|
# @example
|
19
|
-
# content_block_reference.
|
20
|
+
# content_block_reference.identifier #=> "2b92cade-549c-4449-9796-e7a3957f3a86"
|
21
|
+
# content_block_reference.identifier #=> "some-slug"
|
20
22
|
# @return [String]
|
21
23
|
#
|
22
24
|
# @!attribute [r] embed_code
|
@@ -28,11 +30,20 @@ module ContentBlockTools
|
|
28
30
|
# An array of the supported document types
|
29
31
|
SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address content_block_postal_address content_block_pension].freeze
|
30
32
|
# The regex used to find UUIDs
|
31
|
-
UUID_REGEX = /
|
33
|
+
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
34
|
+
# The regex used to find content ID aliases
|
35
|
+
CONTENT_ID_ALIAS_REGEX = /[a-z0-9-]+/
|
32
36
|
# The regex to find optional field names after the UUID, begins with '/'
|
33
37
|
FIELD_REGEX = /(\/[a-z0-9_\-\/]*)?/
|
34
38
|
# The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document}
|
35
|
-
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')})
|
39
|
+
EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):(#{UUID_REGEX}|#{CONTENT_ID_ALIAS_REGEX})#{FIELD_REGEX}}})/
|
40
|
+
|
41
|
+
# Returns if the identifier is an alias
|
42
|
+
#
|
43
|
+
# @return Boolean
|
44
|
+
def identifier_is_alias?
|
45
|
+
!identifier.match?(UUID_REGEX)
|
46
|
+
end
|
36
47
|
|
37
48
|
class << self
|
38
49
|
# Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX`
|
@@ -40,10 +51,9 @@ module ContentBlockTools
|
|
40
51
|
#
|
41
52
|
# @return [Array<ContentBlockReference>] An array of content block references
|
42
53
|
def find_all_in_document(document)
|
43
|
-
ContentBlockTools.logger.info("Finding embedded content")
|
44
54
|
document.scan(ContentBlockReference::EMBED_REGEX).map do |match|
|
45
55
|
ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
|
46
|
-
ContentBlockReference.new(document_type: match[1],
|
56
|
+
ContentBlockReference.new(document_type: match[1], identifier: match[2], embed_code: match[0])
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
metadata
CHANGED
@@ -1,13 +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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|
@@ -43,14 +43,14 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - '='
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 5.
|
46
|
+
version: 5.1.4
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - '='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 5.
|
53
|
+
version: 5.1.4
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: actionview
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.6.
|
117
|
+
rubygems_version: 3.6.8
|
118
118
|
specification_version: 4
|
119
119
|
summary: A suite of tools for working with GOV.UK Content Blocks
|
120
120
|
test_files: []
|