more hacking
This commit is contained in:
parent
860e411435
commit
95fb0e9702
@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
|
|||||||
gem.add_development_dependency 'ejs'
|
gem.add_development_dependency 'ejs'
|
||||||
|
|
||||||
gem.add_runtime_dependency 'rack'
|
gem.add_runtime_dependency 'rack'
|
||||||
|
gem.add_runtime_dependency 'thin'
|
||||||
gem.add_runtime_dependency 'sprockets'
|
gem.add_runtime_dependency 'sprockets'
|
||||||
gem.add_runtime_dependency 'coffee-script'
|
gem.add_runtime_dependency 'coffee-script'
|
||||||
gem.add_runtime_dependency 'sprockets-vendor_gems'
|
gem.add_runtime_dependency 'sprockets-vendor_gems'
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require 'rack'
|
require 'rack'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'socket'
|
require 'socket'
|
||||||
|
require 'rack/builder'
|
||||||
|
|
||||||
module Flowerbox
|
module Flowerbox
|
||||||
module Delivery
|
module Delivery
|
||||||
@ -14,12 +15,18 @@ module Flowerbox
|
|||||||
def start
|
def start
|
||||||
@server_thread = Thread.new do
|
@server_thread = Thread.new do
|
||||||
server_options = { :Port => port, :Host => interface }
|
server_options = { :Port => port, :Host => interface }
|
||||||
if !options[:logging]
|
|
||||||
server_options[:AccessLog] = [ nil, nil ]
|
app = options[:app]
|
||||||
server_options[:Logger] = Logger.new('/dev/null')
|
|
||||||
|
if options[:logging]
|
||||||
|
real_app = app
|
||||||
|
app = ::Rack::Builder.new do
|
||||||
|
use ::Rack::CommonLogger, STDOUT
|
||||||
|
run real_app
|
||||||
|
end
|
||||||
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 }
|
trap('QUIT') { server.stop }
|
||||||
|
|
||||||
Thread.current[:server] = server
|
Thread.current[:server] = server
|
||||||
@ -35,7 +42,7 @@ module Flowerbox
|
|||||||
|
|
||||||
def stop
|
def stop
|
||||||
if @server_thread
|
if @server_thread
|
||||||
@server_thread[:server].shutdown
|
@server_thread[:server].stop
|
||||||
|
|
||||||
wait_for_server_to_stop
|
wait_for_server_to_stop
|
||||||
end
|
end
|
||||||
@ -68,6 +75,14 @@ module Flowerbox
|
|||||||
@port
|
@port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def address
|
||||||
|
"http://#{interface}:#{port}/"
|
||||||
|
end
|
||||||
|
|
||||||
|
def alive?
|
||||||
|
@server_thread.alive?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def wait_for_server_to_start
|
def wait_for_server_to_start
|
||||||
while true do
|
while true do
|
||||||
@ -84,7 +99,7 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_server_to_stop
|
def wait_for_server_to_stop
|
||||||
while true do
|
while alive? do
|
||||||
begin
|
begin
|
||||||
connect_interface = '127.0.0.1' if interface == '0.0.0.0'
|
connect_interface = '127.0.0.1' if interface == '0.0.0.0'
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ module Flowerbox::Delivery
|
|||||||
|
|
||||||
attr_reader :files, :options
|
attr_reader :files, :options
|
||||||
|
|
||||||
def_delegators :environment, :append_path, :register_engine
|
def_delegators :environment, :append_path, :register_engine, :[]
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = options
|
@options = options
|
||||||
@ -25,16 +25,20 @@ module Flowerbox::Delivery
|
|||||||
environment.find_asset(asset).to_a.collect(&:pathname)
|
environment.find_asset(asset).to_a.collect(&:pathname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expire_index!
|
||||||
|
@environment.send(:expire_index!)
|
||||||
|
end
|
||||||
|
|
||||||
def environment
|
def environment
|
||||||
return @environment if @environment
|
return @environment if @environment
|
||||||
|
|
||||||
@environment = Sprockets::EnvironmentWithVendoredGems.new
|
@environment = Sprockets::EnvironmentWithVendoredGems.new
|
||||||
@environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
@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.unregister_bundle_processor('text/css', Sprockets::CharsetNormalizer)
|
||||||
@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
|
#@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
|
||||||
@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
|
#@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
|
||||||
@environment.register_engine('.jst', Flowerbox::Delivery::Tilt::JSTTemplate)
|
#@environment.register_engine('.jst', Flowerbox::Delivery::Tilt::JSTTemplate)
|
||||||
|
|
||||||
options[:asset_paths].each { |path| append_path(path) }
|
options[:asset_paths].each { |path| append_path(path) }
|
||||||
|
|
||||||
|
@ -6,5 +6,6 @@ class Flowerbox::Delivery::Tilt::CSSTemplate < Tilt::Template
|
|||||||
EXTENSION = "css"
|
EXTENSION = "css"
|
||||||
|
|
||||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,5 +6,9 @@ class Flowerbox::Delivery::Tilt::JSTemplate < Tilt::Template
|
|||||||
EXTENSION = "js"
|
EXTENSION = "js"
|
||||||
|
|
||||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
handle_evaluate
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,9 +6,15 @@ class Flowerbox::Delivery::Tilt::JSTTemplate < Sprockets::JstProcessor
|
|||||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
def evaluate(scope, locals, &block)
|
||||||
super
|
@data = super
|
||||||
|
|
||||||
|
p @data
|
||||||
|
|
||||||
handle_evaluate
|
handle_evaluate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_to_save
|
||||||
|
@data || data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,21 +12,25 @@ module Flowerbox::Delivery::Tilt::TemplateThatSaves
|
|||||||
|
|
||||||
def save
|
def save
|
||||||
FileUtils.mkdir_p File.dirname(temp_file)
|
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
|
temp_file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_to_save
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
def temp_file
|
def temp_file
|
||||||
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{extension})(.*)$}, '\1'))
|
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{extension})(.*)$}, '\1'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
|
||||||
handle_evaluate
|
|
||||||
end
|
|
||||||
|
|
||||||
def extension
|
def extension
|
||||||
self.class::EXTENSION
|
self.class::EXTENSION
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
handle_evaluate
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module Flowerbox::Delivery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
collect(&:body)
|
collect(&:logical_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Loading…
Reference in New Issue
Block a user