more hacking

This commit is contained in:
John Bintz 2012-03-14 13:07:28 -04:00
parent 860e411435
commit 95fb0e9702
8 changed files with 53 additions and 18 deletions

View File

@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'ejs'
gem.add_runtime_dependency 'rack'
gem.add_runtime_dependency 'thin'
gem.add_runtime_dependency 'sprockets'
gem.add_runtime_dependency 'coffee-script'
gem.add_runtime_dependency 'sprockets-vendor_gems'

View File

@ -1,6 +1,7 @@
require 'rack'
require 'net/http'
require 'socket'
require 'rack/builder'
module Flowerbox
module Delivery
@ -14,12 +15,18 @@ module Flowerbox
def start
@server_thread = Thread.new do
server_options = { :Port => port, :Host => interface }
if !options[:logging]
server_options[:AccessLog] = [ nil, nil ]
server_options[:Logger] = Logger.new('/dev/null')
app = options[:app]
if options[:logging]
real_app = app
app = ::Rack::Builder.new do
use ::Rack::CommonLogger, STDOUT
run real_app
end
end
::Rack::Handler::WEBrick.run(options[:app], server_options) do |server|
::Rack::Handler::Thin.run(app, server_options) do |server|
trap('QUIT') { server.stop }
Thread.current[:server] = server
@ -35,7 +42,7 @@ module Flowerbox
def stop
if @server_thread
@server_thread[:server].shutdown
@server_thread[:server].stop
wait_for_server_to_stop
end
@ -68,6 +75,14 @@ module Flowerbox
@port
end
def address
"http://#{interface}:#{port}/"
end
def alive?
@server_thread.alive?
end
private
def wait_for_server_to_start
while true do
@ -84,7 +99,7 @@ module Flowerbox
end
def wait_for_server_to_stop
while true do
while alive? do
begin
connect_interface = '127.0.0.1' if interface == '0.0.0.0'

View File

@ -9,7 +9,7 @@ module Flowerbox::Delivery
attr_reader :files, :options
def_delegators :environment, :append_path, :register_engine
def_delegators :environment, :append_path, :register_engine, :[]
def initialize(options)
@options = options
@ -25,16 +25,20 @@ module Flowerbox::Delivery
environment.find_asset(asset).to_a.collect(&:pathname)
end
def expire_index!
@environment.send(:expire_index!)
end
def environment
return @environment if @environment
@environment = Sprockets::EnvironmentWithVendoredGems.new
@environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
@environment.register_postprocessor('application/javascript', Flowerbox::Delivery::Tilt::EnsureSavedFile)
#@environment.register_postprocessor('application/javascript', Flowerbox::Delivery::Tilt::EnsureSavedFile)
@environment.unregister_bundle_processor('text/css', Sprockets::CharsetNormalizer)
@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
@environment.register_engine('.jst', Flowerbox::Delivery::Tilt::JSTTemplate)
#@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
#@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
#@environment.register_engine('.jst', Flowerbox::Delivery::Tilt::JSTTemplate)
options[:asset_paths].each { |path| append_path(path) }

View File

@ -6,5 +6,6 @@ class Flowerbox::Delivery::Tilt::CSSTemplate < Tilt::Template
EXTENSION = "css"
include Flowerbox::Delivery::Tilt::TemplateThatSaves
end

View File

@ -6,5 +6,9 @@ class Flowerbox::Delivery::Tilt::JSTemplate < Tilt::Template
EXTENSION = "js"
include Flowerbox::Delivery::Tilt::TemplateThatSaves
def evaluate(scope, locals, &block)
handle_evaluate
end
end

View File

@ -6,9 +6,15 @@ class Flowerbox::Delivery::Tilt::JSTTemplate < Sprockets::JstProcessor
include Flowerbox::Delivery::Tilt::TemplateThatSaves
def evaluate(scope, locals, &block)
super
@data = super
p @data
handle_evaluate
end
def data_to_save
@data || data
end
end

View File

@ -12,21 +12,25 @@ module Flowerbox::Delivery::Tilt::TemplateThatSaves
def save
FileUtils.mkdir_p File.dirname(temp_file)
File.open(temp_file, 'wb') { |fh| fh.print data }
File.open(temp_file, 'wb') { |fh| fh.print data_to_save }
temp_file
end
def data_to_save
data
end
def temp_file
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{extension})(.*)$}, '\1'))
end
def evaluate(scope, locals, &block)
handle_evaluate
end
def extension
self.class::EXTENSION
end
def evaluate(scope, locals, &block)
handle_evaluate
end
end

View File

@ -5,7 +5,7 @@ module Flowerbox::Delivery
end
def to_json
collect(&:body)
collect(&:logical_path)
end
private