2011-05-27 22:14:45 +00:00
|
|
|
require 'rack/utils'
|
|
|
|
|
|
|
|
module Locomotive
|
|
|
|
module Hosting
|
|
|
|
module Bushido
|
|
|
|
class Middleware
|
|
|
|
|
|
|
|
include Rack::Utils
|
|
|
|
|
|
|
|
def initialize(app, opts = {})
|
|
|
|
@app = app
|
2011-06-21 22:03:23 +00:00
|
|
|
@path_regexp = %r{^/admin/}
|
2011-05-27 22:14:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2011-06-21 22:03:23 +00:00
|
|
|
if env['PATH_INFO'] =~ @path_regexp
|
|
|
|
status, headers, response = @app.call(env)
|
|
|
|
|
|
|
|
content = ""
|
|
|
|
response.each { |part| content += part }
|
|
|
|
|
|
|
|
# enable chat
|
|
|
|
content.gsub!(/<\/head>/i, <<-STR
|
|
|
|
<script type="text/javascript">var _bushido_chat = true;</script>
|
|
|
|
</head>
|
|
|
|
STR
|
|
|
|
)
|
|
|
|
|
|
|
|
headers['content-length'] = bytesize(content).to_s
|
|
|
|
|
|
|
|
[status, headers, [content]]
|
|
|
|
else
|
|
|
|
@app.call(env)
|
|
|
|
end
|
2011-05-27 22:14:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-06-21 22:03:23 +00:00
|
|
|
end
|