Module: YUICompressor::JRuby
- Defined in:
- lib/yuicompressor/jruby.rb
Overview
This module contains methods specific to the JRuby platform and is automatically used when JRuby is detected. It provides a significant increase in performance over the Shell module.
Defined Under Namespace
Classes: ErrorReporter
Instance Method Summary collapse
-
#command_arguments(options = {}) ⇒ Object
Returns the set of arguments that are needed to instantiate a compressor using the given
options
. -
#compress(stream_or_string, options = {}) ⇒ Object
Compresses the given
stream_or_string
of code using the givenoptions
.
Instance Method Details
#command_arguments(options = {}) ⇒ Object
Returns the set of arguments that are needed to instantiate a compressor using the given options
.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yuicompressor/jruby.rb', line 32 def command_arguments(={}) args = [ [:line_break] ? [:line_break].to_i : -1 ] if [:type].to_s == 'js' args << !! [:munge] args << false # verbose? args << !! [:preserve_semicolons] args << ! [:optimize] # disable optimizations? end args end |
#compress(stream_or_string, options = {}) ⇒ Object
Compresses 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.
If a block is given, it will receive the IO output object. Otherwise the output will be returned as a string.
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 78 79 80 81 82 |
# File 'lib/yuicompressor/jruby.rb', line 53 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 if block_given? yield output else output.read end end |