Skip to content

Commit 3bea557

Browse files
authored
Merge pull request #807 from ashkulz/doc_extending_sprockets_erb
document how to chain ERB for custom processors
2 parents 5b040f3 + 54103c5 commit 3bea557

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

guides/extending_sprockets.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,13 @@ Sprockets.register_preprocessor 'text/coffeescript', DirectiveProcessor.new(comm
292292

293293
In Sprockets 4 file types are no longer "chainable" this means that if you wanted to use a `.coffee.erb` that it must be registered to sprockets explicitly. This is different from previous versions of sprockets where you would have to register only a `.erb` processor and then a `.coffee` processor and sprockets would chain them (first running erb then coffee).
294294

295-
The reason for the change is to have more explicit behavior. It helps sprockets know to do the right thing, decreases magic, and increases speed. It also means that as a library maintainer you must tell sprockets all the extensions you want your project to work with. Going with the coffee script example. You would need to register a mime type
295+
The reason for the change is to have more explicit behavior. It helps sprockets know to do the right thing, decreases magic, and increases speed. It also means that as a library maintainer you must tell sprockets all the extensions you want your project to work with. Going with the coffee script example:
296296

297-
<!---
298-
Right now sprockets uses an "internal interface" to register erb files. I'm not actually sure how to register support for an ERB file correctly without using that interface, need to do more research
299-
300-
```
301-
env.register_mime_type 'text/coffeescript+ruby', extensions: ['.coffee.erb', '.js.coffee.erb']
302-
303-
env.register_mime_type 'text/coffeescript', extensions: ['.coffee', '.js.coffee']
304-
env.register_transformer 'text/coffeescript', 'application/javascript', CoffeeScriptProcessor
305-
env.register_preprocessor 'text/coffeescript', DirectiveProcessor.new(comments: ["#", ["###", "###"]])
297+
```ruby
298+
Sprockets.register_mime_type('text/coffeescript+ruby', extensions: ['.coffee.erb'])
299+
Sprockets.register_transformer('text/coffeescript+ruby', 'text/coffeescript', ::Sprockets::CoffeeScriptProcessor)
306300
```
307301

308-
-->
309-
310302
## Supporting All Versions of Sprockets in Processors
311303

312304
If you are extending sprockets you may want to support all current major versions of sprockets (2, 3, and 4). The processor interface was deprecated from Sprockets 2 and a legacy shim was put into Sprockets 3. Now that Sprockets 4 is out that shim no longer is active, so you'll need to update your gem to either only use the new interface or use both interfaces. For example:

0 commit comments

Comments
 (0)