diff --git a/flowerbox.gemspec b/flowerbox.gemspec index 2423b1b..dcceada 100644 --- a/flowerbox.gemspec +++ b/flowerbox.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'jasmine-core' gem.add_dependency 'thor' gem.add_dependency 'selenium-webdriver' - gem.add_dependency 'sinatra' gem.add_dependency 'rainbow' gem.add_dependency 'sprockets' gem.add_dependency 'sprockets-vendor_gems' diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb index 1b33fb4..37bc492 100644 --- a/lib/flowerbox/rack.rb +++ b/lib/flowerbox/rack.rb @@ -1,34 +1,20 @@ -require 'sinatra' -require 'cgi' - module Flowerbox - class Rack < Sinatra::Base - class << self - attr_accessor :runner, :sprockets + class Rack + attr_accessor :runner, :sprockets + + def initialize(runner, sprockets) + @runner, @sprockets = runner, sprockets end - def sprockets - self.class.sprockets + def call(env) + dup._call(env) end - def runner - self.class.runner - end - - get %r{^/__F__/(.*)$} do |file| - asset = sprockets.asset_for(file, :bundle => false) - - halt(404) if !asset - - content_type asset.content_type - asset.body - end - - get '/' do - begin - runner.template - rescue Flowerbox::Runner::Base::RunnerDiedError => e - e.message + def _call(env) + if sprockets_file = env['PATH_INFO'][%r{/__F__(.*)$}, 1] + sprockets.call(env.merge('PATH_INFO' => sprockets_file)) + else + [ 200, { 'Content-type' => 'text/html' }, [ runner.template ] ] end end end diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index e39d763..61d0275 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -131,14 +131,15 @@ module Flowerbox def server require 'flowerbox/rack' - Flowerbox::Rack.runner = self - Flowerbox::Rack.sprockets = @sprockets - - return Flowerbox.server if Flowerbox.server + if Flowerbox.server + Flowerbox.server.app.runner = self + Flowerbox.server.app.sprockets = sprockets + return Flowerbox.server + end require 'flowerbox/server' - server_options = { :app => Flowerbox::Rack } + server_options = { :app => Flowerbox::Rack.new(self, sprockets) } server_options[:logging] = true if options[:verbose_server] server_options[:port] = Flowerbox.port diff --git a/lib/flowerbox/sprockets_handler.rb b/lib/flowerbox/sprockets_handler.rb index 82b5108..7f7f613 100644 --- a/lib/flowerbox/sprockets_handler.rb +++ b/lib/flowerbox/sprockets_handler.rb @@ -10,7 +10,7 @@ module Flowerbox attr_reader :files, :options - def_delegators :environment, :append_path, :register_engine, :[] + def_delegators :environment, :append_path, :register_engine, :[], :call def self.gem_asset_paths @gem_asset_paths ||= Sprockets.find_gem_vendor_paths @@ -29,7 +29,7 @@ module Flowerbox end def assets_for(asset) - environment.find_asset(asset, :bundle => false).to_a + environment.find_asset(asset, :bundle => true).to_a end def expire_index!