Skip to content

Commit

Permalink
Merge pull request #488 from bem/issue-487_apply
Browse files Browse the repository at this point in the history
Docs: apply mode without templates (fix for #487)
  • Loading branch information
miripiruni authored Oct 26, 2017
2 parents 0f01a86 + e3d1bdd commit ba102b7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/en/7-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ block('header').tag()(function() {
<header class="header"></header><div class="footer"></div>
```

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
<div class="animal">cat</div>
```

### applyNext

```js
Expand Down
23 changes: 23 additions & 0 deletions docs/ru/7-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ block('header').tag()(function() {
<div class="footer"></div>
```

Если будет вызван `apply()` для режима для которого нет шаблонов, то
шаблонизатор попытается извлечь значение поля с соответствующим названием из
текущего узла BEMJSON-а.

```js
// BEMJSON
{ block: 'animal', type: 'cat' }
```

Шаблон:

```js
block('animal').content()(function() {
return apply('type');
});
```

*Результат шаблонизации:*

```html
<div class="animal">cat</div>
```

### applyNext

```js
Expand Down
9 changes: 9 additions & 0 deletions test/runtime-apply-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit ba102b7

Please sign in to comment.