Class: ContentBlockTools::ContentBlock

Inherits:
Data
  • Object
show all
Defined in:
lib/content_block_tools/content_block.rb,
lib/content_block_tools/content_block.rb

Overview

Defines a Content Block

Constant Summary collapse

CONTENT_PRESENTERS =

A lookup of presenters for particular content block types

{
  "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
  "content_block_postal_address" => ContentBlockTools::Presenters::PostalAddressPresenter,
  "content_block_pension" => ContentBlockTools::Presenters::PensionPresenter,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_id ⇒ String (readonly)

The content UUID for a block

Examples:

content_block.id #=> "2b92cade-549c-4449-9796-e7a3957f3a86"

Returns:

  • (String)


43
44
45
# File 'lib/content_block_tools/content_block.rb', line 43

def content_id
  @content_id
end

#details ⇒ Hash (readonly)

A hash that contains the details of the content block

Examples:

content_block.details #=> { email_address: "[email protected]" }

Returns:

  • (Hash) —

    the details



43
44
45
# File 'lib/content_block_tools/content_block.rb', line 43

def details
  @details
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 ContentBlockTools::ContentBlockReference::SUPPORTED_DOCUMENT_TYPES

Examples:

content_block.document_type #=> "content_block_email_address"

Returns:

  • (String) —

    the document type



43
44
45
# File 'lib/content_block_tools/content_block.rb', line 43

def document_type
  @document_type
end

#embed_code ⇒ Object (readonly)

The embed_code used for a block containing optional field name @example content_block_reference.embed_code #=> "{embed:content_block_email_address:2b92cade-549c-4449-9796-e7a3957f3a86}" content_block_reference.embed_code #=> "{embed:content_block_postal_address:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}" @return [String]



43
44
45
# File 'lib/content_block_tools/content_block.rb', line 43

def embed_code
  @embed_code
end

#title ⇒ String (readonly)

A title for the content block

Examples:

content_block.title #=> "Some title"

Returns:

  • (String)


43
44
45
# File 'lib/content_block_tools/content_block.rb', line 43

def title
  @title
end

Instance Method Details

#render ⇒ string

Calls the appropriate presenter class to return a HTML representation of a content block. Defaults to Presenters::BasePresenter

Returns:

  • (string) —

    A HTML representation of the content block



55
56
57
58
59
# File 'lib/content_block_tools/content_block.rb', line 55

def render
  CONTENT_PRESENTERS
    .fetch(document_type, Presenters::BasePresenter)
    .new(self).render
end