pthrasher / snockets

Sprockets-style script concatenation for Node
119 stars 39 forks source link

Make it easier to add template compilers #12

Closed umairsiddique closed 11 years ago

umairsiddique commented 12 years ago

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

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.

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

or

connectAssets.jsCompilers.template 'mustache', (source) -> Hogan.compile(source, asString: true)
pthrasher commented 11 years ago

I like the idea. I'll consider this in some form or another for the next release.