Sha256: d6743c70ad182a621db428d3e45e253aa5c02487eb0dd73236e24a70bb485857

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

require "middleman/builder"

module Middleman
  class Builder
    alias_method :pre_smush_after_run, :after_run
    def after_run
      pre_smush_after_run
      smush_dir = File.join(Middleman::Base.build_dir, Middleman::Base.images_dir)
      
      # Read cache
      cache_file = File.join(Middleman::Base.root, ".smush-cache")
      cache_data = if File.exists?(cache_file)
        Marshal.restore(File.read(cache_file))
      else
        {}
      end
      
      require "smusher"
      require "json/pure"
      ::Smusher.class_eval do
        images_in_folder(smush_dir).each do |file|
          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
            say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %>  " + file.gsub(Middleman::Base.build_dir+"/", '')
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
middleman-0.14.1 lib/middleman/features/smush_pngs.rb
middleman-0.14.0 lib/middleman/features/smush_pngs.rb
middleman-0.14.0.pre2 lib/middleman/features/smush_pngs.rb
middleman-0.13.2.pre lib/middleman/features/smush_pngs.rb
middleman-0.13.1 lib/middleman/features/smush_pngs.rb
middleman-0.12.2 lib/middleman/features/smush_pngs.rb
middleman-0.12.1 lib/middleman/features/smush_pngs.rb
middleman-0.12.0.pre3 lib/middleman/features/smush_pngs.rb
middleman-0.12.0.pre2 lib/middleman/features/smush_pngs.rb
middleman-0.12.0.pre lib/middleman/features/smush_pngs.rb