Module: Sprockets::Compressing

### Home Classes Methods

### In Files

- lib/sprockets/compressing.rb

### Methods

- #compressors
- #css_compressor
- #css_compressor=
- #js_compressor
- #js_compressor=
- #register_compressor

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::AssetAttributes
- Sprockets::Base
- Sprockets::BundledAsset
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Caching
- Sprockets::CharsetNormalizer
- Sprockets::CircularDependencyError
- Sprockets::ClosureCompressor
- Sprockets::Compressing
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::DirectiveProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsTemplate
- Sprockets::EncodingError
- Sprockets::EngineError
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::Manifest
- Sprockets::Mime
- Sprockets::NotImplementedError
- Sprockets::Paths
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::SassCacheStore
- Sprockets::SassCompressor
- Sprockets::SassFunctions
- Sprockets::SassImporter
- Sprockets::SassTemplate
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::UglifierCompressor
- Sprockets::UnserializeError
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::Compressing

`Compressing` is an internal mixin whose public methods are exposed on the `Environment` and `Index` classes.

### Public Instance Methods

compressors() click to toggle source

    # File lib/sprockets/compressing.rb, line 5
    def compressors
      deep_copy_hash(@compressors)
    end

css_compressor() click to toggle source

Return CSS compressor or nil if none is set

    # File lib/sprockets/compressing.rb, line 14
    def css_compressor
      @css_compressor if defined? @css_compressor
    end

css_compressor=(compressor) click to toggle source

Assign a compressor to run on `text/css` assets.

The compressor object must respond to `compress`.

    # File lib/sprockets/compressing.rb, line 21
    def css_compressor=(compressor)
      unregister_bundle_processor 'text/css', css_compressor if css_compressor
      @css_compressor = nil
      return unless compressor

      if compressor.is_a?(Symbol)
        compressor = compressors['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
      end

      if compressor.respond_to?(:compress)
        klass = Class.new(Processor) do
          @name = "css_compressor"
          @processor = proc { |context, data| compressor.compress(data) }
        end
        @css_compressor = :css_compressor
      else
        @css_compressor = klass = compressor
      end

      register_bundle_processor 'text/css', klass
    end

js_compressor() click to toggle source

Return JS compressor or nil if none is set

    # File lib/sprockets/compressing.rb, line 44
    def js_compressor
      @js_compressor if defined? @js_compressor
    end

js_compressor=(compressor) click to toggle source

Assign a compressor to run on `application/javascript` assets.

The compressor object must respond to `compress`.

    # File lib/sprockets/compressing.rb, line 51
    def js_compressor=(compressor)
      unregister_bundle_processor 'application/javascript', js_compressor if js_compressor
      @js_compressor = nil
      return unless compressor

      if compressor.is_a?(Symbol)
        compressor = compressors['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
      end

      if compressor.respond_to?(:compress)
        klass = Class.new(Processor) do
          @name = "js_compressor"
          @processor = proc { |context, data| compressor.compress(data) }
        end
        @js_compressor = :js_compressor
      else
        @js_compressor = klass = compressor
      end

      register_bundle_processor 'application/javascript', klass
    end

register_compressor(mime_type, sym, klass) click to toggle source

    # File lib/sprockets/compressing.rb, line 9
    def register_compressor(mime_type, sym, klass)
      @compressors[mime_type][sym] = klass
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.