From 809292f444cfb3ce131f1266dcc4012546e283cd Mon Sep 17 00:00:00 2001 From: Vladimir Grinenko Date: Tue, 10 Feb 2015 23:53:19 +0300 Subject: [PATCH 1/2] i-bem__html: Support mix of elem with same block Conflicts: blocks-common/i-bem/__html/i-bem__html.bemhtml blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json --- blocks-common/i-bem/__html/i-bem__html.bemhtml | 2 +- .../__html/test/files/i-bem/gh-core-804.html | 1 + .../__html/test/files/i-bem/gh-core-804.json | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html create mode 100644 blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json diff --git a/blocks-common/i-bem/__html/i-bem__html.bemhtml b/blocks-common/i-bem/__html/i-bem__html.bemhtml index 4c047246..2dfc33a3 100644 --- a/blocks-common/i-bem/__html/i-bem__html.bemhtml +++ b/blocks-common/i-bem/__html/i-bem__html.bemhtml @@ -389,7 +389,7 @@ default: { if (!mixItem) continue; - var hasItem = mixItem.block || mixItem.elem, + var hasItem = (mixItem.block && (this.block !== v.block || mixItem.block !== this.block)) || this.elem || mixItem.elem, block = mixItem.block || mixItem._block || this.block, elem = mixItem.elem || mixItem._elem || this.elem, mods = mixItem.mods || this.mods, diff --git a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html new file mode 100644 index 00000000..38ca10fb --- /dev/null +++ b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html @@ -0,0 +1 @@ +
diff --git a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json new file mode 100644 index 00000000..6c8c6c3f --- /dev/null +++ b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json @@ -0,0 +1,18 @@ +[ +{ + "block": "b1", + "mix": { + "block": "b1", + "mods": { "m1": "v1" } + } +}, +{ + "block": "b1", + "elem": "e1", + "mix": [{ "block": "b1" }] +}, +{ + "block": "b1", + "mix": [{ "block": "b1", "elem": "e1" }] +} +] From 8e877d754a13dc32cab7d802c48e9d82e43fdec0 Mon Sep 17 00:00:00 2001 From: restrry Date: Mon, 30 Mar 2015 16:34:28 +0300 Subject: [PATCH 2/2] Add some tests and little fixes --- .../i-bem/__html/i-bem__html.bemhtml | 6 +-- .../test/files/i-bem/gh-core-804.bemhtml | 0 .../__html/test/files/i-bem/gh-core-804.html | 2 +- .../__html/test/files/i-bem/gh-core-804.json | 52 +++++++++++++++++-- blocks-common/i-bem/__html/test/i-bem-test.js | 1 + 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.bemhtml diff --git a/blocks-common/i-bem/__html/i-bem__html.bemhtml b/blocks-common/i-bem/__html/i-bem__html.bemhtml index 2dfc33a3..8e3ac1bd 100644 --- a/blocks-common/i-bem/__html/i-bem__html.bemhtml +++ b/blocks-common/i-bem/__html/i-bem__html.bemhtml @@ -388,13 +388,13 @@ default: { var mixItem = mix[i]; if (!mixItem) continue; - - var hasItem = (mixItem.block && (this.block !== v.block || mixItem.block !== this.block)) || this.elem || mixItem.elem, + var hasItem = (mixItem.block && (this.block !== v.block || mixItem.block !== this.block)) + || (this.elem && (!mixItem.elemMods && !mixItem.mods)) + || mixItem.elem , block = mixItem.block || mixItem._block || this.block, elem = mixItem.elem || mixItem._elem || this.elem, mods = mixItem.mods || this.mods, elemMods = mixItem.elemMods || {}; - hasItem && buf.push(' '); BEM_.INTERNAL[hasItem? 'buildClasses' : 'buildModsClasses']( block, diff --git a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.bemhtml b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.bemhtml new file mode 100644 index 00000000..e69de29b diff --git a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html index 38ca10fb..c61a5c6a 100644 --- a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html +++ b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.html @@ -1 +1 @@ -
+
diff --git a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json index 6c8c6c3f..3c9f2dd0 100644 --- a/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json +++ b/blocks-common/i-bem/__html/test/files/i-bem/gh-core-804.json @@ -7,12 +7,54 @@ } }, { - "block": "b1", - "elem": "e1", - "mix": [{ "block": "b1" }] + "block": "b1", + "mix": {"mods": {"m1": "v1"}} }, { - "block": "b1", - "mix": [{ "block": "b1", "elem": "e1" }] + "block": "b1", + "mix": { + "block": "b2", + "mods": { "m1": "v1" } + } +}, +{ + "block": "b1", + "elem": "e1", + "mix": [{ "block": "b1" }] +}, +{ + "block": "b2", + "mix": [{ "block": "b1", "elem": "e1" }] +}, +{ + "block": "b1", + "mix": {"elem": "e1"} +}, +{ + "block": "b1", + "elem": "e1", + "mix": {"elemMods": {"m1": "v1"}} +}, +{ + "block": "b1", + "elem": "e1", + "mix": {"mods": {"m1": "v1"}} +}, +{ + "block": "b1", + "elem": "e1", + "mix": {"elem": "e2", "elemMods": {"m2": "v2"}} +}, +{ + "block": "b1", + "elem": "e1", + "elemMods": {"m1": "v1"}, + "mix": {"elem": "e2", "elemMods": {"m2": "v2"}} +}, +{ + "block": "b1", + "elem": "e1", + "elemMods": {"m1": "v1"}, + "mix": {"elem": "e2"} } ] diff --git a/blocks-common/i-bem/__html/test/i-bem-test.js b/blocks-common/i-bem/__html/test/i-bem-test.js index ec3462a0..5b6a01ff 100644 --- a/blocks-common/i-bem/__html/test/i-bem-test.js +++ b/blocks-common/i-bem/__html/test/i-bem-test.js @@ -47,6 +47,7 @@ suite('i-bem block and others', function() { unit('simple types regression #254', 'gh-254'); unit('applyNext in content regression #289', 'gh-289'); unit('mods redefinition #550', 'gh-550'); + unit('mix elem on same block', 'gh-core-804'); unit('block with escaping this', 'escaping-this'); test('re-entrance', function() {