From 9aefb1063ce272477404c4ff4671d8b2d727a1ce Mon Sep 17 00:00:00 2001 From: tenorok Date: Thu, 20 Nov 2014 18:32:26 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D1=83?= =?UTF-8?q?=20=D0=B8=20=D0=B1=D0=BB=D0=BE=D0=BA=D1=83=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/bemerTest.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/bemerTest.js b/test/bemerTest.js index 758e5e0..a163592 100644 --- a/test/bemerTest.js +++ b/test/bemerTest.js @@ -414,6 +414,92 @@ definer('bemerTest', function(assert, bemer, Helpers) { ); }); + describe('Изменение модификатора блока элемента.', function() { + + it('Добавление нового модификатора блоку', function() { + bemer + .match('header__logo', { + mods: { a: 'foo' } + }) + .match('header_a_foo__logo', { + tag: 'header' + }); + assert.equal(bemer({ block: 'header', elem: 'logo' }), + '' + ); + }); + + it('Не нужно выполнять шаблон без модификатора после шаблона с модификатором', function() { + var i = 0; + bemer + .match('header__logo', { + construct: /* istanbul ignore next */ function() { + throw new Error('Excessively execute template'); + }, + tag: 'footer' + }) + .match('header__logo', { + construct: function() {}, + attrs: function() { + var attrs = {}; + attrs['a' + i] = i++; + return attrs; + }, + mods: { a: 'foo' } + }) + .match('header_a_foo__logo', { + tag: 'header' + }); + assert.equal(bemer({ block: 'header', elem: 'logo' }), + '' + ); + }); + + }); + + describe('Изменение модификаторов элементов.', function() { + + it('Добавление нового модификатора', function() { + bemer + .match('header__logo', { + elemMods: { a: 'foo' } + }) + .match('header__logo_a_foo', { + tag: 'header' + }); + assert.equal(bemer({ block: 'header', elem: 'logo' }), + '' + ); + }); + + it('Не нужно выполнять шаблон без модификатора после шаблона с модификатором', function() { + var i = 0; + bemer + .match('header__logo', { + construct: /* istanbul ignore next */ function() { + throw new Error('Excessively execute template'); + }, + tag: 'footer' + }) + .match('header__logo', { + construct: function() {}, + attrs: function() { + var attrs = {}; + attrs['a' + i] = i++; + return attrs; + }, + elemMods: { a: 'foo' } + }) + .match('header__logo_a_foo', { + tag: 'header' + }); + assert.equal(bemer({ block: 'header', elem: 'logo' }), + '' + ); + }); + + }); + }); }); From 6a572944d3c553b9608cbde7e3f60d75ceb0cd4b Mon Sep 17 00:00:00 2001 From: tenorok Date: Thu, 20 Nov 2014 18:42:19 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D0=BA=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=BE=D0=B2=20=D1=8D=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/Pool.js | 3 ++- modules/Template.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/Pool.js b/modules/Pool.js index 123742a..a08ee07 100644 --- a/modules/Pool.js +++ b/modules/Pool.js @@ -125,7 +125,8 @@ definer('Pool', /** @exports Pool */ function(array, object) { processedTemplates.push(this.pool[index]); // Если изменился набор модификаторов, шаблоны нужно прогонять заново. - if(!object.isEqual(currentBemjson.mods || {}, node.bemjson().mods || {})) { + if(!object.isEqual(currentBemjson.mods || {}, node.bemjson().mods) || + !object.isEqual(currentBemjson.elemMods || {}, node.bemjson().elemMods)) { index = this.pool.length; } } diff --git a/modules/Template.js b/modules/Template.js index 19008a9..c19a9ae 100644 --- a/modules/Template.js +++ b/modules/Template.js @@ -115,10 +115,12 @@ definer('Template', /** @exports Template */ function( /* jshint maxparams: fals } if(this._matches[i].is(bemjson)) { - processedMods.push({ - modName: mods.modName, - elemModName: mods.elemModName - }); + if(mods.modName !== '' || mods.elemModName !== '') { + processedMods.push({ + modName: mods.modName, + elemModName: mods.elemModName + }); + } return this.transform(object.clone(bemjson), data, baseBemjson, modesFromAnotherTemplates, index); } } From 61e53ad21aa1fb9b06ebfc53789bd3055265a4e0 Mon Sep 17 00:00:00 2001 From: tenorok Date: Fri, 21 Nov 2014 13:08:26 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=92=20readme=20=D0=BF=D1=80=D0=B8=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D1=8B=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B4=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D1=8F=D1=89=D0=B8=D1=85=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 53d8f05..2bf870a 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,18 @@ bemer({ block: 'header', elem: 'logo' }); ``` +При изменении списка модификаторов автоматически накладываются подходящие шаблоны: +```js +bemer + .match('button', { mods: { theme: 'normal' }}) + .match('button_theme_normal', { tag: 'span' }); +bemer({ block: 'button' }); +``` + +```html + +``` + ###### Поле `elemMods` Тип: `{object}` @@ -521,6 +533,18 @@ bemer({ block: 'header', elem: 'logo' }); ``` +При изменении списка модификаторов автоматически накладываются подходящие шаблоны: +```js +bemer + .match('button__label', { elemMods: { size: 'm' }}) + .match('button__label_size_m', { tag: 'label' }); +bemer({ block: 'button', elem: 'label' }); +``` + +```html + +``` + ###### Поле `mix` Тип: `{array}` From 31bcb2f4e3a213e81448da6e13cff9cd2f3ba43a Mon Sep 17 00:00:00 2001 From: tenorok Date: Fri, 21 Nov 2014 14:07:26 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BD=20travis=20=D0=B8=20coveralls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 18 ++++++++++++++++++ Gruntfile.js | 3 +++ README.md | 3 +++ package.json | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4b67f9c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: node_js + +node_js: + - "0.10" + +branches: + only: + - master + - dev + +install: + - npm install + +script: + - grunt test lint + +after_success: + - grunt coverage coveralls diff --git a/Gruntfile.js b/Gruntfile.js index 36c36cd..e86ab38 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,6 +76,9 @@ module.exports = function(grunt) { root: 'test/tmp/' } } + }, + coveralls: { + src: 'coverage/lcov.info' } }); diff --git a/README.md b/README.md index 2bf870a..6be6cf2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Bemer — БЭМ-шаблонизатор +[![npm version](https://badge.fury.io/js/bemer.svg)](http://badge.fury.io/js/bemer) +[![Build Status](https://travis-ci.org/tenorok/bemer.svg?branch=master)](https://travis-ci.org/tenorok/bemer) +[![Coverage Status](https://img.shields.io/coveralls/tenorok/bemer/master.svg)](https://coveralls.io/r/tenorok/bemer) БЭМ — это методология эффективной разработки веб-приложений. Большое количество информации размещено на официальном сайте [http://ru.bem.info](http://ru.bem.info). diff --git a/package.json b/package.json index 8691143..ba0b225 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "grunt-contrib-uglify": "~0.4.0", "grunt-mocha-istanbul": "~2.1.0", "benchmark": "~1.0.0", - "beautify-benchmark": "~0.2.4" + "beautify-benchmark": "~0.2.4", + "grunt-coveralls": "~1.0.0" } }