diff options
author | Gosha Arinich <me@goshakkk.name> | 2013-01-10 14:00:31 +0300 |
---|---|---|
committer | Gosha Arinich <me@goshakkk.name> | 2013-01-10 14:09:47 +0300 |
commit | 38efe878c9ae66d29300bdfba867eddf84386824 (patch) | |
tree | 014fbd9d68dbdd562866b08f2515ad5daf1c6022 /guides/source | |
parent | ffa9540fd361eb34c445568b66abf283b9e658f8 (diff) | |
download | rails-38efe878c9ae66d29300bdfba867eddf84386824.tar.gz rails-38efe878c9ae66d29300bdfba867eddf84386824.tar.bz2 rails-38efe878c9ae66d29300bdfba867eddf84386824.zip |
add asset pipeline guides section on implementing & registering own engines
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/asset_pipeline.md | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index b302ef76c6..fffa31927d 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -720,7 +720,31 @@ A good example of this is the `jquery-rails` gem which comes with Rails as the s Making Your Library or Gem a Pre-Processor ------------------------------------------ -TODO: Registering gems on [Tilt](https://github.com/rtomayko/tilt) enabling Sprockets to find them. +As Sprockets uses [Tilt](https://github.com/rtomayko/tilt) as a generic +interface to different templating engines, your gem should just +implement the Tilt template protocol. Normally, you would subclass +`Tilt::Template` and reimplement `evaluate` method to return final +output. Template source is stored at `@code`. Have a look at +[`Tilt::Template`](https://github.com/rtomayko/tilt/blob/master/lib/tilt/template.rb) +sources to learn more. + +```ruby +module BangBang + class Template < ::Tilt::Template + # Adds a "!" to original template. + def evaluate(scope, locals, &block) + "#{@code}!" + end + end +end +``` + +Now that you have a `Template` class, it's time to associate it with an +extenstion for template files: + +```ruby +Sprockets.register_engine '.bang', BangBang::Template +``` Upgrading from Old Versions of Rails ------------------------------------ |