module Sprockets::Compressing

def compressors

def compressors
  config[:compressors]
end

def css_compressor

Return CSS compressor or nil if none is set
def css_compressor
  if defined? @css_compressor
    @css_compressor
  end
end

def css_compressor=(compressor)

The compressor object must respond to `compress`.

Assign a compressor to run on `text/css` assets.
def css_compressor=(compressor)
  unregister_bundle_processor 'text/css', @css_compressor if defined? @css_compressor
  @css_compressor = nil
  return unless compressor
  if compressor.is_a?(Symbol)
    @css_compressor = klass = config[:compressors]['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
  elsif compressor.respond_to?(:compress)
    klass = proc { |input| compressor.compress(input[:data]) }
    @css_compressor = :css_compressor
  else
    @css_compressor = klass = compressor
  end
  register_bundle_processor 'text/css', klass
end

def gzip=(gzip)


environment.gzip = :zopfli

instead:
installed you can specify the zopfli algorithm to be used
be used to gzip assets. If you have the Zopfli gem
To enable set to a truthy value. By default zlib wil

environment.gzip = false

To disable gzip generation set to a falsey value:

Public: Enable or disable the creation of Gzip files.
def gzip=(gzip)
  self.config = config.merge(gzip_enabled: gzip).freeze
  case gzip
  when false, nil
    self.unregister_exporter Exporters::ZlibExporter
    self.unregister_exporter Exporters::ZopfliExporter
  when :zopfli
    self.unregister_exporter Exporters::ZlibExporter
    self.register_exporter '*/*', Exporters::ZopfliExporter
  else
    self.unregister_exporter Exporters::ZopfliExporter
    self.register_exporter '*/*', Exporters::ZlibExporter
  end
  gzip
end

def gzip?

Public: Checks if Gzip is enabled.
def gzip?
  config[:gzip_enabled]
end

def js_compressor

Return JS compressor or nil if none is set
def js_compressor
  if defined? @js_compressor
    @js_compressor
  end
end

def js_compressor=(compressor)

The compressor object must respond to `compress`.

Assign a compressor to run on `application/javascript` assets.
def js_compressor=(compressor)
  unregister_bundle_processor 'application/javascript', @js_compressor if defined? @js_compressor
  @js_compressor = nil
  return unless compressor
  if compressor.is_a?(Symbol)
    @js_compressor = klass = config[:compressors]['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
  elsif compressor.respond_to?(:compress)
    klass = proc { |input| compressor.compress(input[:data]) }
    @js_compressor = :js_compressor
  else
    @js_compressor = klass = compressor
  end
  register_bundle_processor 'application/javascript', klass
end

def register_compressor(mime_type, sym, klass)

Returns nothing.

klass - The compressor class.
sym - Symbol registration address.
mime_type - String MIME Type (one of: 'test/css' or 'application/javascript').

css_compressor = :my_sass
register_compressor 'text/css', :my_sass, MySassCompressor

Examples

different type of asset, use a processor instead.
Compressors only operate on JavaScript and CSS. If you want to compress a

assigning a JavaScript or CSS compressor.
Registering a processor allows it to be looked up by `sym` later when

Public: Register a new compressor `klass` at `sym` for `mime_type`.
def register_compressor(mime_type, sym, klass)
  self.config = hash_reassoc(config, :compressors, mime_type) do |compressors|
    compressors[sym] = klass
    compressors
  end
end

def skip_gzip?

Public: Checks if Gzip is disabled.
def skip_gzip?
  !gzip?
end