Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
BPM Rack Middleware
  • Loading branch information
wagenet committed Sep 15, 2011
1 parent f7a8bd7 commit fd31664
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/bpm.rb
Expand Up @@ -12,6 +12,7 @@ module BPM
autoload :Remote, 'bpm/remote'
autoload :Repository, 'bpm/repository'
autoload :Project, 'bpm/project'
autoload :Rack, 'bpm/rack'
autoload :Server, 'bpm/server'
autoload :Pipeline, 'bpm/pipeline'
autoload :DirectiveProcessor, 'bpm/pipeline/directive_processor'
Expand Down
2 changes: 1 addition & 1 deletion lib/bpm/pipeline/generated_asset.rb
Expand Up @@ -118,7 +118,7 @@ def minify(hash)

hash = environment.cache_hash("#{pathname}:minify", id) do
data = minify_body hash['source']
{ 'length' => Rack::Utils.bytesize(data),
{ 'length' => ::Rack::Utils.bytesize(data),
'digest' => environment.digest.update(data).hexdigest,
'source' => data }
end
Expand Down
17 changes: 17 additions & 0 deletions lib/bpm/rack.rb
@@ -0,0 +1,17 @@
module BPM
class Rack
def initialize(app, project, mode=:debug)
@app = app
@pipeline = BPM::Pipeline.new(project, mode, true)
end

def call(env)
if env['PATH_INFO'] =~ %r{^/assets/(.+)$}
env['PATH_INFO'] = $1
@pipeline.call(env)
else
@app.call(env)
end
end
end
end
13 changes: 4 additions & 9 deletions lib/bpm/server.rb
Expand Up @@ -4,7 +4,7 @@

module BPM

class Server < Rack::Server
class Server < ::Rack::Server

def initialize(project, options={})
options = default_options.merge(options)
Expand All @@ -31,14 +31,9 @@ def app
cur_project = @project
cur_mode = @mode

@app ||= Rack::Builder.new do
map '/assets' do
run BPM::Pipeline.new cur_project, cur_mode, true
end

map '/' do
run Rack::Directory.new cur_project.root_path
end
@app ||= ::Rack::Builder.new do
use BPM::Rack, cur_project, cur_mode
run ::Rack::Directory.new cur_project.root_path
end.to_app
end
end
Expand Down

0 comments on commit fd31664

Please sign in to comment.