Class: Rack::Pack::Javascript

Inherits:
Package
  • Object
show all
Defined in:
lib/rack/pack/javascript.rb

Instance Attribute Summary

Attributes inherited from Package

#file

Instance Method Summary collapse

Methods inherited from Package

[], #compile, #compress?, #initialize, mappings, register, #source_files, #stale?, #update

Constructor Details

This class inherits a constructor from Rack::Pack::Package

Instance Method Details

#compress(source) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/pack/javascript.rb', line 4

def compress(source)
  if defined?(JSMin)
    JSMin.minify(source)
  elsif defined?(Packr)
    options = compression_options :shrink_vars => true
    Packr.pack(source, options)
  elsif defined?(YUI) and defined?(YUI::JavaScriptCompressor)
    options = compression_options :munge => true
    YUI::JavaScriptCompressor.new(options).compress(source)
  elsif defined?(Closure) and defined?(Closure::Compiler)
    Closure::Compiler.new(compression_options).compile(source)
  elsif defined?(Uglifier)
    Uglifier.new(compression_options).compile(source)
  else
    source
  end
end