Parent

Files

Class/Module Index [+]

Quicksearch

Uglifier

A wrapper around the UglifyJS interface

Constants

DEFAULTS

Default options for compilation

ES5FallbackPath

ES5 shims source path

Error
JS
SourcePath

UglifyJS source patch

SplitFallbackPath

String.split shim source path

VERSION

Public Class Methods

compile(source, options = {}) click to toggle source

Minifies JavaScript code using implicit context.

source should be a String or IO object containing valid JavaScript. options contain optional overrides to Uglifier::DEFAULTS

Returns minified code as String

# File lib/uglifier.rb, line 136
def self.compile(source, options = {})
  new(options).compile(source)
end
compile_with_map(source, options = {}) click to toggle source

Minifies JavaScript code and generates a source map using implicit context.

source should be a String or IO object containing valid JavaScript. options contain optional overrides to Uglifier::DEFAULTS

Returns a pair of [minified code as String, source map as a String]

# File lib/uglifier.rb, line 146
def self.compile_with_map(source, options = {})
  new(options).compile_with_map(source)
end
new(options = {}) click to toggle source

Initialize new context for Uglifier with given options

options - Hash of options to override Uglifier::DEFAULTS

# File lib/uglifier.rb, line 153
def initialize(options = {})
  (options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
    raise ArgumentError, "Invalid option: #{missing}"
  end
  @options = options
  @context = ExecJS.compile(File.open(ES5FallbackPath, "r:UTF-8").read +
                            File.open(SplitFallbackPath, "r:UTF-8").read +
                            File.open(SourcePath, "r:UTF-8").read)
end

Public Instance Methods

compile(source) click to toggle source

Minifies JavaScript code

source should be a String or IO object containing valid JavaScript.

Returns minified code as String

# File lib/uglifier.rb, line 168
def compile(source)
  run_uglifyjs(source, false)
end
Also aliased as: compress
compile_with_map(source) click to toggle source

Minifies JavaScript code and generates a source map

source should be a String or IO object containing valid JavaScript.

Returns a pair of [minified code as String, source map as a String]

# File lib/uglifier.rb, line 178
def compile_with_map(source)
  run_uglifyjs(source, true)
end
compress(source) click to toggle source
Alias for: compile

[Validate]

Generated with the Darkfish Rdoc Generator 2.