Skip to content

Commit b1dc50c

Browse files
committed
i-bem: use resetApplyNext before entering content
Skip all `applyNext()` flags before entering the `content` to support recursive blocks with `applyNext()` (see test).
1 parent 42e7590 commit b1dc50c

File tree

7 files changed

+46
-31
lines changed

7 files changed

+46
-31
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ 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+
resetApplyNext = context.resetApplyNext || function() {};
1516

1617
(function(BEM, undefined) {
1718

@@ -179,6 +180,7 @@ function BEMContext(context, apply_) {
179180
this.elem = undef;
180181
this.mods = undef;
181182
this.elemMods = undef;
183+
this._resetApplyNext = resetApplyNext;
182184
}
183185

184186
BEMContext.prototype.isArray = isArray;
@@ -459,6 +461,7 @@ def()(function() {
459461

460462
var content = apply('content');
461463
if(content || content === 0) {
464+
this._resetApplyNext(this);
462465
isBEM = vBlock || this.elem;
463466
apply('', {
464467
_notNewList : false,

common.blocks/i-bem/i-bem.bemtree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var undef,
1515
r = new RegExp(r, 'g');
1616
return function(s) { return ('' + s).replace(r, f); };
1717
};
18-
})();
18+
})(),
19+
resetApplyNext = context.resetApplyNext || function() {};
1920

2021
context.BEMContext = BEMContext;
2122

@@ -32,6 +33,7 @@ function BEMContext(context, apply_) {
3233
this.elem = undef;
3334
this.mods = undef;
3435
this.elemMods = undef;
36+
this._resetApplyNext = resetApplyNext;
3537
}
3638

3739
BEMContext.prototype.isArray = isArray;
@@ -152,6 +154,7 @@ match(this._mode === '')(
152154
def()(function() {
153155
var content = apply('content');
154156
if(content || content === 0) {
157+
this._resetApplyNext(this);
155158
this.ctx.content = apply('', { ctx : content });
156159
}
157160
return this.ctx;
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
@@ -49,4 +49,5 @@ suite('i-bem block and others', function() {
4949
unit('mix with same block bem-core/804', 'gh-core-804');
5050
unit('nested mix as object bem-core/873', 'gh-core-873');
5151
unit('string mix', 'string-mix');
52+
unit('reset apply next when entering content', 'reset-apply-next');
5253
});

common.blocks/page/page.bemhtml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
block('page')(
22

3-
def()(function() {
3+
def().match(function() { return !this._pageInit; })(function() {
44
var ctx = this.ctx;
55
this._nonceCsp = ctx.nonce;
66

7-
return applyCtx([
8-
ctx.doctype || '<!DOCTYPE html>',
9-
{
10-
tag : 'html',
11-
cls : 'ua_js_no',
12-
content : [
13-
{
14-
elem : 'head',
15-
content : [
16-
{ tag : 'meta', attrs : { charset : 'utf-8' } },
17-
ctx.uaCompatible === false? '' : {
18-
tag : 'meta',
19-
attrs : {
20-
'http-equiv' : 'X-UA-Compatible',
21-
content : ctx.uaCompatible || 'IE=edge'
22-
}
23-
},
24-
{ tag : 'title', content : ctx.title },
25-
{ block : 'ua', attrs : { nonce : ctx.nonce } },
26-
ctx.head,
27-
ctx.styles,
28-
ctx.favicon? { elem : 'favicon', url : ctx.favicon } : ''
29-
]
30-
},
31-
ctx
32-
]
33-
}
34-
]);
7+
// TODO(indunty): remove local after bem/bem-xjst#50
8+
return local({ _pageInit : true })(function() {
9+
return applyCtx([
10+
ctx.doctype || '<!DOCTYPE html>',
11+
{
12+
tag : 'html',
13+
cls : 'ua_js_no',
14+
content : [
15+
{
16+
elem : 'head',
17+
content : [
18+
{ tag : 'meta', attrs : { charset : 'utf-8' } },
19+
{ tag : 'title', content : ctx.title },
20+
{ block : 'ua' },
21+
ctx.head,
22+
ctx.styles,
23+
ctx.favicon? { elem : 'favicon', url : ctx.favicon } : ''
24+
]
25+
},
26+
ctx
27+
]
28+
}
29+
]);
30+
});
3531
}),
3632

3733
tag()('body'),

0 commit comments

Comments
 (0)