Class: ContentBlockTools::ContentBlockReference
- Inherits:
-
Data
- Object
- Data
- ContentBlockTools::ContentBlockReference
- Defined in:
- lib/content_block_tools/content_block_reference.rb
Overview
Defines a reference pointer for a Content Block
Constant Summary collapse
- SUPPORTED_DOCUMENT_TYPES =
An array of the supported document types
%w[contact content_block_email_address].freeze
- UUID_REGEX =
The regex used to find UUIDs
/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
- EMBED_REGEX =
The regex used when scanning a document using find_all_in_document
/({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/
Instance Attribute Summary collapse
-
#content_id ⇒ String
readonly
The content UUID for a block.
-
#document_type ⇒ String
readonly
The document type of the content block - this will be used to work out which Presenter will be used to render the content block.
-
#embed_code ⇒ String
readonly
The embed_code used for a block.
Class Method Summary collapse
-
.find_all_in_document(document) ⇒ Array<ContentBlockReference>
Finds all content block references within a document, using ‘ContentBlockReference::EMBED_REGEX` to scan through the document.
Instance Attribute Details
#content_id ⇒ String (readonly)
The content UUID for a block
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/content_block_tools/content_block_reference.rb', line 27 class ContentBlockReference < Data # An array of the supported document types SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze # The regex used to find UUIDs UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ # The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document} EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/ class << self # Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX` # to scan through the document # # @return [Array<ContentBlockReference>] An array of content block references def find_all_in_document(document) document.scan(ContentBlockReference::EMBED_REGEX).map do |match| ContentBlockReference.new(document_type: match[1], content_id: match[2], embed_code: match[0]) end end end end |
#document_type ⇒ String (readonly)
The document type of the content block - this will be used to work out which Presenter will be used to render the content block. All supported document_types are documented in SUPPORTED_DOCUMENT_TYPES
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/content_block_tools/content_block_reference.rb', line 27 class ContentBlockReference < Data # An array of the supported document types SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze # The regex used to find UUIDs UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ # The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document} EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/ class << self # Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX` # to scan through the document # # @return [Array<ContentBlockReference>] An array of content block references def find_all_in_document(document) document.scan(ContentBlockReference::EMBED_REGEX).map do |match| ContentBlockReference.new(document_type: match[1], content_id: match[2], embed_code: match[0]) end end end end |
#embed_code ⇒ String (readonly)
The embed_code used for a block
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/content_block_tools/content_block_reference.rb', line 27 class ContentBlockReference < Data # An array of the supported document types SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address].freeze # The regex used to find UUIDs UUID_REGEX = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ # The regex used when scanning a document using {ContentBlockTools::ContentBlockReference.find_all_in_document} EMBED_REGEX = /({{embed:(#{SUPPORTED_DOCUMENT_TYPES.join('|')}):#{UUID_REGEX}}})/ class << self # Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX` # to scan through the document # # @return [Array<ContentBlockReference>] An array of content block references def find_all_in_document(document) document.scan(ContentBlockReference::EMBED_REGEX).map do |match| ContentBlockReference.new(document_type: match[1], content_id: match[2], embed_code: match[0]) end end end end |
Class Method Details
.find_all_in_document(document) ⇒ Array<ContentBlockReference>
Finds all content block references within a document, using ‘ContentBlockReference::EMBED_REGEX` to scan through the document
40 41 42 43 44 |
# File 'lib/content_block_tools/content_block_reference.rb', line 40 def find_all_in_document(document) document.scan(ContentBlockReference::EMBED_REGEX).map do |match| ContentBlockReference.new(document_type: match[1], content_id: match[2], embed_code: match[0]) end end |