Method: YUICompressor.compress
- Defined in:
-
lib/yuicompressor/jruby.rb,
lib/yuicompressor/shell.rb
Returns a compressed version of the given stream_or_string of code using the given options. When using this method directly, at least the :type option must be specified, and should be one of "css" or "js". See YUICompressor#compress_css and YUICompressor#compress_js for details about which options are acceptable for each type of compressor.
In addition to the standard options, this method also accepts a :java option that can be used to specify the location of the Java executable. This option will default to using "java" unless otherwise specified.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/yuicompressor/jruby.rb', line 52 def compress(stream_or_string, ={}) raise ArgumentError, 'Option :type required' unless .key?(:type) stream = streamify(stream_or_string) output = StringIO.new reader = InputStreamReader.new(stream.to_inputstream) writer = OutputStreamWriter.new(output.to_outputstream) compressor = case [:type].to_s when 'js' = .merge() JavaScriptCompressor.new(reader, ErrorReporter.new) when 'css' = .merge() CssCompressor.new(reader) else raise ArgumentError, 'Unknown resource type: %s' % [:type] end compressor.compress(writer, *command_arguments()) writer.flush output.rewind output.read end |