content_block_tools 1.4.1 → 1.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: c34b07afe5921c6615c4b9e8a7411361ade415837086f38d1536c90f440f6f62
|
4
|
+
data.tar.gz: c71bc6c809d2633613aedd8e4b1c35d22cba35c6307ca1f12ec9da6410293678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8141f6186ec06d0890dea636d293d650aa3ef3e1e69b86fa88bac0c937e61e9e3a5bd299b2e6dd66c8bd390dc7213c1b2b2a21dd7251fdae03108433b8cf0be
|
7
|
+
data.tar.gz: 11b9f5f84654032e9cabb1d3aed0498bebc3e1396359bde3fc56683c6a79c931f47ca753b05022e23bf86f50c35ec55427975c484eb5834e415f50a952ee2ded
|
@@ -51,13 +51,57 @@ module ContentBlockTools
|
|
51
51
|
#
|
52
52
|
# @return [Array<ContentBlockReference>] An array of content block references
|
53
53
|
def find_all_in_document(document)
|
54
|
-
document.scan(
|
55
|
-
|
56
|
-
ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
|
57
|
-
ContentBlockReference.new(document_type: match[1], identifier: match[2], embed_code: match[0])
|
54
|
+
document.scan(EMBED_REGEX).map do |match_data|
|
55
|
+
ContentBlockReference.from_match_data(match_data)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
59
|
+
# Converts a single embed code string into a ContentBlockReference object
|
60
|
+
#
|
61
|
+
# Parses an embed code string using {EMBED_REGEX} to extract the document type,
|
62
|
+
# identifier, and embed code, then creates a ContentBlockReference instance.
|
63
|
+
#
|
64
|
+
# @param embed_code [String] the embed code to parse
|
65
|
+
# @example Parse an embed code with a UUID
|
66
|
+
# ContentBlockReference.from_string("{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}")
|
67
|
+
# #=> #<ContentBlockReference document_type="content_block_pension" identifier="2b92cade-549c-4449-9796-e7a3957f3a86" embed_code="{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}">
|
68
|
+
# @example Parse an embed code with a slug
|
69
|
+
# ContentBlockReference.from_string("{{embed:content_block_contact:some-slug}}")
|
70
|
+
# #=> #<ContentBlockReference document_type="content_block_contact" identifier="some-slug" embed_code="{{embed:content_block_contact:some-slug}}">
|
71
|
+
# @return [ContentBlockReference] a new ContentBlockReference instance
|
72
|
+
# @raise [InvalidEmbedCodeError] if the embed_code doesn't match {EMBED_REGEX} (match_data will be nil)
|
73
|
+
# @see from_match_data
|
74
|
+
def from_string(embed_code)
|
75
|
+
match_data = embed_code.match(/^#{EMBED_REGEX}$/)
|
76
|
+
raise InvalidEmbedCodeError unless match_data
|
77
|
+
|
78
|
+
ContentBlockReference.from_match_data(match_data.captures)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Converts match data from a regex scan into a ContentBlockReference object
|
82
|
+
#
|
83
|
+
# This method is used internally by {find_all_in_document} and {from_string} to create
|
84
|
+
# ContentBlockReference instances from regex match data. It normalizes the match data
|
85
|
+
# by replacing en/em dashes with double/triple dashes (which can occur due to Kramdown's
|
86
|
+
# markdown parsing) before creating the object.
|
87
|
+
#
|
88
|
+
# @param match_data [MatchData, Array] the match data from scanning with {EMBED_REGEX}
|
89
|
+
# Expected to contain: [full_match, document_type, identifier, field]
|
90
|
+
# @example Creating from match data
|
91
|
+
# match_data = "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}".match(EMBED_REGEX)
|
92
|
+
# ContentBlockReference.from_match_data(match_data)
|
93
|
+
# #=> #<ContentBlockReference document_type="content_block_pension" identifier="2b92cade-549c-4449-9796-e7a3957f3a86" embed_code="{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}">
|
94
|
+
# @return [ContentBlockReference] a new ContentBlockReference instance
|
95
|
+
# @api private
|
96
|
+
# @see find_all_in_document
|
97
|
+
# @see from_string
|
98
|
+
# @see prepare_match
|
99
|
+
def from_match_data(match_data)
|
100
|
+
match = prepare_match(match_data)
|
101
|
+
ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
|
102
|
+
ContentBlockReference.new(document_type: match[1], identifier: match[2], embed_code: match[0])
|
103
|
+
end
|
104
|
+
|
61
105
|
private
|
62
106
|
|
63
107
|
# This replaces an en / em dashes in content block references with double or triple dashes. This can occur
|
data/lib/content_block_tools.rb
CHANGED