Anonymous helpers and events for Jade with Coffeescript support

I created an integration between Jade and Coffeescript that makes it easy to develop programs without helpers/events.
Here’s an example:

body
  .container
    header
      h1 Todo List (#{Tasks.find({checked: $ne: true}).count()})
      label.hide-completed(mt-change="Session.set 'hideCompleted', event.target.checked")
        input(type="checkbox" checked="#{Session.get 'hideCompleted'}")
        | Hide Completed Tasks #{testhelper}

You can see the details here: https://atmospherejs.com/xiphy/jade-coffee, or just typing

meteor add xiphy:jade-coffee
2 Likes

Bloody hell, count me in! <3

1 Like

I finally have time to play with it. Unfortunately I fail to make it work.

Let’s say I use your package as follows:

'xiphy:jade-coffee@0.1.1',

I get the following error:

   error: No plugin known to handle file 'showWebsite/showWebsite.coffee.tpl.jade'. If you want this file to be a
   static asset, use addAssets instead of addFiles; eg, api.addAssets('showWebsite/showWebsite.coffee.tpl.jade',
   'client').

It seems I’ve got no package to handle Jade (even if yours is a fork of one). So I add some:

'xiphy:jade-coffee@0.1.1',
'dalgard:jade@0.5.0',

I don’t see the previous error anymore. But the following line:

p #{Websites.find({}).count()}

which is based on your example:

h1 Todo List (#{Tasks.find({checked: $ne: true}).count()})

still gives a following error:

   showWebsite/showWebsite.coffee.tpl.jade: Jade syntax error: Expected IDENTIFIER
   {{Websites.find({}}).count()}

What do I miss? What do I do wrong?

Thanks for the testing!
I added some dependencies so that now I have a good build for Linux as well, I hope.
xiphy:jade-coffee@0.1.4 is the new package, which depends on xiphy:jade-compiler@0.5.1, but it’s incompatible with dalgard:jade and mquandalle:jade (I should probably mark this incompatibility somehow, but I’m new to Meteor packages).
Could you please try it?

Thanks! Yeah I will in few hours, as it’s an important evening here in Poland because of parliament elections.

Too bad it’s a fork of mquandelle:jade instead of dalgard:jade as the latter has few very good advantages over mquandelle’s version, especially the features that were introduced to Blaze with Meteor 1.2.

Yes, my testing environment is Meteor 1.2 on Linux.

The problem is that dalgard added other features as well, like bindings that make it harder to integrate generic coffeescript/javascript, as there are more conflicts between the syntaxes. Still, if there’s enough interest, I may port nice features in the future (and accept pull requests).

What is interesting is that this is a completely different direction from what dalgard is doing, I got rid of helpers and prefer global functions (that is similar to the early Meteor days).

I created some general form processing functions today:

@processForm = (event)->
  r={}
  event.preventDefault()
  _.each event.target, (target)->
      if target.name
          r[target.name]=target.value
  return r

@clearForm = (event)->
  r={}
  event.preventDefault()
  _.each event.target, (target)->
      if target.name
          r[target.name]=target.value
          target.value=''
  return r

With the helper code I am able to simplify form creation to this
:

form.new-contract(
  mt-submit="Tasks.insert clearForm(event)")
  input(type="text" name="text"
   placeholder="Type to add new tasks!")