Created
June 20, 2011 08:38
-
-
Save swistaczek/1035314 to your computer and use it in GitHub Desktop.
Reduce Paperclip processor (loseless opt js, css, jpg, png or gif files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/paperclip_processors/loseless_reduce.rb | |
require 'reduce' | |
## LoseLessReduce | |
# This module is able to reduce js, css, jpg, png or gif files | |
# thanks to gem reduce by grosser (via yui compressor or punnyPng) | |
# https://github.com/grosser/reduce | |
module Paperclip | |
class LoselessReduce < Processor | |
class InstanceNotGiven < ArgumentError; end | |
def compress_asset | |
Reduce.reduce(@file.path) | |
end | |
def initialize(file, options = {}) | |
super | |
@file = file | |
@instance = options[:instance] | |
@current_format = File.extname(@file.path) | |
@basename = File.basename(@file.path, @current_format) | |
end | |
def make | |
@file.pos = 0 | |
dst = Tempfile.new([@basename, @format].compact.join(".")) | |
dst << compress_asset | |
dst | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment