From bed57058413fcb93cfefe703adfd40e86d0cdcbb Mon Sep 17 00:00:00 2001 From: tdreyno Date: Thu, 22 Oct 2009 10:14:47 -0700 Subject: [PATCH] handful of fixes --- bin/mm-server | 2 +- lib/middleman/features/cache_buster.rb | 2 +- lib/middleman/features/minify_javascript.rb | 9 ++++++--- lib/middleman/templater+dynamic_renderer.rb | 12 +++++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/mm-server b/bin/mm-server index 86043198..d5b04e39 100755 --- a/bin/mm-server +++ b/bin/mm-server @@ -6,7 +6,7 @@ require 'optparse' require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman') env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development' -options = { :Port => 4567, :Host => 'localhost', :AccessLog => [] } +options = { :Port => 4567, :AccessLog => [] } OptionParser.new { |opts| opts.banner = "Usage: mm-server [rack options]" diff --git a/lib/middleman/features/cache_buster.rb b/lib/middleman/features/cache_buster.rb index 323931cc..95eadcd7 100644 --- a/lib/middleman/features/cache_buster.rb +++ b/lib/middleman/features/cache_buster.rb @@ -5,7 +5,7 @@ class << Middleman::Base if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path)) http_path else - real_path = File.join(self.environment == "build" ? self.build_dir : self.public, prefix, path) + real_path = File.join(self.public, prefix, path) http_path << "?" + File.mtime(real_path).strftime("%s") if File.readable?(real_path) http_path end diff --git a/lib/middleman/features/minify_javascript.rb b/lib/middleman/features/minify_javascript.rb index e59f24fd..b1292513 100644 --- a/lib/middleman/features/minify_javascript.rb +++ b/lib/middleman/features/minify_javascript.rb @@ -21,9 +21,12 @@ END compressor = ::YUI::JavaScriptCompressor.new(:munge => true) Dir[File.join(Middleman::Base.build_dir, Middleman::Base.js_dir, "**", "*.js")].each do |path| - compressed_js = compressor.compress(File.read(path)) - File.open(path, 'w') { |f| f.write(compressed_js) } - say "<%= color('#{"[COMPRESSED]".rjust(12)}', :yellow) %> " + path.gsub(Middleman::Base.build_dir+"/", '') + 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 if Middleman::Base.environment == "build" diff --git a/lib/middleman/templater+dynamic_renderer.rb b/lib/middleman/templater+dynamic_renderer.rb index 4b026e4e..4f1882a4 100644 --- a/lib/middleman/templater+dynamic_renderer.rb +++ b/lib/middleman/templater+dynamic_renderer.rb @@ -14,10 +14,12 @@ end class Templater::Actions::Template def render - # The default render just requests the page over Rack and writes the response - request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "") - browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base)) - browser.get(request_path) - browser.last_response.body + @render_cache ||= begin + # The default render just requests the page over Rack and writes the response + request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "") + browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base)) + browser.get(request_path) + browser.last_response.body + end end end \ No newline at end of file