Class: Nacelle::AfterFilter

Inherits:
Struct
  • Object
show all
Defined in:
lib/nacelle/after_filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controllerObject

Returns the value of attribute controller

Returns:

  • (Object)

    the current value of 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

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nacelle/after_filter.rb', line 14

def call
  cells = cells controller.response.body

  controller.response.body.gsub!(/(#{cells.keys.join('|')})/) do |tag|
    name, state, attrs = cells[tag]
    attrs = HashWithIndifferentAccess.new(attrs)
    cell = "#{name.camelize}Cell".constantize.new_with_controller(controller)
    args = [state]
    attrs.delete "class" # ignore styling class
    args << attrs unless attrs.empty?
    begin
      cell.render_state *args
    rescue AbstractController::ActionNotFound
      "<strong>Cell “#{name.capitalize} #{state}” not found!</strong>"
    end
  end unless cells.empty?
end