From b1dc50c621b5659cff33daa4dd3f210b67cf25e1 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 5 Mar 2015 13:17:49 -0500 Subject: [PATCH 1/2] i-bem: use resetApplyNext before entering `content` Skip all `applyNext()` flags before entering the `content` to support recursive blocks with `applyNext()` (see test). --- common.blocks/i-bem/i-bem.bemhtml | 5 +- common.blocks/i-bem/i-bem.bemtree | 5 +- .../files/i-bem/reset-apply-next.bemhtml | 5 ++ .../files/i-bem/reset-apply-next.html | 1 + .../files/i-bem/reset-apply-next.json | 6 +++ .../i-bem/i-bem.test.bemhtml/i-bem-test.js | 1 + common.blocks/page/page.bemhtml | 54 +++++++++---------- 7 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.bemhtml create mode 100644 common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.html create mode 100644 common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.json diff --git a/common.blocks/i-bem/i-bem.bemhtml b/common.blocks/i-bem/i-bem.bemhtml index 47121a81a..ae89a63b8 100644 --- a/common.blocks/i-bem/i-bem.bemhtml +++ b/common.blocks/i-bem/i-bem.bemhtml @@ -11,7 +11,8 @@ var undef, }, SHORT_TAGS = { // хэш для быстрого определения, является ли тэг коротким area : 1, base : 1, br : 1, col : 1, command : 1, embed : 1, hr : 1, img : 1, - input : 1, keygen : 1, link : 1, meta : 1, param : 1, source : 1, wbr : 1 }; + input : 1, keygen : 1, link : 1, meta : 1, param : 1, source : 1, wbr : 1 }, + resetApplyNext = context.resetApplyNext || function() {}; (function(BEM, undefined) { @@ -179,6 +180,7 @@ function BEMContext(context, apply_) { this.elem = undef; this.mods = undef; this.elemMods = undef; + this._resetApplyNext = resetApplyNext; } BEMContext.prototype.isArray = isArray; @@ -459,6 +461,7 @@ def()(function() { var content = apply('content'); if(content || content === 0) { + this._resetApplyNext(this); isBEM = vBlock || this.elem; apply('', { _notNewList : false, diff --git a/common.blocks/i-bem/i-bem.bemtree b/common.blocks/i-bem/i-bem.bemtree index 01b88ee47..5f22cbd64 100644 --- a/common.blocks/i-bem/i-bem.bemtree +++ b/common.blocks/i-bem/i-bem.bemtree @@ -15,7 +15,8 @@ var undef, r = new RegExp(r, 'g'); return function(s) { return ('' + s).replace(r, f); }; }; - })(); + })(), + resetApplyNext = context.resetApplyNext || function() {}; context.BEMContext = BEMContext; @@ -32,6 +33,7 @@ function BEMContext(context, apply_) { this.elem = undef; this.mods = undef; this.elemMods = undef; + this._resetApplyNext = resetApplyNext; } BEMContext.prototype.isArray = isArray; @@ -152,6 +154,7 @@ match(this._mode === '')( def()(function() { var content = apply('content'); if(content || content === 0) { + this._resetApplyNext(this); this.ctx.content = apply('', { ctx : content }); } return this.ctx; diff --git a/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.bemhtml b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.bemhtml new file mode 100644 index 000000000..7ff355ad9 --- /dev/null +++ b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.bemhtml @@ -0,0 +1,5 @@ +block('b1').def()(function() { + return local({ 'ctx.tag': 'span' })(function() { + return applyNext(); + }); +}); diff --git a/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.html b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.html new file mode 100644 index 000000000..708622c3f --- /dev/null +++ b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.html @@ -0,0 +1 @@ + diff --git a/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.json b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.json new file mode 100644 index 000000000..fe5437aae --- /dev/null +++ b/common.blocks/i-bem/i-bem.test.bemhtml/files/i-bem/reset-apply-next.json @@ -0,0 +1,6 @@ +{ + "block": "b1", + "content": { + "block": "b1" + } +} diff --git a/common.blocks/i-bem/i-bem.test.bemhtml/i-bem-test.js b/common.blocks/i-bem/i-bem.test.bemhtml/i-bem-test.js index 881c7f14b..2f19a94c5 100644 --- a/common.blocks/i-bem/i-bem.test.bemhtml/i-bem-test.js +++ b/common.blocks/i-bem/i-bem.test.bemhtml/i-bem-test.js @@ -49,4 +49,5 @@ suite('i-bem block and others', function() { unit('mix with same block bem-core/804', 'gh-core-804'); unit('nested mix as object bem-core/873', 'gh-core-873'); unit('string mix', 'string-mix'); + unit('reset apply next when entering content', 'reset-apply-next'); }); diff --git a/common.blocks/page/page.bemhtml b/common.blocks/page/page.bemhtml index ea02eee37..1839a359f 100644 --- a/common.blocks/page/page.bemhtml +++ b/common.blocks/page/page.bemhtml @@ -1,37 +1,33 @@ block('page')( - def()(function() { + def().match(function() { return !this._pageInit; })(function() { var ctx = this.ctx; this._nonceCsp = ctx.nonce; - return applyCtx([ - ctx.doctype || '', - { - tag : 'html', - cls : 'ua_js_no', - content : [ - { - elem : 'head', - content : [ - { tag : 'meta', attrs : { charset : 'utf-8' } }, - ctx.uaCompatible === false? '' : { - tag : 'meta', - attrs : { - 'http-equiv' : 'X-UA-Compatible', - content : ctx.uaCompatible || 'IE=edge' - } - }, - { tag : 'title', content : ctx.title }, - { block : 'ua', attrs : { nonce : ctx.nonce } }, - ctx.head, - ctx.styles, - ctx.favicon? { elem : 'favicon', url : ctx.favicon } : '' - ] - }, - ctx - ] - } - ]); + // TODO(indunty): remove local after bem/bem-xjst#50 + return local({ _pageInit : true })(function() { + return applyCtx([ + ctx.doctype || '', + { + tag : 'html', + cls : 'ua_js_no', + content : [ + { + elem : 'head', + content : [ + { tag : 'meta', attrs : { charset : 'utf-8' } }, + { tag : 'title', content : ctx.title }, + { block : 'ua' }, + ctx.head, + ctx.styles, + ctx.favicon? { elem : 'favicon', url : ctx.favicon } : '' + ] + }, + ctx + ] + } + ]); + }); }), tag()('body'), From 4086fdfc4ff9e260ca0f2abdeaa495c9ab4edf3f Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sun, 5 Jul 2015 16:26:31 -0700 Subject: [PATCH 2/2] fix --- common.blocks/page/page.bemhtml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common.blocks/page/page.bemhtml b/common.blocks/page/page.bemhtml index 1839a359f..dbcacc0d8 100644 --- a/common.blocks/page/page.bemhtml +++ b/common.blocks/page/page.bemhtml @@ -16,8 +16,15 @@ block('page')( elem : 'head', content : [ { tag : 'meta', attrs : { charset : 'utf-8' } }, + ctx.uaCompatible === false? '' : { + tag : 'meta', + attrs : { + 'http-equiv' : 'X-UA-Compatible', + content : ctx.uaCompatible || 'IE=edge' + } + }, { tag : 'title', content : ctx.title }, - { block : 'ua' }, + { block : 'ua', attrs : { nonce : ctx.nonce } }, ctx.head, ctx.styles, ctx.favicon? { elem : 'favicon', url : ctx.favicon } : ''