Class: Middleman::WebPExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-webp/extension.rb

Overview

Middleman extension for converting image assets to WebP alternatives

Conversion is run using after_build or before_build according to the configuration, after_build being the default.

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ WebPExtension

Returns a new instance of WebPExtension.



26
27
28
29
# File 'lib/middleman-webp/extension.rb', line 26

def initialize(app, options_hash = {}, &block)
  super
  @app = app
end

Instance Method Details

#after_build(builder) ⇒ Object



38
39
40
41
42
43
# File 'lib/middleman-webp/extension.rb', line 38

def after_build(builder)
  return if options.run_before_build

  return unless dependencies_installed? builder
  Middleman::WebP::Converter.new(@app, builder, options).convert
end

#before_build(builder) ⇒ Object



31
32
33
34
35
36
# File 'lib/middleman-webp/extension.rb', line 31

def before_build(builder)
  return unless options.run_before_build

  return unless dependencies_installed?(builder)
  Middleman::WebP::Converter.new(@app, builder, options).convert
end

#dependencies_installed?(builder) ⇒ Boolean

Internal: Check that cwebp and gif2webp commandline tools are available.

Returns true if all is OK.

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/middleman-webp/extension.rb', line 48

def dependencies_installed?(builder)
  warn_if_gif2webp_missing builder
  cwebp_installed? builder
end