Module: Sprockets::Engines

### Home Classes Methods

### In Files

- lib/sprockets/engines.rb

### Methods

- #engine_mime_types
- #engines
- #register_engine

### Included Modules

- 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::Engines

`Engines` provides a global and `Environment` instance registry.

An engine is a type of processor that is bound to a filename extension. `application.js.coffee` indicates that the `CoffeeScriptProcessor` engine will be ran on the file.

Extensions can be stacked and will be evaulated from right to left. `application.js.coffee.erb` will first run `ERBProcessor` then `CoffeeScriptProcessor`.

All `Engine`s must follow the `Template` interface. It is recommended to subclass `Template`.

Its recommended that you register engine changes on your local `Environment` instance.

    environment.register_engine '.foo', FooProcessor

The global registry is exposed for plugins to register themselves.

    Sprockets.register_engine '.sass', SassProcessor

### Public Instance Methods

engine_mime_types() click to toggle source

Internal: Returns a `Hash` of engine extensions to mime types.

# => { '.coffee' => 'application/javascript' }

    # File lib/sprockets/engines.rb, line 44
    def engine_mime_types
      config[:engine_mime_types]
    end

engines() click to toggle source

Returns a `Hash` of `Engine`s registered on the `Environment`. If an `ext` argument is supplied, the `Engine` associated with that extension will be returned.

    environment.engines
    # => {".coffee" => CoffeeScriptProcessor, ".sass" => SassProcessor, ...}

    # File lib/sprockets/engines.rb, line 37
    def engines
      config[:engines]
    end

register_engine(ext, klass, options = {}) click to toggle source

Registers a new Engine `klass` for `ext`. If the `ext` already has an engine registered, it will be overridden.

    environment.register_engine '.coffee', CoffeeScriptProcessor

    # File lib/sprockets/engines.rb, line 53
    def register_engine(ext, klass, options = {})
      ext = Sprockets::Utils.normalize_extension(ext)

      self.computed_config = {}

      if klass.respond_to?(:call)
        processor = klass
        self.config = hash_reassoc(config, :engines) do |engines|
          engines.merge(ext => klass)
        end
        if options[:mime_type]
          self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
            mime_types.merge(ext.to_s => options[:mime_type])
          end
        end
      else
        processor = LegacyTiltProcessor.new(klass)
        self.config = hash_reassoc(config, :engines) do |engines|
          engines.merge(ext => processor)
        end
        if klass.respond_to?(:default_mime_type) && klass.default_mime_type
          self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
            mime_types.merge(ext.to_s => klass.default_mime_type)
          end
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.