Class: ComfortableMexicanSofa::Content::Tag::Partial
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::Partial
- Defined in:
- lib/comfortable_mexican_sofa/content/tags/partial.rb
Overview
Tag for injecting partials. Example tag:
{{cms:partial path/to/partial, foo: , zip: zoop}}
This expands into a familiar:
<%= render partial: "path/to/partial", locals: {foo: bar, zip: zoop} %>
Whitelist is can be used to control what partials are renderable.
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#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) ⇒ Partial
constructor
A new instance of Partial.
- #render ⇒ Object
Methods inherited from ComfortableMexicanSofa::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Partial
Returns a new instance of Partial.
13 14 15 16 17 18 19 20 21 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 13 def initialize(context:, params: [], source: nil) super @locals = params. @path = params[0] unless @path.present? raise Error, "Missing path for partial tag" end end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
11 12 13 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 11 def locals @locals end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 11 def path @path end |
Instance Method Details
#allow_erb? ⇒ Boolean
we output erb into rest of the content
24 25 26 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 24 def allow_erb? true end |
#content ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 28 def content format( "<%%= render partial: %<path>p, locals: %<locals>s %%>", path: @path, locals: @locals ) end |
#render ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/comfortable_mexican_sofa/content/tags/partial.rb', line 36 def render whitelist = ComfortableMexicanSofa.config.allowed_partials if whitelist.is_a?(Array) whitelist.member?(@path) ? content : "" else content end end |