# encoding: utf-8 require 'piet' require 'easy_html_generator/generator/base' # this generator minifies image files from src folder and copies them # to the dist folder class EasyHtmlGenerator::Generator::Minimize::Images < EasyHtmlGenerator::Generator::Base def initialize(project, config) super(project, config) @config.src = project.config.paths.src.images @config.dest = project.config.paths.dist.images end def do_file(src, target, *args) return unless File.exist?(src) && File.file?(src) log "-> do_file #{src}" FileUtils.mkdir_p File.dirname(target) args.push target FileUtils.copy(src, target) Piet.optimize(target, @config.options) EasyHtmlGenerator::Checksum.store_file(src) rescue StandardError log '-> you have to install "optipng" and "jpegoptim"'.red end end