parrot
parrot copied to clipboard
Add support for CoffeeScript
This could be easily implemented, we just need to convert the code to real JavaScript after we compiled the input using RegEx.
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
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.
So we'll introduce a new property within the options:
parrot.render(input, {
coffeescript: false, // default
...
});
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.
For CoffeeScript, there's Eco.