Class: Occams::Content::Tag::Template

Inherits:
Occams::Content::Tag show all
Defined in:
lib/occams/content/tags/template.rb

Overview

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.

Instance Attribute Summary collapse

Attributes inherited from Occams::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods inherited from Occams::Content::Tag

#nodes

Constructor Details

#initialize(context:, params: [], source: nil) ⇒ Template

Returns a new instance of Template.

Raises:



12
13
14
15
16
17
18
19
# File 'lib/occams/content/tags/template.rb', line 12

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

  return if @path.present?

  raise Error, 'Missing template path for template tag'
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/occams/content/tags/template.rb', line 10

def path
  @path
end

Instance Method Details

#allow_erb?Boolean

we output erb into rest of the content

Returns:

  • (Boolean)


22
23
24
# File 'lib/occams/content/tags/template.rb', line 22

def allow_erb?
  true
end

#contentObject



26
27
28
# File 'lib/occams/content/tags/template.rb', line 26

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

#renderObject



30
31
32
33
34
35
36
37
# File 'lib/occams/content/tags/template.rb', line 30

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