class OpallaMiddleware
Public Class Methods
new(app)
click to toggle source
# File lib/opalla/middleware.rb, line 2 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/opalla/middleware.rb, line 6 def call(env) s, h, r = @app.call(env) return [s, h, r] unless h['Content-Type'] =~ %r{text/html} html = r.body.gsub("<body>", "<body>#{js_routes}") [s, h, [html]] end
js_routes()
click to toggle source
# File lib/opalla/middleware.rb, line 13 def js_routes <<~JS <script> window.opalla_data = #{ Opalla::Util.data_dump.to_json } </script> JS end