Skip to content

Commit

Permalink
Merge pull request rails#8869 from goshakkk/guides-asset-pipeline-tilt
Browse files Browse the repository at this point in the history
Add asset pipeline guides section on implementing & registering own engines
  • Loading branch information
guilleiguaran committed Jan 10, 2013
2 parents 5be6fa5 + 38efe87 commit 34126fa
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion guides/source/asset_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------------
Expand Down

0 comments on commit 34126fa

Please sign in to comment.