Skip to content

Commit 7b4db25

Browse files
authored
Merge pull request #75 from cossssmin/master
Support multiple tags for loopTags
2 parents 3e2f583 + 331f5e4 commit 7b4db25

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function walk (opts, nodes) {
204204
}
205205

206206
// if the node has content, recurse (unless it's a loop, handled later)
207-
if (node.content && node.tag !== loops[0] && node.tag !== scopes[0]) {
207+
if (node.content && loops.includes(node.tag) === false && node.tag !== scopes[0]) {
208208
node.content = walk(opts, node.content)
209209
}
210210

@@ -318,10 +318,10 @@ function walk (opts, nodes) {
318318
}
319319

320320
// parse loops
321-
if (node.tag === loops[0]) {
321+
if (loops.includes(node.tag)) {
322322
// handle syntax error
323323
if (!(node.attrs && node.attrs.loop)) {
324-
throw new Error(`the "${loops[0]}" tag must have a "loop" attribute`)
324+
throw new Error(`the "${node.tag}" tag must have a "loop" attribute`)
325325
}
326326

327327
// parse the "loop" param

test/expect/loop_customtag.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66

77
<p>2: 3</p>
88

9+
10+
<p>0: 1</p>
11+
12+
<p>1: 2</p>
13+
14+
<p>2: 3</p>
15+
916
<p>x</p>

test/fixtures/loop_customtag.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<p>x</p>
2-
<zeach loop='item, index in items'>
2+
<for loop='item, index in items'>
33
<p>{{index}}: {{item}}</p>
4-
</zeach>
4+
</for>
5+
<each loop='item, index in items'>
6+
<p>{{index}}: {{item}}</p>
7+
</each>
58
<p>x</p>

test/test-loops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test('Loops - conflicting locals', (t) => {
8686

8787
test('Loops - custom tag', (t) => {
8888
return process(t, 'loop_customtag', {
89-
loopTags: ['zeach'],
89+
loopTags: ['for', 'each'],
9090
locals: { items: [1, 2, 3] }
9191
})
9292
})

0 commit comments

Comments
 (0)