Class: ComfortableMexicanSofa::Content::Tag::Template
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::Template
- Defined in:
- lib/comfortable_mexican_sofa/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 ComfortableMexicanSofa::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 ComfortableMexicanSofa::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Template
Returns a new instance of Template.
13 14 15 16 17 18 19 20 |
# 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 |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/comfortable_mexican_sofa/content/tags/template.rb', line 11 def path @path end |
Instance Method Details
#allow_erb? ⇒ Boolean
we output erb into rest of the content
23 24 25 |
# File 'lib/comfortable_mexican_sofa/content/tags/template.rb', line 23 def allow_erb? true end |
#content ⇒ Object
27 28 29 |
# File 'lib/comfortable_mexican_sofa/content/tags/template.rb', line 27 def content format("<%%= render template: %<path>p %%>", path: path) end |
#render ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 |