lib/middleman-webp/extension.rb in middleman-webp-0.3.2 vs lib/middleman-webp/extension.rb in middleman-webp-0.4.0

- old
+ new

@@ -1,6 +1,7 @@ require 'middleman-core' +require 'middleman-webp/logger' require 'middleman-webp/converter' require 'shell' module Middleman @@ -20,36 +21,47 @@ @app = app end def before_build(builder) return unless options[:run_before_build] - return unless dependencies_installed?(builder) - Middleman::WebP::Converter.new(@app, options, builder).convert + + initialize_logger builder + return unless dependencies_installed? + Middleman::WebP::Converter.new(@app, options, builder, @logger).convert end def after_build(builder) return if options[:run_before_build] - return unless dependencies_installed?(builder) - Middleman::WebP::Converter.new(@app, options, builder).convert + + initialize_logger builder + return unless dependencies_installed? + Middleman::WebP::Converter.new(@app, options, builder, @logger).convert end # Internal: Check that cwebp and gif2webp commandline tools are available. # # Returns true if all is OK. - def dependencies_installed?(builder) - sh = Shell.new + def dependencies_installed? + warn_if_gif2webp_missing + cwebp_installed? + end - begin - sh.find_system_command('gif2webp') - rescue Shell::Error::CommandNotFound => e - builder.say_status :webp, "#{e.message} Please install latest version of webp library and tools to get gif2webp and be able to convert gif files also.", :red - end + def initialize_logger(builder) + @logger = Middleman::WebP::Logger.new(builder, verbose: @options.verbose) + end - begin - true if sh.find_system_command('cwebp') - rescue Shell::Error::CommandNotFound => e - builder.say_status :webp, "ERROR: #{e.message} Please install cwebp and gif2webp commandline tools first.", :red - false - end + private + + def warn_if_gif2webp_missing + Shell.new.find_system_command('gif2webp') + rescue Shell::Error::CommandNotFound => e + @logger.error "#{e.message} Please install latest version of webp library and tools to get gif2webp and be able to convert gif files also." + end + + def cwebp_installed? + true if Shell.new.find_system_command('cwebp') + rescue Shell::Error::CommandNotFound => e + @logger.error "ERROR: #{e.message} Please install cwebp and gif2webp commandline tools first." + false end end end