Sha256: 4002b8547b28305790f922af3132539fc97d44dc0bf6a154bf1568e88406ffd9

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

# Tag for injecting template rendering. Example tag:
#   {{cms:template template/path}}
# This expands into something like this:
#   <%= render template: "template/path" %>
# Whitelist is can be used to control what templates are available.
#
class ComfortableMexicanSofa::Content::Tag::Template < ComfortableMexicanSofa::Content::Tag

  attr_reader :path

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

    unless @path.present?
      raise Error, "Missing template path for template tag"
    end
  end

  # we output erb into rest of the content
  def allow_erb?
    true
  end

  def content
    format("<%%= render template: %<path>p %%>", path: path)
  end

  def render
    whitelist = ComfortableMexicanSofa.config.allowed_templates
    if whitelist.is_a?(Array)
      whitelist.member?(@path) ? content : ""
    else
      content
    end
  end

end

ComfortableMexicanSofa::Content::Renderer.register_tag(
  :template, ComfortableMexicanSofa::Content::Tag::Template
)

Version data entries

14 entries across 14 versions & 6 rubygems

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