From e7b7d13a7c37d716d4c8c3db82df2b000d002419 Mon Sep 17 00:00:00 2001 From: miripiruni Date: Thu, 26 Oct 2017 13:59:47 +0300 Subject: [PATCH 1/2] Docs: apply mode without templates (fix for #487) --- docs/en/7-runtime.md | 22 ++++++++++++++++++++++ docs/ru/7-runtime.md | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/docs/en/7-runtime.md b/docs/en/7-runtime.md index d67aedbb..fc3d6432 100644 --- a/docs/en/7-runtime.md +++ b/docs/en/7-runtime.md @@ -132,6 +132,28 @@ block('header').tag()(function() {
``` +If you try to call `apply()` for mode without templates, engine will lookup a +value of the corresponding field from current BEMJSON node. + +```js +// BEMJSON +{ block: 'animal', type: 'cat' } +``` + +Template: + +```js +block('animal').content()(function() { + return apply('type'); +}); +``` + +*Result of templating:* + +```html +
cat
+``` + ### applyNext ```js diff --git a/docs/ru/7-runtime.md b/docs/ru/7-runtime.md index 88a6940b..db4c8ebf 100644 --- a/docs/ru/7-runtime.md +++ b/docs/ru/7-runtime.md @@ -132,6 +132,29 @@ block('header').tag()(function() { ``` +Если будет вызван `apply()` для режима для которого нет шаблонов, то +шаблонизатор попытается извлечь значение поля с соответствующим названием из +текущего узла BEMJSON-а. + +```js +// BEMJSON +{ block: 'animal', type: 'cat' } +``` + +Шаблон: + +```js +block('animal').content()(function() { + return apply('type'); +}); +``` + +*Результат шаблонизации:* + +```html +
cat
+``` + ### applyNext ```js From e3d1bddc5f10691fc20bee3d7999121837fc0580 Mon Sep 17 00:00:00 2001 From: miripiruni Date: Thu, 26 Oct 2017 14:11:40 +0300 Subject: [PATCH 2/2] Tests: apply() should lookup field from bemjson by default --- test/runtime-apply-test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/runtime-apply-test.js b/test/runtime-apply-test.js index 7fdc571a..bdfb17c1 100644 --- a/test/runtime-apply-test.js +++ b/test/runtime-apply-test.js @@ -94,4 +94,13 @@ describe('Runtime apply()', function() { }, { block: 'b' }, undefined); }); + + it('apply(\'\') should lookup field from bemjson by default', function() { + test(function() { + block('b').def()(function() { + return apply('test'); + }); + }, { block: 'b', test: 'bemjson' }, + 'bemjson'); + }); });