Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

dutygeeks commented Feb 28, 2012

brew install htmlcompressor => 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.