class ComfortableMexicanSofa::Content::Tag::Template

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.

Attributes

path[R]

Public Class Methods

new(context:, params: [], source: nil) click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/template.rb, line 13
def initialize(context:, params: [], source: nil)
  super
  @path = params[0]

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

Public Instance Methods

allow_erb?() click to toggle source

we output erb into rest of the content

# File lib/comfortable_mexican_sofa/content/tags/template.rb, line 23
def allow_erb?
  true
end
content() click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/template.rb, line 27
def content
  format("<%%= render template: %<path>p %%>", path: path)
end
render() click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/template.rb, line 31
def render
  whitelist = ComfortableMexicanSofa.config.allowed_templates
  if whitelist.is_a?(Array)
    whitelist.member?(@path) ? content : ""
  else
    content
  end
end