Module: Sprockets::Processing

### Home Classes Methods

### In Files

- lib/sprockets/processing.rb

### Methods

- #bundle_processors
- #format_extensions
- #postprocessors
- #preprocessors
- #processors
- #register_bundle_processor
- #register_postprocessor
- #register_preprocessor
- #register_processor
- #unregister_bundle_processor
- #unregister_postprocessor
- #unregister_preprocessor
- #unregister_processor

### 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::Processing

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

### Public Instance Methods

bundle_processors(mime_type = nil) click to toggle source

Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.

Bundle Processors are ran on concatenated assets rather than individual files.

All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.

    # File lib/sprockets/processing.rb, line 150
    def bundle_processors(mime_type = nil)
      if mime_type
        @bundle_processors[mime_type].dup
      else
        deep_copy_hash(@bundle_processors)
      end
    end

format_extensions() click to toggle source

Returns an `Array` of format extension `String`s.

    format_extensions
    # => ['.js', '.css']

    # File lib/sprockets/processing.rb, line 15
    def format_extensions
      @trail.extensions - @engines.keys
    end

postprocessors(mime_type = nil) click to toggle source

Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.

Postprocessors are ran after Preprocessors and Engine processors.

All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.

    # File lib/sprockets/processing.rb, line 49
    def postprocessors(mime_type = nil)
      if mime_type
        @postprocessors[mime_type].dup
      else
        deep_copy_hash(@postprocessors)
      end
    end

preprocessors(mime_type = nil) click to toggle source

Returns an `Array` of `Processor` classes. If a `mime_type` argument is supplied, the processors registered under that extension will be returned.

Preprocessors are ran before Postprocessors and Engine processors.

All `Processor`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::Template`.

    # File lib/sprockets/processing.rb, line 33
    def preprocessors(mime_type = nil)
      if mime_type
        @preprocessors[mime_type].dup
      else
        deep_copy_hash(@preprocessors)
      end
    end

processors(*args) click to toggle source

Deprecated alias for `preprocessors`.

    # File lib/sprockets/processing.rb, line 20
    def processors(*args)
      preprocessors(*args)
    end

register_bundle_processor(mime_type, klass, &block) click to toggle source

Registers a new Bundle Processor `klass` for `mime_type`.

    register_bundle_processor  'text/css', Sprockets::CharsetNormalizer

A block can be passed for to create a shorthand processor.

    register_bundle_processor 'text/css', :my_processor do |context, data|
      data.gsub(...)
    end

    # File lib/sprockets/processing.rb, line 168
    def register_bundle_processor(mime_type, klass, &block)
      if block_given?
        name  = klass.to_s
        klass = Class.new(Processor) do
          @name      = name
          @processor = block
        end
      end

      @bundle_processors[mime_type].push(klass)
    end

register_postprocessor(mime_type, klass, &block) click to toggle source

Registers a new Postprocessor `klass` for `mime_type`.

    register_postprocessor 'text/css', Sprockets::CharsetNormalizer

A block can be passed for to create a shorthand processor.

    register_postprocessor 'text/css', :my_processor do |context, data|
      data.gsub(...)
    end

    # File lib/sprockets/processing.rb, line 94
    def register_postprocessor(mime_type, klass, &block)
      if block_given?
        name  = klass.to_s
        klass = Class.new(Processor) do
          @name      = name
          @processor = block
        end
      end

      @postprocessors[mime_type].push(klass)
    end

register_preprocessor(mime_type, klass, &block) click to toggle source

Registers a new Preprocessor `klass` for `mime_type`.

    register_preprocessor 'text/css', Sprockets::DirectiveProcessor

A block can be passed for to create a shorthand processor.

    register_preprocessor 'text/css', :my_processor do |context, data|
      data.gsub(...)
    end

    # File lib/sprockets/processing.rb, line 72
    def register_preprocessor(mime_type, klass, &block)
      if block_given?
        name  = klass.to_s
        klass = Class.new(Processor) do
          @name      = name
          @processor = block
        end
      end

      @preprocessors[mime_type].push(klass)
    end

register_processor(*args, &block) click to toggle source

Deprecated alias for `register_preprocessor`.

    # File lib/sprockets/processing.rb, line 58
    def register_processor(*args, &block)
      register_preprocessor(*args, &block)
    end

unregister_bundle_processor(mime_type, klass) click to toggle source

Remove Bundle Processor `klass` for `mime_type`.

    unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer

    # File lib/sprockets/processing.rb, line 184
    def unregister_bundle_processor(mime_type, klass)
      if klass.is_a?(String) || klass.is_a?(Symbol)
        klass = @bundle_processors[mime_type].detect { |cls|
          cls.respond_to?(:name) &&
            cls.name == "Sprockets::Processor (#{klass})"
        }
      end

      @bundle_processors[mime_type].delete(klass)
    end

unregister_postprocessor(mime_type, klass) click to toggle source

Remove Postprocessor `klass` for `mime_type`.

    unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor

    # File lib/sprockets/processing.rb, line 130
    def unregister_postprocessor(mime_type, klass)
      if klass.is_a?(String) || klass.is_a?(Symbol)
        klass = @postprocessors[mime_type].detect { |cls|
          cls.respond_to?(:name) &&
            cls.name == "Sprockets::Processor (#{klass})"
        }
      end

      @postprocessors[mime_type].delete(klass)
    end

unregister_preprocessor(mime_type, klass) click to toggle source

Remove Preprocessor `klass` for `mime_type`.

    unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor

    # File lib/sprockets/processing.rb, line 115
    def unregister_preprocessor(mime_type, klass)
      if klass.is_a?(String) || klass.is_a?(Symbol)
        klass = @preprocessors[mime_type].detect { |cls|
          cls.respond_to?(:name) &&
            cls.name == "Sprockets::Processor (#{klass})"
        }
      end

      @preprocessors[mime_type].delete(klass)
    end

unregister_processor(*args) click to toggle source

Deprecated alias for `unregister_preprocessor`.

    # File lib/sprockets/processing.rb, line 107
    def unregister_processor(*args)
      unregister_preprocessor(*args)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.