Module: Sprockets::Engines
- Included in:
- Sprockets, Processing
- Defined in:
- lib/sprockets/engines.rb
Overview
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
Instance Method Summary collapse
-
#engine_extensions ⇒ Object
Returns an
Arrayof engine extension ‘String`s. -
#engines(ext = nil) ⇒ Object
Returns an
Arrayof ‘Engine`s registered on theEnvironment. -
#register_engine(ext, klass) ⇒ Object
Registers a new Engine
klassforext.
Instance Method Details
#engine_extensions ⇒ Object
Returns an Array of engine extension ‘String`s.
environment.engine_extensions
# => ['.coffee', '.sass', ...]
54 55 56 |
# File 'lib/sprockets/engines.rb', line 54 def engine_extensions @engines.keys end |
#engines(ext = nil) ⇒ Object
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
41 42 43 44 45 46 47 48 |
# File 'lib/sprockets/engines.rb', line 41 def engines(ext = nil) if ext ext = Sprockets::Utils.normalize_extension(ext) @engines[ext] else @engines.dup end end |
#register_engine(ext, klass) ⇒ Object
Registers a new Engine klass for ext. If the ext already has an engine registered, it will be overridden.
environment.register_engine '.coffee', CoffeeScriptTemplate
63 64 65 66 |
# File 'lib/sprockets/engines.rb', line 63 def register_engine(ext, klass) ext = Sprockets::Utils.normalize_extension(ext) @engines[ext] = klass end |