Class: Occams::Content::Tag::Partial
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Partial
- Defined in:
- lib/occams/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 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) ⇒ Partial
constructor
A new instance of Partial.
- #render ⇒ Object
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Partial
Returns a new instance of Partial.
12 13 14 15 16 17 18 19 20 |
# File 'lib/occams/content/tags/partial.rb', line 12 def initialize(context:, params: [], source: nil) super @locals = params. @path = params[0] return if @path.present? raise Error, 'Missing path for partial tag' end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
10 11 12 |
# File 'lib/occams/content/tags/partial.rb', line 10 def locals @locals end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/occams/content/tags/partial.rb', line 10 def path @path end |
Instance Method Details
#allow_erb? ⇒ Boolean
we output erb into rest of the content
23 24 25 |
# File 'lib/occams/content/tags/partial.rb', line 23 def allow_erb? true end |
#content ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/occams/content/tags/partial.rb', line 27 def content format( '<%%= render partial: %<path>p, locals: %<locals>s %%>', path: @path, locals: @locals ) end |
#render ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/occams/content/tags/partial.rb', line 35 def render whitelist = Occams.config.allowed_partials if whitelist.is_a?(Array) whitelist.member?(@path) ? content : '' else content end end |