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-20 23:27:13 +00:00
|
|
|
@path_regexp = %r{^/admin/}
|
2011-05-27 22:14:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2011-06-20 23:27:13 +00:00
|
|
|
if env['PATH_INFO'] =~ @path_regexp
|
|
|
|
status, headers, response = @app.call(env)
|
|
|
|
|
|
|
|
content = ""
|
|
|
|
response.each { |part| content += part }
|
|
|
|
|
2011-06-21 18:38:03 +00:00
|
|
|
# enable chat
|
|
|
|
content.gsub!(/<\/head>/i, <<-STR
|
|
|
|
<script type="text/javascript">var _bushido_chat = true;</script>
|
|
|
|
</head>
|
2011-06-20 23:27:13 +00:00
|
|
|
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
|
|
|
|
end
|