Skip to content

Instantly share code, notes, and snippets.

@insin
Created May 6, 2011 12:07
Show Gist options
  • Select an option

  • Save insin/958838 to your computer and use it in GitHub Desktop.

Select an option

Save insin/958838 to your computer and use it in GitHub Desktop.
Leading-vs-trailing commas with a speculative DOM template API
// Which of these would you rather play hunt-the-missing-comma with?
$template({name: 'article_list', extends: 'article_base'},
$block('content',
DIV({'class': 'articles'},
$for('article in articles',
DIV({id: 'article{{ article.id }}'},
H2('{{ article.title }}'),
DIV({'class': 'body'},
$html('{{ article.body }}')
)
),
'In Loop'
),
'Out of Loop'
),
'Out of Element'
)
)
$template({name: 'article_list', extends: 'article_base'}
, $block('content'
, DIV({'class': 'articles'}
, $for('article in articles'
, DIV({id: 'article{{ article.id }}'}
, H2('{{ article.title }}')
, DIV({'class': 'body'}
, $html('{{ article.body }}')
)
)
, 'In Loop'
)
, 'Out of Loop'
)
, 'Out of Element'
)
)
{% extends "article_base.html" %}
{% block content %}
<div class="articles">
{% for article in articles %}
<div id="article{{ article.id }}">
<h2>{{ article.title }}</h2>
<div class="body">
{{ article.text }}
</div>
</div>
In Loop
{% endfor %}
Out of Loop
</div>
Out of Element
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment