Module: Middleman::Smusher

Defined in:
lib/middleman-smusher/version.rb,
lib/middleman-smusher/extension.rb

Constant Summary collapse

VERSION =
"3.0.0"

Class Method Summary collapse

Class Method Details

.registered(app, options = {}) ⇒ Object Also known as: included



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/middleman-smusher/extension.rb', line 4

def registered(app, options={})
  require "smusher"
  
  # options[:service] ||= "SmushIt"
  options[:quiet] = true
  
  app.after_configuration do
    smush_dir = if options.has_key?(:path)
      options.delete(:path)
    else
      File.join(build_dir, images_dir)
    end
    
    prefix = build_dir + File::SEPARATOR
  
    after_build do |builder|
      files = ::Smusher.class_eval do
        images_in_folder(smush_dir)
      end
            
      files.each do |file|
        ::Smusher.optimize_image(
          [file],
          options
        )
      
        builder.say_status :smushed, file.sub(prefix, "")
      end
    end
  end
end