Sha256: a7c35b40ffd14c88a3a6ad2ccc6e9d38bb93bd36ea6bc4e4cae19e4be470a963

Contents?: true

Size: 1.36 KB

Versions: 39

Compression:

Stored size: 1.36 KB

Contents

require 'sprockets/autoload'
require 'sprockets/digest_utils'

module Sprockets
  # Public: Uglifier/Uglify compressor.
  #
  # To accept the default options
  #
  #     environment.register_bundle_processor 'application/javascript',
  #       Sprockets::UglifierCompressor
  #
  # Or to pass options to the Uglifier class.
  #
  #     environment.register_bundle_processor 'application/javascript',
  #       Sprockets::UglifierCompressor.new(comments: :copyright)
  #
  class UglifierCompressor
    VERSION = '1'

    # Public: Return singleton instance with default options.
    #
    # Returns UglifierCompressor object.
    def self.instance
      @instance ||= new
    end

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

    def self.cache_key
      instance.cache_key
    end

    attr_reader :cache_key

    def initialize(options = {})
      # Feature detect Uglifier 2.0 option support
      if Autoload::Uglifier::DEFAULTS[:copyright]
        # Uglifier < 2.x
        options[:copyright] ||= false
      else
        # Uglifier >= 2.x
        options[:comments] ||= :none
      end

      @options = options
      @cache_key = "#{self.class.name}:#{Autoload::Uglifier::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
    end

    def call(input)
      @uglifier ||= Autoload::Uglifier.new(@options)
      @uglifier.compile(input[:data])
    end
  end
end

Version data entries

39 entries across 36 versions & 9 rubygems

Version Path
sprockets-3.7.5 lib/sprockets/uglifier_compressor.rb
sprockets-3.7.4 lib/sprockets/uglifier_compressor.rb
sprockets-3.7.3 lib/sprockets/uglifier_compressor.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
spiral_form-0.1.1 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
spiral_form-0.1.0 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
tdiary-5.0.11 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb
sprokovuln-0.2.0 vendor/ruby/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb