class Middleman::WebPExtension
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.
Public Class Methods
new(app, options_hash = {}, &block)
click to toggle source
Calls superclass method
# File lib/middleman-webp/extension.rb, line 26 def initialize(app, options_hash = {}, &block) super @app = app end
Public Instance Methods
after_build(builder)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Internal: Check that cwebp and gif2webp commandline tools are available.
Returns true if all is OK.
# File lib/middleman-webp/extension.rb, line 48 def dependencies_installed?(builder) warn_if_gif2webp_missing builder cwebp_installed? builder end
Private Instance Methods
cwebp_installed?(builder)
click to toggle source
# File lib/middleman-webp/extension.rb, line 63 def cwebp_installed?(builder) true if Shell.new.find_system_command('cwebp') rescue Shell::Error::CommandNotFound => e builder.trigger :error, "ERROR: #{e.message} Please install cwebp and "\ 'gif2webp commandline tools first.' false end
warn_if_gif2webp_missing(builder)
click to toggle source
# File lib/middleman-webp/extension.rb, line 55 def warn_if_gif2webp_missing(builder) Shell.new.find_system_command('gif2webp') rescue Shell::Error::CommandNotFound => e builder.trigger :webp, '', "#{e.message} Please install latest version"\ ' of webp library and tools to get gif2webp and be able to convert gif'\ 'files also.' end