Class: MissionControl::Jobs::Theme::Middleware
- Inherits:
-
Object
- Object
- MissionControl::Jobs::Theme::Middleware
- Defined in:
- lib/mission_control/jobs/theme/middleware.rb
Overview
Intercept HTML responses from the Mission Control Jobs engine and inject theme CSS and optional Prism.js syntax highlighting before </head>.
Only rewrites responses that match the engine mount path and have an text/html content type.
Constant Summary collapse
- THEME_CSS =
'<link rel="stylesheet" href="/mission_control/css/theme.min.css">'- PRISM_CSS =
'<link rel="stylesheet" href="/mission_control/css/prism.min.css">'- PRISM_JS =
'<script src="/mission_control/js/prism.min.js" data-manual></script>'- PRISM_INIT =
'<script src="/mission_control/js/prism-init.js"></script>'
Instance Method Summary collapse
-
#call(env) ⇒ Array(Integer, Hash, #each)
Process a Rack request, injecting theme assets into matching HTML responses.
-
#initialize(app, mount_path: RouteDiscovery::FALLBACK, syntax_highlighting: true) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, mount_path: RouteDiscovery::FALLBACK, syntax_highlighting: true) ⇒ Middleware
Returns a new instance of Middleware.
28 29 30 31 32 33 |
# File 'lib/mission_control/jobs/theme/middleware.rb', line 28 def initialize(app, mount_path: RouteDiscovery::FALLBACK, syntax_highlighting: true) @app = app @mount_path = mount_path @mount_path_prefix = "#{mount_path}/" @injection = build_injection(syntax_highlighting) end |
Instance Method Details
#call(env) ⇒ Array(Integer, Hash, #each)
Process a Rack request, injecting theme assets into matching HTML responses.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mission_control/jobs/theme/middleware.rb', line 39 def call(env) status, headers, response = @app.call(env) if inject_theme?(env, status, headers) body = +"" response.each { |part| body << part } response.close if response.respond_to?(:close) body = inject_assets(body) headers["content-length"] = body.bytesize.to_s if headers.key?("content-length") [status, headers, [body]] else [status, headers, response] end end |