Class: ContentBlockTools::EmbedCode

Inherits:
Object
  • Object
show all
Defined in:
lib/content_block_tools/embed_code.rb

Overview

Parses and represents an embed code string

An embed code identifies a content block and optionally specifies which fields to render. The format is:

{{embed:block_type:identifier}}
{{embed:block_type:identifier/field1/nested_field2}}
{{embed:block_type:identifier|format}}
{{embed:block_type:identifier/field1|format}}

Examples:

Basic embed code

embed_code = EmbedCode.new("{{embed:content_block_contact:main-office}}")
embed_code.internal_content_path.present? #=> false

Embed code with field path

embed_code = EmbedCode.new("{{embed:content_block_contact:main-office/email_addresses/main}}")
embed_code.internal_content_path.path #=> [:email_addresses, :main]

Embed code with format

embed_code = EmbedCode.new("{{embed:content_block_time_period:tax-year#years_short}}")
embed_code.format #=> "years_short"

Constant Summary collapse

FORMAT_REGEX =
/\#(?<format>[^}#]+)}}$/

Instance Method Summary collapse

Constructor Details

#initialize(embed_code_string) ⇒ EmbedCode

Returns a new instance of EmbedCode.



26
27
28
# File 'lib/content_block_tools/embed_code.rb', line 26

def initialize(embed_code_string)
  @embed_code_string = embed_code_string
end

Instance Method Details

#formatString

Returns the format specifier from the embed code

Returns:

  • (String)

    The format name, or Format::DEFAULT_FORMAT if none specified



40
41
42
# File 'lib/content_block_tools/embed_code.rb', line 40

def format
  @format ||= parse_format
end

#internal_content_pathInternalContentPath

Returns the internal content path for this embed code

Returns:



33
34
35
# File 'lib/content_block_tools/embed_code.rb', line 33

def internal_content_path
  @internal_content_path ||= InternalContentPath.new(parse_path_segments)
end