Sha256: 1658134c2ae2f609e51996bba6095d76e67ffad25c0032934980588ab97d2171

Contents?: true

Size: 984 Bytes

Versions: 6

Compression:

Stored size: 984 Bytes

Contents

# 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_string)
    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
    "<%= render template: \"#{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

6 entries across 6 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-2.0.8 lib/comfortable_mexican_sofa/content/tags/template.rb
comfortable_mexican_sofa-2.0.7 lib/comfortable_mexican_sofa/content/tags/template.rb
comfortable_mexican_sofa-2.0.6 lib/comfortable_mexican_sofa/content/tags/template.rb
comfortable_mexican_sofa-2.0.5 lib/comfortable_mexican_sofa/content/tags/template.rb
comfortable_mexican_sofa-2.0.4 lib/comfortable_mexican_sofa/content/tags/template.rb
comfortable_mexican_sofa-2.0.3 lib/comfortable_mexican_sofa/content/tags/template.rb