Class: JsCompressor

Inherits:
Compressor show all
Defined in:
lib/compressors/jsCompressor.rb

Constant Summary

Constants included from SqweezeUtils

SqweezeUtils::EMBED_MIME_TYPES

Instance Attribute Summary

Attributes inherited from Compressor

#byteweight_after, #byteweight_before, #input_file_extensions

Instance Method Summary collapse

Methods inherited from Compressor

#collect_filepaths, #compress, #concatenate_files, #filextension2regexpstr, #print_summary, #set_command, #size_check

Methods included from SqweezeUtils

#ansi_bold, #ansi_green, #ansi_nocolour, #ansi_red, #ansi_yellow, #byteweight, #compression_percentage, #encoded_contents, #find_file_in_targetdir, #mime_type, #notify, #remap_filepath, #write_file

Constructor Details

#initializeJsCompressor

Returns a new instance of JsCompressor.



3
4
5
6
# File 'lib/compressors/jsCompressor.rb', line 3

def initialize
  super('js')
  @concatenate_input=true
end

Instance Method Details

#process(input_str, cmd = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/compressors/jsCompressor.rb', line 9

def process(input_str,cmd=nil)
 if @cm.get_conf(:default_js_compressor) == :closure
      compressor, method = Closure::Compiler.new, :compiler
 else
      compressor, method = YUI::JavaScriptCompressor.new( :munge => true), :compress
 end
 fout= (@concatenate_input)? "#{@cm.target_dir}/javascripts.min.js" : @cm.get_target_path(inputpath)
 

 File.open(fout,'w') do |f|
    f.write(compressor.send( method, input_str))
 end

 # set the total byte-weight 
 @byteweight_after=byteweight(fout) 
 fout
end