fix cache_buster (include ancient bug
This commit is contained in:
parent
186651c5b5
commit
931253469d
6 changed files with 96 additions and 83 deletions
|
@ -23,4 +23,4 @@ Feature: Generate mtime-based query string for busting browser caches
|
||||||
Given "cache_buster" feature is "enabled"
|
Given "cache_buster" feature is "enabled"
|
||||||
And the Server is running at "test-app"
|
And the Server is running at "test-app"
|
||||||
When I go to "/cache-buster.html"
|
When I go to "/cache-buster.html"
|
||||||
Then I should not see "?"
|
Then I should see "?"
|
|
@ -27,7 +27,8 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_rack_app(&block)
|
def to_rack_app(&block)
|
||||||
app.run inst(&block)
|
inner_app = inst(&block)
|
||||||
|
app.map("/") { run inner_app }
|
||||||
app
|
app
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def map(map, &block)
|
def map(map, &block)
|
||||||
# app.map(map, &block)
|
app.map(map, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def helpers(*extensions, &block)
|
def helpers(*extensions, &block)
|
||||||
|
@ -61,6 +62,8 @@ class Middleman::Base
|
||||||
@defaults[key] = value
|
@defaults[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def asset_stamp; false; end
|
||||||
|
|
||||||
def before_processing(name=:unnamed, idx=-1, &block)
|
def before_processing(name=:unnamed, idx=-1, &block)
|
||||||
@before_processes ||= []
|
@before_processes ||= []
|
||||||
@before_processes.insert(idx, [name, block])
|
@before_processes.insert(idx, [name, block])
|
||||||
|
@ -312,6 +315,10 @@ public
|
||||||
raw_templates_cache[path]
|
raw_templates_cache[path]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def map(map, &block)
|
||||||
|
self.class.map(map, &block)
|
||||||
|
end
|
||||||
|
|
||||||
# def compiled_templates_cache
|
# def compiled_templates_cache
|
||||||
# @_compiled_templates_cache ||= {}
|
# @_compiled_templates_cache ||= {}
|
||||||
# end
|
# end
|
||||||
|
|
|
@ -2,19 +2,12 @@ require 'pathname'
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require "sprockets"
|
require "sprockets"
|
||||||
|
|
||||||
class RackThingy
|
|
||||||
def call(env)
|
|
||||||
$stderr.puts "thingy"
|
|
||||||
[200, {}, "Sup"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module Middleman::CoreExtensions::Sprockets
|
module Middleman::CoreExtensions::Sprockets
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.set :js_compressor, false
|
app.set :js_compressor, false
|
||||||
app.set :css_compressor, false
|
app.set :css_compressor, false
|
||||||
return
|
|
||||||
# Cut off every extension after .js (which sprockets eats up)
|
# Cut off every extension after .js (which sprockets eats up)
|
||||||
app.build_reroute do |destination, request_path|
|
app.build_reroute do |destination, request_path|
|
||||||
if !request_path.match(/\.js\./i)
|
if !request_path.match(/\.js\./i)
|
||||||
|
@ -27,49 +20,48 @@ module Middleman::CoreExtensions::Sprockets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# app.after_configuration do
|
app.after_configuration do
|
||||||
# js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
|
js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
|
||||||
#
|
|
||||||
# vendor_dir = File.join("vendor", "assets", "javascripts")
|
vendor_dir = File.join("vendor", "assets", "javascripts")
|
||||||
# gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
# ::Middleman.spec_has_file?(spec, vendor_dir)
|
::Middleman.spec_has_file?(spec, vendor_dir)
|
||||||
# end.each do |spec|
|
end.each do |spec|
|
||||||
# js_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
js_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# app_dir = File.join("app", "assets", "javascripts")
|
app_dir = File.join("app", "assets", "javascripts")
|
||||||
# gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
# ::Middleman.spec_has_file?(spec, app_dir)
|
::Middleman.spec_has_file?(spec, app_dir)
|
||||||
# end.each do |spec|
|
end.each do |spec|
|
||||||
# js_env.append_path File.join(spec.full_gem_path, app_dir)
|
js_env.append_path File.join(spec.full_gem_path, app_dir)
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# # add paths to js_env (vendor/assets/javascripts)
|
# add paths to js_env (vendor/assets/javascripts)
|
||||||
# app.map "/#{self.js_dir}" do
|
app.map "/#{self.js_dir}" do
|
||||||
# run js_env
|
run js_env
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
|
|
||||||
app.after_compass_config do
|
app.after_compass_config do
|
||||||
# css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
|
||||||
#
|
|
||||||
# vendor_dir = File.join("vendor", "assets", "stylesheets")
|
vendor_dir = File.join("vendor", "assets", "stylesheets")
|
||||||
# gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
# ::Middleman.spec_has_file?(spec, vendor_dir)
|
::Middleman.spec_has_file?(spec, vendor_dir)
|
||||||
# end.each do |spec|
|
end.each do |spec|
|
||||||
# css_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
css_env.append_path File.join(spec.full_gem_path, vendor_dir)
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# app_dir = File.join("app", "assets", "stylesheets")
|
app_dir = File.join("app", "assets", "stylesheets")
|
||||||
# gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
|
||||||
# ::Middleman.spec_has_file?(spec, app_dir)
|
::Middleman.spec_has_file?(spec, app_dir)
|
||||||
# end.each do |spec|
|
end.each do |spec|
|
||||||
# css_env.append_path File.join(spec.full_gem_path, app_dir)
|
css_env.append_path File.join(spec.full_gem_path, app_dir)
|
||||||
# end
|
end
|
||||||
|
|
||||||
app.map "/#{self.css_dir}" do
|
map("/#{self.css_dir}") do
|
||||||
# run css_env
|
run css_env
|
||||||
run ::RackThingy.new
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,34 +1,12 @@
|
||||||
module Middleman::Features::CacheBuster
|
module Middleman::Features::CacheBuster
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
app.register_asset_handler :cache_buster do |path, prefix|
|
app.send :include, InstanceMethods
|
||||||
http_path = app.before_asset_handler(:cache_buster, path, prefix)
|
|
||||||
|
|
||||||
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
|
|
||||||
http_path
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
prefix = app.images_dir if prefix == app.http_images_path
|
|
||||||
rescue
|
|
||||||
end
|
|
||||||
|
|
||||||
real_path_static = File.join(app.views, prefix, path)
|
|
||||||
|
|
||||||
if File.readable?(real_path_static)
|
|
||||||
http_path << "?" + File.mtime(real_path_static).strftime("%s")
|
|
||||||
elsif app.build?
|
|
||||||
real_path_dynamic = File.join(app.root, app.build_dir, prefix, path)
|
|
||||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
|
||||||
end
|
|
||||||
|
|
||||||
http_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
app.compass_config do |config|
|
app.compass_config do |config|
|
||||||
config.asset_cache_buster do |path, real_path|
|
config.asset_cache_buster do |path, real_path|
|
||||||
real_path = real_path.path if real_path.is_a? File
|
real_path = real_path.path if real_path.is_a? File
|
||||||
real_path = real_path.gsub(File.join(app.root, app.build_dir), app.views)
|
real_path = real_path.gsub(File.join(self.root, self.build_dir), self.views)
|
||||||
if File.readable?(real_path)
|
if File.readable?(real_path)
|
||||||
File.mtime(real_path).strftime("%s")
|
File.mtime(real_path).strftime("%s")
|
||||||
else
|
else
|
||||||
|
@ -39,4 +17,39 @@ module Middleman::Features::CacheBuster
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module InstanceMethods
|
||||||
|
def asset_url(path, prefix="")
|
||||||
|
http_path = super
|
||||||
|
|
||||||
|
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
|
||||||
|
http_path
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
prefix = self.images_dir if prefix == self.http_images_path
|
||||||
|
rescue
|
||||||
|
end
|
||||||
|
|
||||||
|
real_path_static = File.join(prefix, path)
|
||||||
|
result = resolve_template(real_path_static)
|
||||||
|
|
||||||
|
if self.build?
|
||||||
|
real_path_dynamic = File.join(self.build_dir, prefix, path)
|
||||||
|
real_path_dynamic = File.expand_path(real_path_dynamic, self.root)
|
||||||
|
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||||
|
elsif result
|
||||||
|
if result[1].nil?
|
||||||
|
http_path << "?" + File.mtime(result[0]).strftime("%s")
|
||||||
|
else
|
||||||
|
# It's a template, possible with partials. We can't really know when
|
||||||
|
# it's updated, so generate fresh cache buster every time durin
|
||||||
|
# developement
|
||||||
|
http_path << "?" + Time.now.strftime("%s")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
http_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -77,16 +77,17 @@ module Guard
|
||||||
end
|
end
|
||||||
|
|
||||||
def server_start
|
def server_start
|
||||||
app = ::Middleman.server
|
|
||||||
# Quiet down Guard
|
# Quiet down Guard
|
||||||
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
|
# ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
|
||||||
|
|
||||||
@app = app.new
|
env = (@options[:environment] || "development").to_sym
|
||||||
@app.set :environment, (@options[:environment] || "development").to_sym
|
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
|
||||||
@app.set :logging, @options.has_key?(:debug) && (@options[:debug] == "true")
|
@app = ::Middleman.server.inst do
|
||||||
|
set :environment, env
|
||||||
|
set :logging, is_logging
|
||||||
|
end
|
||||||
|
|
||||||
app_rack = ::Middleman::Base.app
|
app_rack = @app.class.to_rack_app
|
||||||
app_rack.run @app
|
|
||||||
|
|
||||||
@server_job = fork do
|
@server_job = fork do
|
||||||
opts = @options.dup
|
opts = @options.dup
|
||||||
|
|
|
@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
||||||
s.add_dependency("execjs", ["~> 1.2.7"])
|
s.add_dependency("execjs", ["~> 1.2.7"])
|
||||||
s.add_dependency("sprockets", ["~> 2.0"])
|
s.add_dependency("sprockets", ["~> 2.0"])
|
||||||
s.add_dependency("sprockets-sass", ["~> 0.4.0"])
|
s.add_dependency("sprockets-sass", ["~> 0.3.0"])
|
||||||
s.add_dependency("hooks", ["~> 0.2.0"])
|
s.add_dependency("hooks", ["~> 0.2.0"])
|
||||||
s.add_dependency("rb-fsevent")
|
s.add_dependency("rb-fsevent")
|
||||||
s.add_dependency("guard", ["~> 0.8.8"])
|
s.add_dependency("guard", ["~> 0.8.8"])
|
||||||
|
|
Loading…
Reference in a new issue