Sprockets::Engines

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

An engine is a type of processor that is bound to an filename extension. `application.js.coffee` indicates that the `CoffeeScriptTemplate` 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 `ERBTemplate` then `CoffeeScriptTemplate`.

All `Engine`s must follow the `Tilt::Template` interface. It is recommended to subclass `Tilt::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', SassTemplate

Public Instance Methods

engine_extensions() click to toggle source

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

    environment.engine_extensions
    # => ['.coffee', '.sass', ...]
    # File lib/sprockets/engines.rb, line 54
54:     def engine_extensions
55:       @engines.keys
56:     end
engines(ext = nil) click to toggle source

Returns an `Array` of `Engine`s registered on the `Environment`. If an `ext` argument is supplied, the `Engine` register under that extension will be returned.

    environment.engines
    # => [CoffeeScriptTemplate, SassTemplate, ...]

    environment.engines('.coffee')
    # => CoffeeScriptTemplate
    # File lib/sprockets/engines.rb, line 41
41:     def engines(ext = nil)
42:       if ext
43:         ext = Sprockets::Utils.normalize_extension(ext)
44:         @engines[ext]
45:       else
46:         @engines.dup
47:       end
48:     end
register_engine(ext, klass) 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', CoffeeScriptTemplate
    # File lib/sprockets/engines.rb, line 63
63:     def register_engine(ext, klass)
64:       ext = Sprockets::Utils.normalize_extension(ext)
65:       @engines[ext] = klass
66:     end

Private Instance Methods

deep_copy_hash(hash) click to toggle source
    # File lib/sprockets/engines.rb, line 69
69:       def deep_copy_hash(hash)
70:         initial = Hash.new { |h, k| h[k] = [] }
71:         hash.inject(initial) { |h, (k, a)| h[k] = a.dup; h }
72:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.