Class: Middleman::WebPExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::WebPExtension
- 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
- #after_build(builder) ⇒ Object
- #before_build(builder) ⇒ Object
-
#dependencies_installed?(builder) ⇒ Boolean
Internal: Check that cwebp and gif2webp commandline tools are available.
-
#initialize(app, options_hash = {}, &block) ⇒ WebPExtension
constructor
A new instance of WebPExtension.
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, = {}, &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 .run_before_build return unless dependencies_installed? builder Middleman::WebP::Converter.new(@app, builder, ).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 .run_before_build return unless dependencies_installed?(builder) Middleman::WebP::Converter.new(@app, builder, ).convert end |
#dependencies_installed?(builder) ⇒ Boolean
Internal: Check that cwebp and gif2webp commandline tools are available.
Returns true if all is OK.
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 |