Sha256: d68dd5d322a1575d16bb3693ca6fe62a17dc7ee48de38f2c37e4a8bd27a10c21

Contents?: true

Size: 902 Bytes

Versions: 17

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

# Tag for reusable snippets within context's site scope. Looks like this:
#   {{cms:snippet identifier}}
# Snippets may have more tags in them like fragments, so they may be expanded too.
#
class ComfortableMexicanSofa::Content::Tag::Snippet < ComfortableMexicanSofa::Content::Tag

  attr_reader :identifier

  def initialize(context:, params: [], source: nil)
    super
    @identifier = params[0]

    unless @identifier.present?
      raise Error, "Missing identifier for snippet tag"
    end
  end

  def content
    snippet.content
  end

  # Grabbing or initializing Comfy::Cms::Snippet object
  def snippet
    context.site.snippets.detect { |s| s.identifier == identifier } ||
      context.site.snippets.build(identifier: identifier)
  end

end

ComfortableMexicanSofa::Content::Renderer.register_tag(
  :snippet, ComfortableMexicanSofa::Content::Tag::Snippet
)

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 lib/comfortable_mexican_sofa/content/tags/snippet.rb
PixelForce_ETS-0.0.2 lib/comfortable_mexican_sofa/content/tags/snippet.rb
PixelForce_ETS-0.0.1 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest2-0.0.4 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest2-0.0.3 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest2-0.0.2 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest2-0.0.1 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest-0.0.1 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcyEtsTest-2.2.19 lib/comfortable_mexican_sofa/content/tags/snippet.rb
ComfortableMexicanSofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/snippet.rb
kcy1-1.0 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.17 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.16 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.15 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.14 lib/comfortable_mexican_sofa/content/tags/snippet.rb
comfortable_mexican_sofa-2.0.13 lib/comfortable_mexican_sofa/content/tags/snippet.rb