Class: ContentBlockTools::Renderer

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/content_block_tools/renderer.rb

Overview

Renders a ContentBlock to HTML

This class encapsulates the logic for rendering a content block, including determining the appropriate component or presenter to use and wrapping the result in the standard content block markup.

Examples:

content_block = ContentBlock.new(...)
html = Renderer.new(content_block).render

Defined Under Namespace

Classes: UnknownComponentError

Instance Method Summary collapse

Constructor Details

#initialize(content_block) ⇒ Renderer

Returns a new instance of Renderer.



17
18
19
# File 'lib/content_block_tools/renderer.rb', line 17

def initialize(content_block)
  @content_block = content_block
end

Instance Method Details

#renderString

Renders the content block to HTML

Returns:

  • (String)

    HTML representation of the content block



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/content_block_tools/renderer.rb', line 24

def render
  (
    base_tag,
    content,
    class: %W[content-block content-block--#{content_block.document_type}],
    data: {
      content_block: "",
      document_type: content_block.document_type,
      content_id: content_block.content_id,
      embed_code: content_block.embed_code,
    },
  )
end