class ComfortableMexicanSofa::Content::Tag::Helper
Tag for injecting view helpers. Example tag:
{{cms:helper method_name, param_a, param_b, foo: bar}}
This expands into something like this:
<%= method_name("param_a", "param_b", "foo" => "bar") %>
Whitelist is can be used to control what helpers are available. By default there's a blacklist of methods that should not be called.
Constants
- BLACKLIST
Attributes
method_name[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/helper.rb, line 16 def initialize(context:, params: [], source: nil) super @method_name = params.shift unless @method_name.present? raise Error, "Missing method name for helper 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/helper.rb, line 26 def allow_erb? true end
content()
click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/helper.rb, line 30 def content helper_params = params.map do |p| case p when Hash format("%<arg>s", arg: p) else format("%<arg>p", arg: p) end end.join(",") "<%= #{method_name}(#{helper_params}) %>" end
render()
click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/helper.rb, line 42 def render whitelist = ComfortableMexicanSofa.config.allowed_helpers if whitelist.is_a?(Array) content if whitelist.map!(&:to_s).member?(method_name) else content unless BLACKLIST.member?(method_name) end end