Class: HocusPocus::Middleware
- Inherits:
-
Object
- Object
- HocusPocus::Middleware
- Includes:
- MiddlewareUtil
- Defined in:
- lib/hocus_pocus/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from MiddlewareUtil
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 |
# File 'lib/hocus_pocus/middleware.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hocus_pocus/middleware.rb', line 11 def call(env) status, headers, body = @app.call env if headers && headers['Content-Type']&.include?('text/html') && (env['REQUEST_PATH'] !~ %r[^/*hocus_pocus/]) case body when ActionDispatch::Response, ActionDispatch::Response::RackBody body = body.body when Array body = body[0] end body.sub!(/<\/body>/i) { %Q[<div id="#{HocusPocus::CONTAINER}" style="position:absolute; top:0; right: 0;"><link href="/assets/recorder.css" media="all" rel="stylesheet" type="text/css"></div>#{$~}] } [status, headers, [body]] else [status, headers, body] end end |