Class | YUI::Compressor
In: | lib/yui/compressor.rb
Parent: | Object

### Methods

compress

### Classes and Modules

Class YUI::Compressor::Error
Class YUI::Compressor::OptionError
Class YUI::Compressor::RuntimeError

### Constants

VERSION | = | "0.9.6"

### Attributes

options | [R] |

### Public Instance methods

compress(stream_or_string) {|stdout| ...}

Compress a stream or string of code with YUI Compressor. (A stream is any object that responds to `read` and `close` like an IO.) If a block is given, you can read the compressed code from the block‘s argument. Otherwise, `compress` returns a string of compressed code.

#### Example: Compress CSS

      compressor = YUI::CssCompressor.new
      compressor.compress(<<-END_CSS)
        div.error {
          color: red;
        }
        div.warning {
          display: none;
        }
      END_CSS
      # => "div.error{color:red;}div.warning{display:none;}"

#### Example: Compress JavaScript

      compressor = YUI::JavaScriptCompressor.new
      compressor.compress('(function () { var foo = {}; foo["bar"] = "baz"; })()')
      # => "(function(){var foo={};foo.bar=\"baz\"})();"

#### Example: Compress and gzip a file on disk

      File.open("my.js", "r") do |source|
        Zlib::GzipWriter.open("my.js.gz", "w") do |gzip|
          compressor.compress(source) do |compressed|
            while buffer = compressed.read(4096)
              gzip.write(buffer)
            end
          end
        end
      end

[Validate]