Created
January 11, 2011 04:23
-
-
Save seth/774015 to your computer and use it in GitHub Desktop.
A Nanoc filter for minifying CSS and Javascript using the YUI Compressor
This file contains 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
YUI_JAR = File.dirname(__FILE__) + "/../tools/yuicompressor-2.4.2.jar" | |
class YuiCompressor < Nanoc3::Filter | |
identifier :yui_compress | |
type :text => :binary | |
def run(content, params={}) | |
type = type_from_extension | |
cmd = "java -jar #{YUI_JAR} --type #{type} -o #{output_filename}" | |
IO.popen(cmd, 'w') { |f| f.write(content) } | |
raise "yuicompressor exited with #{$?} for '#{cmd}'" unless $? == 0 | |
end | |
def type_from_extension | |
case @item[:extension] | |
when /^css/ | |
"css" | |
when /^js/ | |
"js" | |
else | |
raise "unknown type for yuicompressor '#{@item[:extension]}'" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment