Class: Occams::Content::Tag::Helper
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Helper
- Defined in:
- lib/occams/content/tags/helper.rb
Overview
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.
Constant Summary collapse
- BLACKLIST =
%w[eval class_eval instance_eval render].freeze
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
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) ⇒ Helper
constructor
A new instance of Helper.
- #render ⇒ Object
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Helper
Returns a new instance of Helper.
15 16 17 18 19 20 21 22 |
# File 'lib/occams/content/tags/helper.rb', line 15 def initialize(context:, params: [], source: nil) super @method_name = params.shift return if @method_name.present? raise Error, 'Missing method name for helper tag' end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
13 14 15 |
# File 'lib/occams/content/tags/helper.rb', line 13 def method_name @method_name end |
Instance Method Details
#allow_erb? ⇒ Boolean
we output erb into rest of the content
25 26 27 |
# File 'lib/occams/content/tags/helper.rb', line 25 def allow_erb? true end |
#content ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/occams/content/tags/helper.rb', line 29 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 |