Class: Occams::Content::Tag::Template
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Template
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
-
#allow_erb? ⇒ Boolean
we output erb into rest of the content.
- #content ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Template
Returns a new instance of Template.
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
#path ⇒ Object (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
22 23 24 |
# File 'lib/occams/content/tags/template.rb', line 22 def allow_erb? true end |
#content ⇒ Object
26 27 28 |
# File 'lib/occams/content/tags/template.rb', line 26 def content format('<%%= render template: %<path>p %%>', path: path) end |
#render ⇒ Object
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 |