Skip to content

Commit

Permalink
Merge pull request #131 from bem/options
Browse files Browse the repository at this point in the history
Readme: describe `setOptions`
  • Loading branch information
mishanga committed Mar 20, 2015
2 parents 7ca71a7 + e01ef9b commit 3da25bf
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,62 @@ In English:
'block[_blockModifierName[_blockModifierValue]][__elementName][_elementModifierName[_elementModifierValue]]'
```
## Setting up
The `setOptions` method allows you to set the template engine parameters.
### jsAttrName
`jsAttrName` allows you to set the attribute name to store the `js` field. Default value is `onclick`.
```javascript
bh.setOptions({ jsAttrName: 'data-bem' });
bh.apply({ block: 'button', js: true });
```
```html
<div class="button i-bem" data-bem='return {"button":{}}'></div>
```
### jsAttrScheme
The data store format in the attribute. Default value is `js`.
```javascript
bh.setOptions({ jsAttrScheme: 'json' });
bh.apply({ block: 'button', js: { foo: bar } });
```
```html
<div class="button i-bem" onclick='{"button":{"foo":"bar"}}'></div>
```
### jsCls
The name of additional class for nodes with `js`. Default value is `i-bem`. If you set the `false` value, the additional class will not be added.
```javascript
bh.setOptions({ jsCls: false });
bh.apply({ block: 'button', js: true });
```
```html
<div class="button" onclick='{"button":{}}'></div>
```
### escapeContent
`escapeContent` turns on content escaping. Option is turned off by default.
```javascript
bh.setOptions({ escapeContent: true });
bh.apply({ content: '&lt;script&gt;' });

```
```html
<div>&lt;script&gt;</div>
```
## Additional examples
For example, if you want to set `state` modifier with `closed` value for all blocks do the following:
Expand Down Expand Up @@ -236,7 +292,7 @@ bh.match('button', function(ctx) {
## Infinite loop detection
The enableInfiniteLoopDetection method allows you to enable or disable the infinite loop detection process.
The `enableInfiniteLoopDetection` method allows you to enable or disable the infinite loop detection process.
*N.B.* Enable the infinite loop detection in debugging mode only, because it slows down a template engine application.
Expand Down
53 changes: 53 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,59 @@ bh.match('button_pseudo_yes', function(ctx) {
'блок[_имяМодификатораБлока[_значениеМодификатораБлока]][__имяЭлемента][_имяМодификатораЭлемента[_значениеМодификатораЭлемента]]'
```
## Настройка
Метод `setOptions` позволяет задавать параметры шаблонизации.
### jsAttrName
Позволяет задать имя атрибута для хранения поля `js`. Значение по умолчанию — `onclick`.
```javascript
bh.setOptions({ jsAttrName: 'data-bem' });
bh.apply({ block: 'button', js: true });
```
```html
<div class="button i-bem" data-bem='return {"button":{}}'></div>
```
### jsAttrScheme
Формат хранения данных в атрибуте. По умолчанию `js`
```javascript
bh.setOptions({ jsAttrScheme: 'json' });
bh.apply({ block: 'button', js: { foo: bar } });
```
```html
<div class="button i-bem" onclick='{"button":{"foo":"bar"}}'></div>
```
### jsCls
Имя дополнительного класса для узлов, имеющих `js`. По умолчанию `i-bem`.
Если передать значение `false`, дополнительный класс не будет добавляться.
```javascript
bh.setOptions({ jsCls: false });
bh.apply({ block: 'button', js: true });
```
```html
<div class="button" onclick='{"button":{}}'></div>
```
### escapeContent
Включает эскейпинг содержимого. По умолчанию выключен.
```javascript
bh.setOptions({ escapeContent: true });
bh.apply({ content: '<script>' });
```
```html
<div>&lt;script&gt;</div>
```
## Дополнительные примеры
Например, мы хотим установить модификатор `state` со значением `closed` для всех блоков `popup`:
Expand Down

0 comments on commit 3da25bf

Please sign in to comment.