Class: ContentBlockTools::Presenters::BasePresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper
Defined in:
lib/content_block_tools/presenters/base_presenter.rb

Constant Summary collapse

BASE_TAG_TYPE =

The default HTML tag to wrap the presented response in - can be overridden in a subclass

:span
FIELD_PRESENTERS =

A lookup of presenters for particular fields - can be overridden in a subclass

{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(content_block) ⇒ {ContentBlockTools::Presenters::BasePresenter}

Returns a new presenter object

Parameters:



18
19
20
# File 'lib/content_block_tools/presenters/base_presenter.rb', line 18

def initialize(content_block)
  @content_block = content_block
end

Instance Method Details

#renderstring

Returns a HTML representation of the content block wrapped in a base tag with a class and data attributes Calls the #content method, which can be overridden in a subclass

Returns:

  • (string)

    A HTML representation of the content block



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/content_block_tools/presenters/base_presenter.rb', line 27

def render
  (
    base_tag,
    content,
    class: %W[content-embed content-embed__#{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