Sha256: eb1000c4ffb6b5d214717d6ed5067a0dc230d00ca5a7eee15d53e3b0d24ffe40

Contents?: true

Size: 964 Bytes

Versions: 1

Compression:

Stored size: 964 Bytes

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 Occams::Content::Tag::Template < Occams::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 = Occams.config.allowed_templates
    if whitelist.is_a?(Array)
      whitelist.member?(@path) ? content : ""
    else
      content
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
occams-1.0.1 lib/occams/content/tags/template.rb