Class: ContentBlockTools::ContentBlock

Inherits:
Data
  • Object
show all
Defined in:
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,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_idString (readonly)

The content UUID for a block

Examples:

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

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/content_block_tools/content_block.rb', line 36

class ContentBlock < Data
  # A lookup of presenters for particular content block types
  CONTENT_PRESENTERS = {
    "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
  }.freeze

  # Calls the appropriate presenter class to return a HTML representation of a content
  # block. Defaults to {Presenters::BasePresenter}
  #
  # @return [string] A HTML representation of the content block
  def render
    CONTENT_PRESENTERS
      .fetch(document_type, Presenters::BasePresenter)
      .new(self).render
  end

  def details
    to_h[:details].symbolize_keys
  end
end

#detailsHash (readonly)

A hash that contains the details of the content block

Examples:

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

Returns:

  • (Hash)

    the details



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/content_block_tools/content_block.rb', line 36

class ContentBlock < Data
  # A lookup of presenters for particular content block types
  CONTENT_PRESENTERS = {
    "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
  }.freeze

  # Calls the appropriate presenter class to return a HTML representation of a content
  # block. Defaults to {Presenters::BasePresenter}
  #
  # @return [string] A HTML representation of the content block
  def render
    CONTENT_PRESENTERS
      .fetch(document_type, Presenters::BasePresenter)
      .new(self).render
  end

  def details
    to_h[:details].symbolize_keys
  end
end

#document_typeString (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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/content_block_tools/content_block.rb', line 36

class ContentBlock < Data
  # A lookup of presenters for particular content block types
  CONTENT_PRESENTERS = {
    "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
  }.freeze

  # Calls the appropriate presenter class to return a HTML representation of a content
  # block. Defaults to {Presenters::BasePresenter}
  #
  # @return [string] A HTML representation of the content block
  def render
    CONTENT_PRESENTERS
      .fetch(document_type, Presenters::BasePresenter)
      .new(self).render
  end

  def details
    to_h[:details].symbolize_keys
  end
end

#titleString (readonly)

A title for the content block

Examples:

content_block.title #=> "Some title"

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/content_block_tools/content_block.rb', line 36

class ContentBlock < Data
  # A lookup of presenters for particular content block types
  CONTENT_PRESENTERS = {
    "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
  }.freeze

  # Calls the appropriate presenter class to return a HTML representation of a content
  # block. Defaults to {Presenters::BasePresenter}
  #
  # @return [string] A HTML representation of the content block
  def render
    CONTENT_PRESENTERS
      .fetch(document_type, Presenters::BasePresenter)
      .new(self).render
  end

  def details
    to_h[:details].symbolize_keys
  end
end

Instance Method Details

#renderstring

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



46
47
48
49
50
# File 'lib/content_block_tools/content_block.rb', line 46

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