Class: HtmlUglifier::Compressor
- Inherits:
-
Object
- Object
- HtmlUglifier::Compressor
- Defined in:
- lib/html_uglifier.rb
Instance Method Summary collapse
- #compress(html) ⇒ Object
- #compress_file(input_file, output_file) ⇒ Object
-
#initialize ⇒ Compressor
constructor
A new instance of Compressor.
Constructor Details
#initialize ⇒ Compressor
Returns a new instance of Compressor.
4 5 6 |
# File 'lib/html_uglifier.rb', line 4 def initialize() @compressor = File.join(File.dirname(__FILE__), '..', 'vendor', 'htmlcompressor*.jar') end |
Instance Method Details
#compress(html) ⇒ Object
8 9 10 11 12 |
# File 'lib/html_uglifier.rb', line 8 def compress(html) temp_file = File.join(File.dirname(__FILE__), '..', 'temp', 'temp.html') File.open(temp_file, 'w') { |f| f.write(html) } `java -jar #{path @compressor} --type html --compress-js --compress-css #{path temp_file}; rm #{path temp_file}` end |
#compress_file(input_file, output_file) ⇒ Object
14 15 16 17 |
# File 'lib/html_uglifier.rb', line 14 def compress_file(input_file, output_file) minified_html = `java -jar #{path @compressor} --type html --compress-js --compress-css #{path input_file}` File.open(output_file, 'w') { |f| f.write(minified_html) } end |