Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dutygeeks
Forked from seth/yui_compressor.rb
Created February 28, 2012 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dutygeeks/1935969 to your computer and use it in GitHub Desktop.
Save dutygeeks/1935969 to your computer and use it in GitHub Desktop.
HTML COMPRESSOR
class Htmlcompressor < Nanoc3::Filter
identifier :htmlcompressor
type :text => :binary
def run(content, params={})
case @item[:extension]
when "xml.erb"
cmd = "htmlcompressor --type xml -o #{output_filename}"
when "html.erb", "md"
cmd = "htmlcompressor --type html -o #{output_filename} --remove-intertag-spaces --remove-quotes --simple-doctype --remove-style-attr --remove-link-attr --remove-script-attr --remove-form-attr --remove-input-attr --simple-bool-attr --remove-js-protocol --remove-http-protocol --remove-https-protocol --remove-surrounding-spaces --compress-js --compress-css"
else
raise "err"
end
IO.popen(cmd, 'w') { |f| f.write(content) }
raise "htmlcompressor exited with #{$?} for '#{cmd}'" unless $? == 0
end
end
@dutygeeks
Copy link
Author

brew install htmlcompressor => 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment