Sha256: b1042cf8472b6c46fa8d39119f4aacd668d86910ce8693518327ff9824a8d07b
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
#require 'rack/utils' module Bushido class Middleware include Rack::Utils def initialize(app, opts = {}) @app = app end def call(env) if Bushido::Platform.on_bushido? and Bushido::Bar.in_bar_display_path?(env) status, headers, response = @app.call(env) content = "" response.each { |part| content += part } # "claiming" bar + stats ? content.gsub!(/<\/body>/i, <<-STR <script type="text/javascript"> var _bushido_app = '#{Bushido::Platform.name}'; var _bushido_claimed = #{Bushido::Platform.claimed?.to_s}; var _bushido_metrics_token = '#{Bushido::Platform.metrics_token}'; (function() { var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true; bushido.src = '#{Bushido::Platform.bushido_js_source}?t=#{::Bushido::VERSION.gsub('.', '')}'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s); })(); </script> </body> STR ) headers['content-length'] = bytesize(content).to_s [status, headers, [content]] else @app.call(env) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bushido-0.0.36 | lib/bushido/middleware.rb |