class ComfortableMexicanSofa::Content::Tag::Partial
Tag for injecting partials. Example tag:
{{cms:partial path/to/partial, foo: bar, 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.
Attributes
locals[R]
path[R]
Public Class Methods
new(context:, params: [], source: nil)
click to toggle source
Calls superclass method
ComfortableMexicanSofa::Content::Tag::new
# File lib/comfortable_mexican_sofa/content/tags/partial.rb, line 13 def initialize(context:, params: [], source: nil) super @locals = params.extract_options! @path = params[0] unless @path.present? raise Error, "Missing path for partial tag" end end
Public Instance Methods
allow_erb?()
click to toggle source
we output erb into rest of the content
# File lib/comfortable_mexican_sofa/content/tags/partial.rb, line 24 def allow_erb? true end
content()
click to toggle source
# 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()
click to toggle source
# 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