Class: ContentBlockTools::ContentBlock

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

Overview

Defines a Content Block

Constant Summary collapse

CONTENT_BLOCK_PREFIX =
"content_block_".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_id:, title:, document_type:, details:, embed_code:) ⇒ ContentBlock

Returns a new instance of ContentBlock.



52
53
54
55
56
57
58
# File 'lib/content_block_tools/content_block.rb', line 52

def initialize(content_id:, title:, document_type:, details:, embed_code:)
  @content_id = content_id
  @title = title
  @document_type = document_type
  @details = details
  @embed_code = embed_code
end

Instance Attribute Details

#content_idString (readonly)

The content UUID for a block

Examples:

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

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  end
end

#detailsHash (readonly)

A hash that contains the details of the content block

Examples:

content_block.details #=> { email_address: "foo@example.com" }

Returns:

  • (Hash)

    the details



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  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_pension"

Returns:

  • (String)

    the document type



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  end
end

#embed_codeString (readonly)

The embed_code used for a block containing optional field name

Examples:

content_block_reference.embed_code #=> "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}"
content_block_reference.embed_code #=> "{{embed:content_block_contact:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}}"

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  end
end

#formatString (readonly)

The format specifier from the embed code, used to control rendering output

Examples:

content_block.format #=> "years_short"

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  end
end

#titleString (readonly)

A title for the content block

Examples:

content_block.title #=> "Some title"

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/content_block_tools/content_block.rb', line 47

class ContentBlock
  CONTENT_BLOCK_PREFIX = "content_block_".freeze

  attr_reader :content_id, :title, :embed_code

  def initialize(content_id:, title:, document_type:, details:, embed_code:)
    @content_id = content_id
    @title = title
    @document_type = document_type
    @details = details
    @embed_code = embed_code
  end

  # Renders the content block to HTML using the appropriate component or presenter
  #
  # @return [String] A HTML representation of the content block
  # @see Renderer
  def render
    Renderer.new(self).render
  end

  def details
    @details.deep_symbolize_keys
  end

  def document_type
    @document_type.delete_prefix(CONTENT_BLOCK_PREFIX)
  end

  def format
    EmbedCode.new(embed_code).format
  end
end

Instance Method Details

#renderString

Renders the content block to HTML using the appropriate component or presenter

Returns:

  • (String)

    A HTML representation of the content block

See Also:



64
65
66
# File 'lib/content_block_tools/content_block.rb', line 64

def render
  Renderer.new(self).render
end