In Files

Parent

Files

Class/Module Index [+]

Quicksearch

Uglifier

Constants

DEFAULTS

Default options for compilation

ES5FallbackPath
Error
SourcePath
SplitFallbackPath

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 66
def self.compile(source, options = {})
  self.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 76
def self.compile_with_map(source, options = {})
  self.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 83
def initialize(options = {})
  (options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
    raise ArgumentError.new("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 98
def compile(source)
  really_compile(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 108
def compile_with_map(source)
  really_compile(source, true)
end
compress(source) click to toggle source
Alias for: compile

[Validate]

Generated with the Darkfish Rdoc Generator 2.