Class: Nacelle::AfterFilter
- Inherits:
-
Struct
- Object
- Struct
- Nacelle::AfterFilter
- Defined in:
- lib/nacelle/after_filter.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller
7 8 9 |
# File 'lib/nacelle/after_filter.rb', line 7 def controller @controller end |
Class Method Details
.after(controller) ⇒ Object
8 9 10 11 12 |
# File 'lib/nacelle/after_filter.rb', line 8 def self.after controller if controller.content_type&.include?("text/html") new(controller).call end end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nacelle/after_filter.rb', line 14 def call cells = cells controller.response.body return if cells.empty? controller.response.body = controller.response.body.gsub(/(#{cells.keys.join('|')})/) do |tag| name, action, attrs = cells[tag] action = action.to_sym attrs = HashWithIndifferentAccess.new(attrs) cell = "#{name.camelize}Cell".constantize.new_with_controller(controller) attrs.delete "class" # ignore styling class if cell.class.action_methods.include?(action) cell.action = action if cell.method(action).arity.zero? && attrs.empty? cell.send(action) else cell.send(action, attrs) end else "<strong>Cell “#{name.capitalize} #{action}” not found!</strong>" end end end |