Class: Middleman::Imageoptim::Optimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-imageoptim/optimizer.rb

Overview

Optimizer class that accepts an options object and processes files and passes them off to image_optim to be processed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, builder, options) ⇒ Optimizer

Returns a new instance of Optimizer.



15
16
17
18
19
20
# File 'lib/middleman-imageoptim/optimizer.rb', line 15

def initialize(app, builder, options)
  @app = app
  @builder = builder
  @options = options
  @byte_savings = 0
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



9
10
11
# File 'lib/middleman-imageoptim/optimizer.rb', line 9

def app
  @app
end

#builderObject (readonly)

Returns the value of attribute builder.



9
10
11
# File 'lib/middleman-imageoptim/optimizer.rb', line 9

def builder
  @builder
end

#byte_savingsObject (readonly)

Returns the value of attribute byte_savings.



9
10
11
# File 'lib/middleman-imageoptim/optimizer.rb', line 9

def byte_savings
  @byte_savings
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/middleman-imageoptim/optimizer.rb', line 9

def options
  @options
end

Class Method Details

.optimize!(app, builder, options) ⇒ Object



11
12
13
# File 'lib/middleman-imageoptim/optimizer.rb', line 11

def self.optimize!(app, builder, options)
  new(app, builder, options).process_images
end

Instance Method Details

#process_imagesObject



22
23
24
25
26
27
28
29
30
# File 'lib/middleman-imageoptim/optimizer.rb', line 22

def process_images
  images = updated_images
  modes = preoptimize_modes(images)
  optimizer.optimize_images(images) do |source, destination|
    process_image(source, destination, modes.fetch(source.to_s))
  end
  update_manifest
  say_status 'Total savings: %{data}', data: Utils.format_size(byte_savings)
end