Sha256: 013d4c95ccb8a5f85b73c07946b24beceb4b608eb39b2b1f817269982243574c

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

class ComfortableMediaSurfer::Content::Tag
  class Error < StandardError; end

  # @type [Comfy::Cms::WithFragments]
  attr_reader :context

  # @type [Array<String, {String => String}>] params
  attr_reader :params

  # @type [String, nil] source
  attr_reader :source

  # @param [Comfy::Cms::WithFragments] context
  # @param [Array<String, {String => String}>] params
  # @param [String, nil] source
  def initialize(context:, params: [], source: nil)
    @context  = context
    @params   = params
    @source   = source
  end

  # Making sure we don't leak erb from tags by accident.
  # Tag classes can override this, like partials/helpers tags.
  def allow_erb?
    ComfortableMediaSurfer.config.allow_erb
  end

  # Normally it's a {(String)}. However, if tag content has tags,
  # we need to expand them and that produces potentially more stuff.
  # @return [Array<String, ComfortableMediaSurfer::Content::Tag>]
  def nodes
    template  = ComfortableMediaSurfer::Content::Renderer.new(@context)
    tokens    = template.tokenize(content)
    template.nodes(tokens)
  end

  # @return [String]
  def content
    raise Error, 'This is a base class. It holds no content'
  end

  # @return [String]
  def render
    content
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfortable_media_surfer-3.1.1 lib/comfortable_media_surfer/content/tag.rb
comfortable_media_surfer-3.1.0 lib/comfortable_media_surfer/content/tag.rb
comfortable_media_surfer-3.0.0 lib/comfortable_media_surfer/content/tag.rb