Class: Spree::ThemeSupport::HookModifier
- Inherits:
-
Object
- Object
- Spree::ThemeSupport::HookModifier
- Defined in:
- lib/spree_core/theme_support/hook_modifier.rb
Overview
A hook modifier is created for each usage of ‘insert_before’,‘replace’ etc. This stores how the original contents of the hook should be modified and does the work of altering the hooks content appropriately
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#hook_name ⇒ Object
Returns the value of attribute hook_name.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
Instance Method Summary collapse
- #apply_to(content, context, locals = {}) ⇒ Object
-
#initialize(hook_name, action, renderer = nil) ⇒ HookModifier
constructor
A new instance of HookModifier.
Constructor Details
#initialize(hook_name, action, renderer = nil) ⇒ HookModifier
Returns a new instance of HookModifier.
12 13 14 15 16 |
# File 'lib/spree_core/theme_support/hook_modifier.rb', line 12 def initialize(hook_name, action, renderer = nil) @hook_name = hook_name @action = action @renderer = renderer end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
9 10 11 |
# File 'lib/spree_core/theme_support/hook_modifier.rb', line 9 def action @action end |
#hook_name ⇒ Object
Returns the value of attribute hook_name.
8 9 10 |
# File 'lib/spree_core/theme_support/hook_modifier.rb', line 8 def hook_name @hook_name end |
#renderer ⇒ Object
Returns the value of attribute renderer.
10 11 12 |
# File 'lib/spree_core/theme_support/hook_modifier.rb', line 10 def renderer @renderer end |
Instance Method Details
#apply_to(content, context, locals = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spree_core/theme_support/hook_modifier.rb', line 18 def apply_to(content, context, locals = {}) return '' if renderer.nil? case action when :insert_before "#{renderer.call(context, locals)}#{content}".html_safe when :insert_after "#{content}#{renderer.call(context, locals)}".html_safe when :replace renderer.call(context, locals).to_s.html_safe else '' end end |