Skip to content

Commit 5dce5f1

Browse files
committed
i-bem: use skipApplyNext before entering content
Skip all `applyNext()` flags before entering the `content` to support recursive blocks with `applyNext()` (see test).
1 parent 1768daa commit 5dce5f1

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

common.blocks/i-bem/i-bem.bemhtml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ var undef,
1111
},
1212
SHORT_TAGS = { // хэш для быстрого определения, является ли тэг коротким
1313
area : 1, base : 1, br : 1, col : 1, command : 1, embed : 1, hr : 1, img : 1,
14-
input : 1, keygen : 1, link : 1, meta : 1, param : 1, source : 1, wbr : 1 };
14+
input : 1, keygen : 1, link : 1, meta : 1, param : 1, source : 1, wbr : 1 },
15+
skipApplyNext = context.skipApplyNext ||
16+
function noop(ctx, cb) { return cb.call(ctx); };
1517

1618
(function(BEM, undefined) {
1719

@@ -188,6 +190,7 @@ function BEMContext(context, apply_) {
188190
this.elem = undef;
189191
this.mods = undef;
190192
this.elemMods = undef;
193+
this._skipApplyNext = skipApplyNext;
191194
}
192195

193196
BEMContext.prototype.isArray = isArray;
@@ -453,12 +456,14 @@ def()(function() {
453456

454457
var content = apply('content');
455458
if(content || content === 0) {
456-
isBEM = vBlock || this.elem;
457-
apply('', {
458-
_notNewList : false,
459-
position : isBEM? 1 : this.position,
460-
_listLength : isBEM? 1 : this._listLength,
461-
ctx : content
459+
this._skipApplyNext(this, function() {
460+
isBEM = vBlock || this.elem;
461+
apply('', {
462+
_notNewList : false,
463+
position : isBEM? 1 : this.position,
464+
_listLength : isBEM? 1 : this._listLength,
465+
ctx : content
466+
});
462467
});
463468
}
464469

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
block('b1').def()(function() {
2+
return local({ 'ctx.tag': 'span' })(function() {
3+
return applyNext();
4+
});
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="b1"><span class="b1"></span></span>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"block": "b1",
3+
"content": [{
4+
"block": "b1"
5+
}]
6+
}

common.blocks/i-bem/i-bem.test.bemhtml/i-bem-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ suite('i-bem block and others', function() {
4747
unit('boolean mods bem-core/169', 'boolean-mods');
4848
unit('mods redefinition bem-core/441', 'redefine-mods');
4949
unit('mix with same block bem-core/804', 'gh-core-804');
50+
unit('skip apply next when entering content', 'skip-apply-next');
5051
});

0 commit comments

Comments
 (0)