get rid of the yellow banner in production

This commit is contained in:
did 2011-06-21 01:27:13 +02:00
parent fdfa36838b
commit 57ba3ba273
4 changed files with 18 additions and 30 deletions

View File

@ -47,8 +47,6 @@ group :test, :development do
gem 'ruby-debug19', :platforms => :mri_19
gem 'bushido_stub', :git => 'git://github.com/did/bushido_stub.git'
# :path => '../gems/bushido_stub'
# gem 'bushido'
end
group :production do

View File

@ -71,7 +71,7 @@ module Locomotive
def add_middleware
::Locomotive::Application.configure do |config|
config.middleware.use '::Locomotive::Hosting::Bushido::Middleware'
config.middleware.use ::Locomotive::Hosting::Bushido::Middleware
end
end

View File

@ -5,43 +5,33 @@ module Locomotive
module Bushido
class Middleware
# BUSHIDO_JS_URL = 'http://localhost:4567/javascripts/bushido.js'
BUSHIDO_JS_URL = 'http://bushi.do/api/bushido.js'
include Rack::Utils
def initialize(app, opts = {})
@app = app
@bushido_app_name = ENV['BUSHIDO_APP']
@bushido_metrics_token = ENV['BUSHIDO_METRICS_TOKEN']
@bushido_claimed = ::Locomotive.bushido_app_claimed?
@path_regexp = %r{^/admin/}
end
def call(env)
status, headers, response = @app.call(env)
if env['PATH_INFO'] =~ @path_regexp
status, headers, response = @app.call(env)
content = ""
response.each { |part| content += part }
content = ""
response.each { |part| content += part }
# "claiming" bar + stats ?
content.gsub!(/<\/body>/i, <<-STR
<script type="text/javascript">
var _bushido_app = '#{@bushido_app_name}';
var _bushido_claimed = #{@bushido_claimed.to_s};
var _bushido_metrics_token = '#{@bushido_metrics_token}';
(function() {
var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true;
bushido.src = '#{BUSHIDO_JS_URL}?#{::Bushido::VERSION.gsub('.', '')}';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s);
})();
</script>
</body>
STR
)
# "claiming" bar + stats ?
content.gsub!(/<\/body>/i, <<-STR
<script type="text/javascript">bushido.enableChat();</script>
</body>
STR
)
headers['content-length'] = bytesize(content).to_s
headers['content-length'] = bytesize(content).to_s
[status, headers, [content]]
[status, headers, [content]]
else
@app.call(env)
end
end
end