Skip to content

Commit

Permalink
Docs: production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Oct 10, 2016
1 parent 6ad3d5c commit 3f3169e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/en/3-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Escaping](#escaping)
- [Extending BEMContext](#extending-bemcontext)
- [Runtime linting](#runtime-linting)
- [Production mode](#production-mode)
* [Bundling](#bundling)

## Choosing an engine, compiling and applying templates
Expand Down Expand Up @@ -395,6 +396,35 @@ old value of ctx.mod.one was 1
Notice that you should change this.mods instead of this.ctx.mods in templates
```

### Production mode

You can use option `production` to render whole BEMJSON even if one template contains error.

Example:
```js
var template = bemxjst.compile(function() {
block('b1').attrs()(function() {
var attrs = applyNext();
attrs.undef.foo = 'bar';
return attrs;
});
}, { production: true });
var html = template.apply({ block: 'page', content: { block: 'b1' } });
```
`html` will equals `<div class="page"></div>`.

Also in production mode bem-xjst will produce error messages to STDERR.

```bash
$node index.js 1> stdout.txt 2> stderr.txt

$ cat stdout.txt
<div class="page"></div>

$ cat stderr.txt
BEMXJST ERROR: cannot render block b1, elem undefined, mods {}, elemMods {} [TypeError: Cannot read property 'undef' of undefined]
```


## Bundling

Expand Down
32 changes: 32 additions & 0 deletions docs/ru/3-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Экранирование](#Экранирование)
- [Расширение BEMContext](#Расширение-bemcontext)
- [Runtime проверки ошибок в шаблонах и входных данных](#Runtime-проверки-ошибок-в-шаблонах-и-входных-данных)
- [Режим production](#режим-production)
* [Создание бандла](#Создание-бандла)

## Выбор движка, компиляция и применение шаблонов
Expand Down Expand Up @@ -386,6 +387,37 @@ old value of ctx.mod.one was 1
Notice that you should change this.mods instead of this.ctx.mods in templates
```

### Режим Production

Вы можете использовать опцию `production`, чтобы отрендерить весь BEMJSON,
даже если в одном из шаблонов произошла ошибка.

Пример:
```js
var template = bemxjst.compile(function() {
block('b1').attrs()(function() {
var attrs = applyNext();
attrs.undef.foo = 'bar';
return attrs;
});
}, { production: true });
var html = template.apply({ block: 'page', content: { block: 'b1' } });
```
`html` будет содержать `<div class="page"></div>`.

Если в результате выполнения шаблонов случится ошибка, то узел не будет отрендерен, но шаблонизатор продолжит
работу, выведя в STDERR сообщение об этой ошибке.

```bash
$node index.js 1> stdout.txt 2> stderr.txt

$ cat stdout.txt
<div class="page"></div>

$ cat stderr.txt
BEMXJST ERROR: cannot render block b1, elem undefined, mods {}, elemMods {} [TypeError: Cannot read property 'undef' of undefined]
```


## Создание бандла

Expand Down

0 comments on commit 3f3169e

Please sign in to comment.