Class: Sprockets::ClosureCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/closure_compressor.rb

Overview

Public: Closure Compiler minifier.

To accept the default options

environment.register_bundle_processor 'application/javascript',
  Sprockets::ClosureCompressor

Or to pass options to the Closure::Compiler class.

environment.register_bundle_processor 'application/javascript',
  Sprockets::ClosureCompressor.new({ ... })

Constant Summary collapse

VERSION =
'1'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ClosureCompressor

Returns a new instance of ClosureCompressor



30
31
32
33
34
35
36
37
38
39
# File 'lib/sprockets/closure_compressor.rb', line 30

def initialize(options = {})
  @compiler = ::Closure::Compiler.new(options)
  @cache_key = [
    self.class.name,
    ::Closure::VERSION,
    ::Closure::COMPILER_VERSION,
    VERSION,
    options
  ].freeze
end

Class Method Details

.call(input) ⇒ Object



26
27
28
# File 'lib/sprockets/closure_compressor.rb', line 26

def self.call(input)
  instance.call(input)
end

.instanceObject

Public: Return singleton instance with default options.

Returns ClosureCompressor object.



22
23
24
# File 'lib/sprockets/closure_compressor.rb', line 22

def self.instance
  @instance ||= new
end

Instance Method Details

#call(input) ⇒ Object



41
42
43
44
45
# File 'lib/sprockets/closure_compressor.rb', line 41

def call(input)
  input[:cache].fetch(@cache_key + [input[:data]]) do
    @compiler.compile(input[:data])
  end
end