sstephenson / eco

Embedded CoffeeScript templates
MIT License
1.71k stars 70 forks source link

Document requirement for colon after functions #63

Open andrewhavens opened 11 years ago

andrewhavens commented 11 years ago

I am using Backbone and Eco templates in my Rails application. My template has the following code:

  <% @collection.each (model)-> %>
    <% console.log model.get('name') %>
    <p><%= model.get('name') %></p>
    <p><%= model.get('description') %></p>
  <% end %>

For some reason, the HTML is blank. The name and description are not displayed. However, the console.log method outputs the correct data. What am I doing wrong?

andrewhavens commented 11 years ago

Well I figured out the missing character. Apparently you need a colon after the arrow:

<% @collection.each (model)->: %>

Not sure why this is. It's not a CoffeeScript requirement. None of the code samples in the "blocks and capturing" section of the readme use a colon. Is this a bug, or an undocumented feature?

andrewhavens commented 11 years ago

In case it matters, here are the eco-related version numbers in my Gemfile.lock file:

eco (1.0.0)
  coffee-script
  eco-source
  execjs
eco-source (1.1.0.rc.1)
allenwyma commented 11 years ago

It's not a bug. Whenever you use an if or loop you need a colon at the end and an end keyword to end it. This is how Eco works.

andrewhavens commented 11 years ago

I'm going to change the title of this issue. The issue is really that this isn't fully documented in the readme. I'll try to submit a pull request by the end of the day.

andrewhavens commented 11 years ago

Just submitted pull request #64 to address this issue.