ollym / parrot

A lightning fast and lightweight templating engine for Node.js
38 stars 7 forks source link

Add support for CoffeeScript #10

Open e2b opened 11 years ago

e2b commented 11 years ago

This could be easily implemented, we just need to convert the code to real JavaScript after we compiled the input using RegEx.

ollym commented 11 years ago

I agree this should be easy, but it does add a dependency on the CoffeeScript library - not the end of the world! And I think it would be worth it as it would enable stuff like:

<% for key, value in hash %>
  Key: <%= key %>, Value: <%= value %>
<% end %>

And

<% for value in array when value isnt 'Foo' %>
  Value: <%= value %>
<% end %>

Etc. CoffeeScript lends itself quite nicely to templating

e2b commented 11 years ago

parrot is currently a really lightweight module, it has only ~13 kB (uncompressed) as package. coffee-script will add 314 kB (68 kb compressed download). Since it is currently only server-side and I'll only load it with require('coffee-script') if the module is available and requested by the parrot options, it seems acceptable. npm's optionalDependencies is quite suitable. The implementation in parrot is minimal and we could still remove it from the dependencies if the automatic installation is unpleasable.

e2b commented 11 years ago

So we'll introduce a new property within the options:

parrot.render(input, {
  coffeescript: false, // default
  ...
});
e2b commented 11 years ago

Since CoffeeScript is heavily based on indentation, we cannot simply use our current JavaScript procedure. Especially we would have to determine if an inline CoffeeScript statement will increment the indentation level for the following lines. I'm not sure if CoffeeScript is usable at all with this ERB-like way. It doesn't look like inline CoffeeScript is a good idea. Either I'm missing some point or this would require a decent amount of logic if even possible. I'm too new to CoffeeScript to think about this right now, maybe later. Hints are welcome.

So, in short: Nah.

Yuffster commented 11 years ago

For CoffeeScript, there's Eco.