craigspaeth / nap

Compile, manage, & package stylesheets, javascripts, and javascript templates for node.js
MIT License
122 stars 33 forks source link

Precompiling mixed handlebars and jade templates #51

Closed ragulka closed 11 years ago

ragulka commented 11 years ago

I'm mixing jade with handlebars so that I don't have to write HTML. For example, I have a template called invoices/invoicerow.handlebars.jade and it looks like this:

tr
  td.title {{title}}
  td.price {{price}}
  td.quantity {{quantity}}
  td.discountRate {{discountRate}}
  td.taxRate {{taxRate}}
  td.total {{total}}

I have extended nap templateParses with this function:

nap.templateParsers['.handlebars.jade'] = function(contents) {
  contents = jade.compile(contents);
  return "Handlebars.template(" + Handlebars.precompile( contents ) + ")";
};

The only problem is that my .handlebars.jade templates are just being compiled into jade - and it happens because nap is extracting the extension from the template filenames: https://github.com/craigspaeth/nap/blob/master/lib/nap.coffee#L270

Now, I could just use a custom file extension for my case, but that would mean that I lose syntax highlighting and I do not like the semantics of something like template.hbsjade

One solution would be to check if the filename ends with one of the extensions that the templateParses use, moving from more specific to less specific (ie check .handlebars.jade first, then .jade) and choose the template parser accordingly.

I'm not sure if this is something that You want to support, but I think it would be nice.

ragulka commented 11 years ago

I have added support for combined template in this pull requests, there is also a test for .mustache.jade. Please let me know your thoughts.

ragulka commented 11 years ago

I'm going to close this pull request as I accidentally issued this from my master branch. I will create a new pull request from a topic branch soon.