Module: Sprockets::Processing

### Home Classes Methods

### In Files

- lib/sprockets/processing.rb

### Methods

- #build_processors_uri
- #bundle_processors
- #default_processors_for
- #pipelines
- #postprocessors
- #preprocessors
- #processors
- #processors_for
- #register_bundle_metadata_reducer
- #register_bundle_processor
- #register_pipeline
- #register_postprocessor
- #register_preprocessor
- #register_processor
- #resolve_processors_cache_key_uri
- #self_processors_for
- #unregister_bundle_processor
- #unregister_postprocessor
- #unregister_preprocessor
- #unregister_processor

### Included Modules

- Sprockets::ProcessorUtils
- Sprockets::URIUtils
- Sprockets::Utils

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::Autoload
- Sprockets::Base
- Sprockets::Bower
- Sprockets::Bundle
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Cache::GetWrapper
- Sprockets::Cache::HashWrapper
- Sprockets::Cache::MemoryStore
- Sprockets::Cache::NullStore
- Sprockets::Cache::ReadWriteWrapper
- Sprockets::Cache::Wrapper
- Sprockets::CachedEnvironment
- Sprockets::ClosureCompressor
- Sprockets::CoffeeScriptProcessor
- Sprockets::CoffeeScriptTemplate
- Sprockets::Compressing
- Sprockets::Configuration
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::ConversionError
- Sprockets::Dependencies
- Sprockets::DigestUtils
- Sprockets::DirectiveProcessor
- Sprockets::ERBProcessor
- Sprockets::ERBTemplate
- Sprockets::EcoProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsProcessor
- Sprockets::EjsTemplate
- Sprockets::EncodingUtils
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::FileReader
- Sprockets::HTTPUtils
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::LegacyProcProcessor
- Sprockets::LegacyTiltProcessor
- Sprockets::Loader
- Sprockets::Manifest
- Sprockets::ManifestUtils
- Sprockets::Mime
- Sprockets::NotFound
- Sprockets::NotImplementedError
- Sprockets::PathDependencyUtils
- Sprockets::PathDigestUtils
- Sprockets::PathUtils
- Sprockets::Paths
- Sprockets::Processing
- Sprockets::ProcessorUtils
- Sprockets::Resolve
- Sprockets::SassCompressor
- Sprockets::SassProcessor
- Sprockets::SassProcessor::CacheStore
- Sprockets::SassProcessor::Functions
- Sprockets::SassTemplate
- Sprockets::ScssProcessor
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::Transformers
- Sprockets::URITar
- Sprockets::URIUtils
- Sprockets::UglifierCompressor
- Sprockets::UnloadedAsset
- 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 `CachedEnvironment` classes.

### Public Instance Methods

bundle_processors() click to toggle source

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

    # File lib/sprockets/processing.rb, line 88
    def bundle_processors
      config[:bundle_processors]
    end

pipelines() click to toggle source

    # File lib/sprockets/processing.rb, line 16
    def pipelines
      config[:pipelines]
    end

postprocessors() click to toggle source

Postprocessors are ran after Preprocessors and Engine processors.

    # File lib/sprockets/processing.rb, line 36
    def postprocessors
      config[:postprocessors]
    end

preprocessors() click to toggle source

Preprocessors are ran before Postprocessors and Engine processors.

    # File lib/sprockets/processing.rb, line 30
    def preprocessors
      config[:preprocessors]
    end

Also aliased as: processors
processors() click to toggle source
Alias for: preprocessors
register_bundle_metadata_reducer(mime_type, key, *args, &block) click to toggle source

Public: Register bundle metadata reducer function.

Examples

    Sprockets.register_bundle_metadata_reducer 'application/javascript', :jshint_errors, [], :+

    Sprockets.register_bundle_metadata_reducer 'text/css', :selector_count, 0 { |total, count|
      total + count
    }

mime_type - String MIME Type. Use '/' applies to all types. key - Symbol metadata key initial - Initial memo to pass to the reduce funciton (default: nil) block - Proc accepting the memo accumulator and current value

Returns nothing.

    # File lib/sprockets/processing.rb, line 130
    def register_bundle_metadata_reducer(mime_type, key, *args, &block)
      case args.size
      when 0
        reducer = block
      when 1
        if block_given?
          initial = args[0]
          reducer = block
        else
          initial = nil
          reducer = args[0].to_proc
        end
      when 2
        initial = args[0]
        reducer = args[1].to_proc
      else
        raise ArgumentError, "wrong number of arguments (#{args.size} for 0..2)"
      end

      self.config = hash_reassoc(config, :bundle_reducers, mime_type) do |reducers|
        reducers.merge(key => [initial, reducer])
      end
    end

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

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

    register_bundle_processor  'application/javascript', Sprockets::DirectiveProcessor

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

    register_bundle_processor 'application/javascript', :my_processor do |context, data|
      data.gsub(...)
    end

    # File lib/sprockets/processing.rb, line 102
    def register_bundle_processor(*args, &block)
      register_config_processor(:bundle_processors, *args, &block)
    end

register_pipeline(name, proc = nil, &block) click to toggle source

    # File lib/sprockets/processing.rb, line 20
    def register_pipeline(name, proc = nil, &block)
      proc ||= block

      self.config = hash_reassoc(config, :pipelines) do |pipelines|
        pipelines.merge(name.to_sym => proc)
      end
    end

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

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

    register_postprocessor 'application/javascript', Sprockets::DirectiveProcessor

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

    register_postprocessor 'application/javascript', :my_processor do |context, data|
      data.gsub(...)
    end

    # File lib/sprockets/processing.rb, line 65
    def register_postprocessor(*args, &block)
      register_config_processor(:postprocessors, *args, &block)
    end

register_preprocessor(*args, &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 50
    def register_preprocessor(*args, &block)
      register_config_processor(:preprocessors, *args, &block)
    end

Also aliased as: register_processor
register_processor(*args, &block) click to toggle source
Alias for: register_preprocessor
unregister_bundle_processor(*args) click to toggle source

Remove Bundle Processor `klass` for `mime_type`.

    unregister_bundle_processor 'application/javascript', Sprockets::DirectiveProcessor

    # File lib/sprockets/processing.rb, line 110
    def unregister_bundle_processor(*args)
      unregister_config_processor(:bundle_processors, *args)
    end

unregister_postprocessor(*args) click to toggle source

Remove Postprocessor `klass` for `mime_type`.

    unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor

    # File lib/sprockets/processing.rb, line 82
    def unregister_postprocessor(*args)
      unregister_config_processor(:postprocessors, *args)
    end

unregister_preprocessor(*args) click to toggle source

Remove Preprocessor `klass` for `mime_type`.

    unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor

    # File lib/sprockets/processing.rb, line 73
    def unregister_preprocessor(*args)
      unregister_config_processor(:preprocessors, *args)
    end

Also aliased as: unregister_processor
unregister_processor(*args) click to toggle source
Alias for: unregister_preprocessor

### Protected Instance Methods

build_processors_uri(type, file_type, engine_extnames, pipeline) click to toggle source

    # File lib/sprockets/processing.rb, line 162
    def build_processors_uri(type, file_type, engine_extnames, pipeline)
      engines = engine_extnames.join(',') if engine_extnames.any?
      query = encode_uri_query_params(
        type: type,
        file_type: file_type,
        engines: engines,
        pipeline: pipeline
      )
      "processors:#{query}"
    end

default_processors_for(type, file_type, engine_extnames) click to toggle source

    # File lib/sprockets/processing.rb, line 178
    def default_processors_for(type, file_type, engine_extnames)
      bundled_processors = config[:bundle_processors][type]
      if bundled_processors.any?
        bundled_processors
      else
        self_processors_for(type, file_type, engine_extnames)
      end
    end

processors_for(type, file_type, engine_extnames, pipeline) click to toggle source

    # File lib/sprockets/processing.rb, line 173
    def processors_for(type, file_type, engine_extnames, pipeline)
      pipeline ||= :default
      config[:pipelines][pipeline.to_sym].call(self, type, file_type, engine_extnames)
    end

resolve_processors_cache_key_uri(uri) click to toggle source

    # File lib/sprockets/processing.rb, line 155
    def resolve_processors_cache_key_uri(uri)
      params = parse_uri_query_params(uri[11..-1])
      params[:engine_extnames] = params[:engines] ? params[:engines].split(',') : []
      processors = processors_for(params[:type], params[:file_type], params[:engine_extnames], params[:pipeline])
      processors_cache_keys(processors)
    end

self_processors_for(type, file_type, engine_extnames) click to toggle source

    # File lib/sprockets/processing.rb, line 187
    def self_processors_for(type, file_type, engine_extnames)
      processors = []

      processors.concat config[:postprocessors][type]

      if type != file_type && processor = config[:transformers][file_type][type]
        processors << processor
      end

      processors.concat engine_extnames.map { |ext| engines[ext] }
      processors.concat config[:preprocessors][file_type]

      if processors.any? || mime_type_charset_detecter(type)
        processors << FileReader
      end

      processors
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.