Releases: bem/bem-xjst
v6.5.1
Now bem-xjst trim and escape cls
. Example:
// Template:
block('b1').elem('e1').content()(function() {
return JSON.stringify(this.mods);
});
// BEMJSON:
[
{ block: 'b1', cls: '">' },
{ block: 'b2', cls: ' hello ' }
]
Result before fix (v6.5.0):
<div class="b ">"></div>
<div class=" hello "></div>
Result after fix (v6.5.1):
<div class="b ">"></div>
<div class="hello"></div>
v6.5.0
bemhtml.compile()
and bemtree.compile()
should work with arrow functions and function with name and params.
var bemhtml = require('bem-xjst').bemhtml;
var myFunction = function() {
block('page').tag()('body');
};
// myFunction can be in v6.5.0:
// function name() { … }
// function (a, b) { … }
// function name(a, b) { … }
// () => { … }
// (a, b) => { … }
// _ => { … }
var templates = bemhtml.compile(myFunction);
v6.4.3
bem-xjst should not render attrs if it’s not hash. Strings, arrays, and etc.
Example:
// BEMJSON:
{ block: 'b', attrs: [ 1, 2 ] }
Result before fix (v6.4.2):
<div class="b" 0="1" 1="2"></div>
Result after fix (v6.4.3):
<div class="b"></div>
v6.4.2
bem-xjst should not inherit mods from namesake parent block. Example:
// BEMJSON:
{
block: 'b1',
mods: { a: 1 },
content: { block: 'b1' }
}
Result before fix (v6.4.1):
<div class="b1 b1_a_1"><div class="b1_a_1"></div></div>
Result after fix (v6.4.2):
<div class="b1 b1_a_1"><div class="b1"></div></div>
bem-xjst should not match on removed mods. Example:
// Template:
block('b1').mod('a', 'b').replace()(function() {
return {
block: 'b1',
content: 'content'
};
});
// BEMJSON:
{
block: 'b1',
mods: { a: 1 }
}
Result before fix (v6.4.1): endless loop :(
Result after fix (v6.4.2):
<div class="b1">content</div>
- [
3451467c5d
] - bemxjst: should not inheritmods
from namesake parent block (Dmitry Starostin) - [
c2f697f71a
] - We don’t need it anymore (Vasiliy Loginevskiy) - [
ed7624ac91
] - Simple example (miripiruni)
v6.4.1
Bug fixed: in case of same block mods
disappearing. Now bem-xjst keeps it. Example:
// Template:
block('b1').elem('e1').content()(function() {
return JSON.stringify(this.mods);
});
// BEMJSON:
{
block: 'b1',
mods: { a: 1 },
content: { block: 'b1', elem: 'e1' }
}
Result before fix (v6.4.0):
<div class="b1 b1_a_1"><div class="b1__e1">{}</div></div>
Result after fix (v6.4.1):
<div class="b1 b1_a_1"><div class="b1__e1">{"a":1}</div></div>
Now you can pass to bemxjst.compile
named function.
- [
61f21249cf
] - bemjxst: should keepmods
in case of same block (miripiruni) - [
ae5521104c
] - RemoveelemMatch
fix for #260 (miripiruni) - [
af9a35c906
] - Change files in package.js (Vasiliy) - [
274f438116
] - bemxjst.compile: error when passed function with name (Fix #250) (miripiruni)
v6.4.0
New option for content escaping: escapeContent
.
In v6.4.0 escapeContent
is set to false
by default but will be inverted in one of the next major versions.
Example:
You can set escapeContent
option to true
to escape string values of content
field with xmlEscape
.
var bemxjst = require('bem-xjst');
var templates = bemxjst.bemhtml.compile(function() {
// In this example we will add no templates.
// Default behaviour is used for HTML rendering.
}, {
// Turn on content escaping
escapeContent: true
});
var bemjson = {
block: 'danger',
// Danger UGC content
content: ' <script src="alert()"></script>'
};
var html = templates.apply(bemjson);
Result:
<div class="danger">&nbsp;<script src="alert()"></script></div>
If you want avoid escaping in content use special value: { html: '…' }
.
If you already use this.xmlEscape()
on content
values please don’t forget to remove it.
- [
9bdb20479a
] - Merge pull request #217 from bem/escaping2 (Slava Oliyanchuk) - [
9cb7249d03
] - Package name fixed (Slava Oliyanchuk) - [
54d505922b
] - BEMXJST runSimple small refactoring (miripiruni)
6.3.1
Improved error message about no block subpredicate.
Example:
$cat noblock.js
var bemxjst = require('bem-xjst');
var bemhtml = bemxjst.bemhtml;
var templates = bemhtml.compile(function() {
tag()('span');
});
$ node noblock.js
/Users/miripiruni/Documents/www/bem-xjst-errors/lib/compiler.js:59
throw new BEMXJSTError(e.message);
^
BEMXJSTError: block(…) subpredicate is not found.
See template with subpredicates:
* tag()
And template body:
("span")
at _compile (.../lib/compiler.js:60:13)
at Compiler.compile (...//lib/compiler.js:79:3)
at Object.<anonymous> (.../noblock.js:3:25)
…
6.3.0
New option elemJsInstances
for support JS instances for elems (bem-core v4+).
In v6.3.0 elemJsInstances
is set to false
by default but will be inverted in one of the next major versions.
var bemxjst = require('bem-xjst');
var templates = bemxjst.bemhtml.compile(function() {
// In this example we will add no templates.
// Default behaviour is used for HTML rendering.
}, {
// Turn on support for JS instances for elems
elemJsInstances: true
});
var bemjson = {
block: 'b',
elem: 'e',
js: true
};
var html = templates.apply(bemjson);
Result with v6.2.x:
<div class="b__e" data-bem='{"b__e":{}}'></div>
Result with v6.3.0:
<div class="b__e i-bem" data-bem='{"b__e":{}}'></div>
Notice that i-bem
was added.
v6.2.1
- Fixed arrow function support for
replace
,wrap
,once
. - Minor updates: readme, package meta info, authors file, etc.
- [
669db0d7db
] - BEMHTML, BEMTREE added to keywords (Slava Oliyanchuk) - [
abab495e2e
] - README.md: description changed (Slava Oliyanchuk) - [
ac43d023aa
] - Russian comments in README.ru.md (Slava Oliyanchuk) - [
eb56169ddc
] - Pass context to wrap-based matchers and once (Alexey Yaroshevich) - [
369b8543b2
] - Twitter added (Slava Oliyanchuk) - [
a2e4a0716a
] - Twitter added (Slava Oliyanchuk) - [
e51c1fae85
] - Increment year (Slava Oliyanchuk) - [
da3bfecbc8
] - AUTHORS added (miripiruni) - [
7d16b39958
] - package.json: engines field added (miripiruni) - [
7d823dc92d
] - Travis: node 5 added (miripiruni) - [
61f56a6e48
] - keywords, homepage, directories and contributors added (miripiruni)
v.6.2.0
2016-03-24, v6.2.0, @miripiruni
New xhtml
option. Default value is true
. But in next major version we invert it.
xhtml
option allow you to ommit closing slash in void HTML elements (only have a start tag).
Example for v6.2.0:
var bemxjst = require('bem-xjst');
var templates = bemxjst.bemhtml.compile(function() {
// In this example we didn’t add templates
// bem-xjst will render by default
}, {
// Turn off XHTML
xhtml: false
});
var bemjson = { tag: 'br' };
var html = templates.apply(bemjson);
v6.2.0 result:
<br>
v6.1.1 result:
<br/>