class ContentBlockTools::Presenters::BasePresenter

def content

Returns:
  • (string) - A representation of the content block to be wrapped in the base_tag in
def content
  ContentBlockTools.logger.info("Getting content for content block #{content_block.content_id}")
  if field_names.present?
    content_for_fields
  else
    default_content
  end
end

def content_for_fields

def content_for_fields
  content = content_block.details.deep_symbolize_keys.dig(*field_names)
  if content.blank?
    ContentBlockTools.logger.warn("Content not found for content block #{content_block.content_id} and fields #{field_names}")
    content_block.embed_code
  else
    content
  end
end

def default_content

def default_content
  content_block.title
end

def field_names

def field_names
  embed_code_match = ContentBlockReference::EMBED_REGEX.match(content_block.embed_code)
  if embed_code_match.present?
    all_fields = embed_code_match[4]&.reverse&.chomp("/")&.reverse
    all_fields&.split("/")&.map(&:to_sym)
  end
end

def initialize(content_block)

Returns:
  • ({ContentBlockTools::Presenters::BasePresenter}) -

Parameters:
  • content_block ({ContentBlockTools::ContentBlock}) -- A content block object
def initialize(content_block)
  @content_block = content_block
end

def render

Returns:
  • (string) - A HTML representation of the content block
def render
  content_tag(
    BASE_TAG_TYPE,
    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