Module: YUICompressor

Defined in:
lib/yuicompressor.rb,
lib/yuicompressor/jruby.rb,
lib/yuicompressor/shell.rb

Defined Under Namespace

Modules: JRuby, Shell

Constant Summary collapse

JAR_FILE =

The path to the YUI Compressor jar file.

File.expand_path('../yuicompressor-2.4.2.jar', __FILE__)

Class Method Summary collapse

Class Method Details

.compress_css(stream_or_string, options = {}, &block) ⇒ Object

Compress the given CSS stream_or_string using the given options. Options should be a Hash with any of the following keys:

:line_break

The maximum number of characters that may appear in a single line of compressed code. Defaults to no maximum length. If set to 0 each line will be the minimum length possible.



25
26
27
# File 'lib/yuicompressor.rb', line 25

def compress_css(stream_or_string, options={}, &block)
  compress(stream_or_string, options.merge(:type => 'css'), &block)
end

.compress_js(stream_or_string, options = {}, &block) ⇒ Object

Compress the given JavaScript stream_or_string using the given options. Options should be a Hash with any of the following keys:

:line_break

The maximum number of characters that may appear in a single line of compressed code. Defaults to no maximum length. If set to 0 each line will be the minimum length possible.

:munge

Should be true if the compressor should shorten local variable names when possible. Defaults to false.

:preserve_semicolons

Should be true if the compressor should preserve all semicolons in the code. Defaults to false.

:optimize

Should be true if the compressor should enable all micro optimizations. Defaults to true.



42
43
44
# File 'lib/yuicompressor.rb', line 42

def compress_js(stream_or_string, options={}, &block)
  compress(stream_or_string, options.merge(:type => 'js'), &block)
end

.default_css_optionsObject

:nodoc:



46
47
48
# File 'lib/yuicompressor.rb', line 46

def default_css_options #:nodoc:
  { :line_break => nil }
end

.default_js_optionsObject

:nodoc:



50
51
52
53
54
55
56
# File 'lib/yuicompressor.rb', line 50

def default_js_options #:nodoc:
  default_css_options.merge(
    :munge => false,
    :preserve_semicolons => false,
    :optimize => true
  )
end

.jruby?Boolean

Returns true if the Ruby platform is JRuby.

Returns:

  • (Boolean)


14
15
16
# File 'lib/yuicompressor.rb', line 14

def jruby?
  !! (RUBY_PLATFORM =~ /java/)
end

.streamify(stream_or_string) ⇒ Object

:nodoc:



58
59
60
61
62
63
64
65
66
# File 'lib/yuicompressor.rb', line 58

def streamify(stream_or_string) #:nodoc:
  if IO === stream_or_string || StringIO === stream_or_string
    stream_or_string
  elsif String === stream_or_string
    StringIO.new(stream_or_string.to_s)
  else
    raise ArgumentError, 'Stream or string required'
  end
end