Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow arbitrary JS expressions in the from part of an each loop.

  • Loading branch information...
commit 936171391dda1a173827012f69cd259b9d2b719c 1 parent df6fc97
@creationix authored
Showing with 18 additions and 3 deletions.
  1. +9 −1 lib/haml.js
  2. +2 −1  test/foreach.haml
  3. +7 −1 test/foreach.html
View
10 lib/haml.js
@@ -204,7 +204,7 @@ if (exports) {
// each loops
{
- regexp: /^(\s*):each\s+(?:([a-z_][a-z_\-]*),\s*)?([a-z_][a-z_\-]*)\s+in\s+([a-z_][a-z_\-]*)(.*)$/i,
+ regexp: /^(\s*):each\s+(?:([a-z_][a-z_\-]*),\s*)?([a-z_][a-z_\-]*)\s+in\s+(.*)(\s*)$/i,
process: function () {
var ivar = this.matches[2] || '__key__', // index
vvar = this.matches[3], // value
@@ -284,6 +284,14 @@ if (exports) {
}
},
+ // Embedded markdown. Needs to be added to exports externally.
+ {
+ regexp: /^(\s*):markdown\s*$/i,
+ process: function () {
+ return exports.Markdown.encode(this.contents.join("\n"));
+ }
+ },
+
// script blocks
{
regexp: /^(\s*):(?:java)?script\s*$/,
View
3  test/foreach.haml
@@ -6,4 +6,5 @@
:each name, value in item
%dt&= name
%dd&= value
-
+:each number in [1,2,3,4,5,6,7]
+ = number
View
8 test/foreach.html
@@ -5,4 +5,10 @@
</dt><dd>Tim Caswell
</dd><dt>age
</dt><dd>27
-</dd></dl>
+</dd></dl>1
+2
+3
+4
+5
+6
+7
Please sign in to comment.
Something went wrong with that request. Please try again.