TrevorBurnham/snockets — Issue #12: Make it easier to add template compilers
Author: umairsiddique
Created: 2012-01-29 18:19:20+00:00
State: open

If you are able to add support for issue #11, then we can also have a method for adding template compilers.

```coffeescript
module.exports.compilers = compilers =
template: (name, compiler, namespace = "TEMPLATES") ->
match: /\.js$/
namespace: namespace
compileSync: (sourcePath, source, assetName) ->
"(function() { window.#{@namespace} = window.#{@namespace} || {}; window.#{@namespace}['#{assetName}'] = #{compiler(source, assetName, sourcePath)}; })();"

coffee:
match: /\.js$/
compileSync: (sourcePath, source, assetName) ->
CoffeeScript.compile source, {filename: sourcePath}
```

Then we would be able to add new template compilers like so.

```coffeescript
snockets.compilers.template 'mustache', (source) -> Hogan.compile(source, asString: true)
```

or

```coffeescript
connectAssets.jsCompilers.template 'mustache', (source) -> Hogan.compile(source, asString: true)
```