parrot icon indicating copy to clipboard operation
parrot copied to clipboard

Add support for CoffeeScript

Open e2b opened this issue 12 years ago • 5 comments

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

e2b avatar Jan 28 '13 16:01 e2b

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

ollym avatar Jan 28 '13 17:01 ollym

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 avatar Jan 28 '13 19:01 e2b

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

parrot.render(input, {
  coffeescript: false, // default
  ...
});

e2b avatar Feb 04 '13 18:02 e2b

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.

e2b avatar Mar 06 '13 22:03 e2b

For CoffeeScript, there's Eco.

Yuffster avatar Mar 21 '13 21:03 Yuffster