class Middleman::TinyPNG::Extension

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method
# File lib/middleman-tiny_png/extension.rb, line 13
def initialize(app, options_hash={}, &block)
  super
end

Public Instance Methods

after_build(builder) click to toggle source
# File lib/middleman-tiny_png/extension.rb, line 17
def after_build(builder)
  Tinify.key = options.api_key

  image_dir = File.join(app.config[:build_dir], app.config[:images_dir])
  image_file_paths = []

  Find.find(image_dir) do |path|
    image_file_paths << path if (path =~ /.*\.png$/) || (path =~ /.*\.jpg$/)
  end

  image_file_paths.each do |file|
    source = Tinify.from_file(file)
    source.to_file(file)
  end
end