Skip to content

Commit

Permalink
Compiler: exportName option (fix for #397)
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Apr 28, 2017
1 parent 578c89a commit 8afc310
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/en/3-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Escaping](#escaping)
- [Runtime linting](#runtime-linting)
- [Production mode](#production-mode)
- [exportName](#exportname-option)
* [Using thirdparty libraries](#using-thirdparty-libraries)
* [Extending BEMContext](#extending-bemcontext)
* [Bundling](#bundling)
Expand Down Expand Up @@ -424,6 +425,14 @@ $ cat stderr.txt
BEMXJST ERROR: cannot render block b1, elem undefined, mods {}, elemMods {} [TypeError: Cannot read property 'undef' of undefined]
```

### exportName option

You can use `exportName` option for choose name of variable where engine will
be exported. By default it’s BEMHTML or BEMTREE.

For example read next.


### Using thirdparty libraries

BEMTREE and BEMHTML allows you using thirdparty libraries as well as a global
Expand Down
26 changes: 24 additions & 2 deletions docs/ru/3-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Экранирование](#Экранирование)
- [Runtime проверки ошибок в шаблонах и входных данных](#runtime-проверки-ошибок-в-шаблонах-и-входных-данных)
- [Режим production](#Режим-production)
- [exportName](#Настройка-exportname)
* [Подключение сторонних библиотек](#Подключение-сторонних-библиотек)
* [Расширение BEMContext](#Расширение-bemcontext)
* [Создание бандла](#Создание-бандла)
Expand Down Expand Up @@ -418,6 +419,13 @@ $ cat stderr.txt
BEMXJST ERROR: cannot render block b1, elem undefined, mods {}, elemMods {} [TypeError: Cannot read property 'undef' of undefined]
```

### Настройка exportName

Вы можете использовать опцию `exportName` чтобы выбрать имя переменной, в
которой будет храниться движок. По умолчанию движки хранятся в BEMHTML и BEMTREE.

За примером обратитесь к следующему разделу, про создание бандла.


## Подключение сторонних библиотек

Expand Down Expand Up @@ -530,13 +538,27 @@ var html = templates.apply(bemjson);

```js
var bemxjst = require('bem-xjst');
var bundle = bemxjst.bemhtml.generate(function() {
var bemhtml = bemxjst.bemhtml;

var fs = require('fs');

var bundle = bemhtml.generate(function() {
// пользовательские шаблоны
// ...

}, { exportName: 'bemhtml8x' });

// Записываем бандл на файловую систему
fs.writeFile('bundle.js', bundle, function(err) {
if (err) return console.error(err);
console.log('Done');
});
```

В `bundle` будет строка, содержащая JS-код ядра BEMHTML и пользовательских шаблонов.
В результате вы получите файл `bundle.js`, в котором будет лежать код движка и
пользовательские шаблоны. Код движка будет доступен в переменной bemhtml8x и
полностью готов к исполению в браузерах, node.js или любой виртуальной машине
JS.

***

Expand Down

0 comments on commit 8afc310

Please sign in to comment.