Class: StyleCapsule::HeadInjectionMiddleware
- Inherits:
-
Object
- Object
- StyleCapsule::HeadInjectionMiddleware
- Defined in:
- lib/style_capsule/head_injection_middleware.rb,
sig/style_capsule.rbs
Overview
Injects stylesheets registered during body rendering into <head> on the same request.
Layouts call stylesheet_registry_tags before the body, so register_stylesheet in
components runs too late for that call. This middleware appends pending link/style tags
immediately before </head> once the full HTML response is available.
Constant Summary collapse
- HTML_CONTENT_TYPE =
%r{\Atext/html}i- SUCCESS_STATUS =
(200..299)
Instance Method Summary collapse
- #call(env) ⇒ [Integer, Hash[String, String], untyped]
-
#initialize(app) ⇒ HeadInjectionMiddleware
constructor
A new instance of HeadInjectionMiddleware.
Constructor Details
#initialize(app) ⇒ HeadInjectionMiddleware
Returns a new instance of HeadInjectionMiddleware.
13 14 15 |
# File 'lib/style_capsule/head_injection_middleware.rb', line 13 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ [Integer, Hash[String, String], untyped]
17 18 19 20 21 22 23 |
# File 'lib/style_capsule/head_injection_middleware.rb', line 17 def call(env) status, headers, response = @app.call(env) return [status, headers, response] unless inject_response?(status, headers, response) return [status, headers, response] unless StylesheetRegistry.pending_head_stylesheets? maybe_inject_head_styles(status, headers, response, env) end |