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 'ruby-debug19', :platforms => :mri_19
gem 'bushido_stub', :git => 'git://github.com/did/bushido_stub.git' gem 'bushido_stub', :git => 'git://github.com/did/bushido_stub.git'
# :path => '../gems/bushido_stub'
# gem 'bushido'
end end
group :production do group :production do

View File

@ -13,7 +13,7 @@
#submenu #submenu
%ul %ul
= yield :submenu = yield :submenu
- if content_for? :actions - if content_for? :actions
.action .action
= yield :actions = yield :actions

View File

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

View File

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