Pull smusher out into its own gem

This commit is contained in:
Thomas Reynolds 2011-04-18 10:56:12 -07:00
parent bfcb7cbd36
commit 7b666cb7c2
6 changed files with 1 additions and 61 deletions

View file

@ -64,10 +64,6 @@ module Middleman::Features
# will attempt to generate a `sitemap.html` file from your project. # will attempt to generate a `sitemap.html` file from your project.
autoload :Slickmap, "middleman/features/slickmap" autoload :Slickmap, "middleman/features/slickmap"
# SmushPngs uses Yahoo's Smush.it API to compresses PNGs and JPGs. Often times
# the service can decrease the size of Photoshop-exported images by 30-50%
autoload :SmushPngs, "middleman/features/smush_pngs"
# CodeRay is a syntax highlighter. # CodeRay is a syntax highlighter.
autoload :CodeRay, "middleman/features/code_ray" autoload :CodeRay, "middleman/features/code_ray"

View file

@ -1,48 +0,0 @@
module Middleman::Features::SmushPngs
module ThorActions
def smush_pngs
# Read cache
cache_file = File.join(Middleman::Server.root, ".smush-cache")
cache_data = if File.exists?(cache_file)
Marshal.restore(File.read(cache_file))
else
{}
end
smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
files = ::Smusher.class_eval do
images_in_folder(smush_dir)
end
files.each do |file|
::Smusher.class_eval do
original_file_size = size(file)
return if original_file_size.zero?
return if cache_data[file] && cache_data[file] == original_file_size
with_logging(file, true) do
write_optimized_data(file)
cache_data[file] = size(file) # Add or update cache
File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
end
end
say_status :smushed, file.gsub(Middleman::Server.build_dir+"/", "")
end
end
end
class << self
def registered(app)
require "middleman/builder"
require "smusher"
require "json/pure"
Middleman::Builder.send :include, ThorActions
Middleman::Builder.after_run "smush_pngs" do
smush_pngs
end
end
end
end

View file

@ -49,9 +49,6 @@ configure :build do
# Minify Javascript on build # Minify Javascript on build
# activate :minify_javascript # activate :minify_javascript
# Shrink/smush PNG/JPEGs on build
# activate :smush_pngs
# Enable cache buster # Enable cache buster
# activate :cache_buster # activate :cache_buster

View file

@ -37,9 +37,6 @@ configure :build do
# Minify Javascript on build # Minify Javascript on build
# activate :minify_javascript # activate :minify_javascript
# Shrink/smush PNG/JPEGs on build
# activate :smush_pngs
# Enable cache buster # Enable cache buster
# activate :cache_buster # activate :cache_buster

View file

@ -1,3 +1,3 @@
module Middleman module Middleman
VERSION = "1.1.1.a" VERSION = "1.1.2"
end end

View file

@ -34,8 +34,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("compass", ["0.11.beta.6"]) s.add_runtime_dependency("compass", ["0.11.beta.6"])
s.add_runtime_dependency("chunky_png", ["~> 1.1.0"]) s.add_runtime_dependency("chunky_png", ["~> 1.1.0"])
s.add_runtime_dependency("oily_png", ["~> 1.0"]) unless defined?(JRUBY_VERSION) s.add_runtime_dependency("oily_png", ["~> 1.0"]) unless defined?(JRUBY_VERSION)
s.add_runtime_dependency("json", [">= 0"])
s.add_runtime_dependency("smusher", ["~> 0.4.5"])
s.add_runtime_dependency("compass-slickmap", ["~> 0.4.0"]) s.add_runtime_dependency("compass-slickmap", ["~> 0.4.0"])
s.add_runtime_dependency("coffee-script", ["~> 2.1.0"]) s.add_runtime_dependency("coffee-script", ["~> 2.1.0"])
s.add_runtime_dependency("less", ["~> 1.2.0"]) s.add_runtime_dependency("less", ["~> 1.2.0"])