move yui into rack
This commit is contained in:
parent
d4929e18d6
commit
2020646909
6 changed files with 30 additions and 32 deletions
|
@ -27,6 +27,9 @@ module Middleman
|
|||
end
|
||||
|
||||
def self.file(name, *args, &block)
|
||||
file_ext = File.extname(args[0])
|
||||
return if Middleman::Base.supported_formats.include? file_ext[1..file_ext.length]
|
||||
|
||||
if (args[0] === args[1])
|
||||
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
|
||||
end
|
||||
|
@ -35,7 +38,8 @@ module Middleman
|
|||
|
||||
def self.init!
|
||||
glob! File.basename(Middleman::Base.public), []
|
||||
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats
|
||||
glob! File.basename(Middleman::Base.views), %w(sass js)
|
||||
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats - %w(sass js)
|
||||
end
|
||||
|
||||
def after_run
|
||||
|
|
|
@ -30,11 +30,14 @@ class << Middleman::Base
|
|||
end
|
||||
|
||||
real_path_static = File.join(self.public, prefix, path)
|
||||
real_path_dynamic = File.join(self.views, prefix, path)
|
||||
real_path_dynamic << ".sass" if File.extname(real_path_dynamic) == ".css"
|
||||
|
||||
http_path << "?" + File.mtime(real_path_static).strftime("%s") if File.readable?(real_path_static)
|
||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||
|
||||
if File.readable?(real_path_static)
|
||||
http_path << "?" + File.mtime(real_path_static).strftime("%s")
|
||||
elsif Middleman::Base.environment == "build"
|
||||
real_path_dynamic = File.join(self.root, self.build_dir, prefix, path)
|
||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||
end
|
||||
|
||||
http_path
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "yui/compressor"
|
||||
require "middleman/builder"
|
||||
|
||||
module Middleman
|
||||
|
@ -14,23 +13,6 @@ END
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Builder
|
||||
alias_method :pre_yui_after_run, :after_run
|
||||
def after_run
|
||||
pre_yui_after_run
|
||||
|
||||
compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
|
||||
Dir[File.join(Middleman::Base.build_dir, Middleman::Base.js_dir, "**", "*.js")].each do |path|
|
||||
lines = IO.readlines(path)
|
||||
if lines.length > 1
|
||||
compressed_js = compressor.compress(lines.join($/))
|
||||
File.open(path, 'w') { |f| f.write(compressed_js) }
|
||||
say "<%= color('#{"[COMPRESSED]".rjust(12)}', :yellow) %> " + path.gsub(Middleman::Base.build_dir+"/", '')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Middleman::Base.supported_formats << "js"
|
|
@ -1,5 +0,0 @@
|
|||
require "middleman/rack/sprockets"
|
||||
|
||||
class Middleman::Base
|
||||
use Middleman::Rack::Sprockets
|
||||
end
|
|
@ -1,9 +1,16 @@
|
|||
begin
|
||||
require 'sprockets'
|
||||
require 'middleman/rack/sprockets+ruby19' # Sprockets ruby 1.9 duckpunch
|
||||
|
||||
rescue LoadError
|
||||
puts "Sprockets not available. Install it with: gem install sprockets"
|
||||
end
|
||||
|
||||
begin
|
||||
require "yui/compressor"
|
||||
rescue LoadError
|
||||
puts "Sprockets not available. Install it with: gem install yui-compressor"
|
||||
end
|
||||
|
||||
module Middleman
|
||||
module Rack
|
||||
|
@ -21,8 +28,15 @@ module Middleman
|
|||
:source_files => [ File.join("views", path) ],
|
||||
:load_path => [ File.join("public", Middleman::Base.js_dir),
|
||||
File.join("views", Middleman::Base.js_dir) ])
|
||||
|
||||
result = secretary.concatenation.to_s
|
||||
|
||||
if @app.class.respond_to?(:minify_javascript?) && @app.class.minify_javascript?
|
||||
compressor = ::YUI::JavaScriptCompressor.new(:munge => true)
|
||||
result = compressor.compress(result)
|
||||
end
|
||||
|
||||
[200, { "Content-Type" => "text/javascript" }, [secretary.concatenation.to_s]]
|
||||
[200, { "Content-Type" => "text/javascript" }, [result]]
|
||||
else
|
||||
@app.call(env)
|
||||
end
|
||||
|
|
|
@ -13,9 +13,9 @@ describe "Cache Buster Feature in CSS" do
|
|||
browser.last_response.body.should include("?")
|
||||
end
|
||||
|
||||
it "should append query string in HTML if on" do
|
||||
it "should not append query string in HTML if on IN DEVELOPMENT" do
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new))
|
||||
browser.get("/cache-buster.html")
|
||||
browser.last_response.body.count("?").should == 2
|
||||
browser.last_response.body.count("?").should == 0
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue