@@ -26,8 +26,8 @@ var bemxjst = require('bem-xjst');
26
26
var bemhtml = bemxjst .bemhtml ;
27
27
28
28
// Add a template
29
- var templates = bemhtml .compile (function () {
30
- block (' quote' ). tag ()( ' q' );
29
+ var templates = bemhtml .compile (() => {
30
+ block (' quote' )({ tag : ' q' } );
31
31
});
32
32
33
33
// Add data
@@ -50,14 +50,16 @@ var bemxjst = require('bem-xjst');
50
50
var bemtree = bemxjst .bemtree ;
51
51
52
52
// Add a template
53
- var templates = bemtree .compile (function () {
54
- block (' phone' ).content ()({ mask: ' 8-800-×××-××-××' , mandatory: true });
55
-
56
- block (' page' ).content ()([
57
- { block: ' header' },
58
- { block: ' body' },
59
- { block: ' footer' }
60
- ]);
53
+ var templates = bemtree .compile (() => {
54
+ block (' phone' )({ content: { mask: ' 8-800-×××-××-××' , mandatory: true } });
55
+
56
+ block (' page' )({
57
+ content: [
58
+ { block: ' header' }
59
+ { block: ' body' },
60
+ { block: ' footer' }
61
+ ]
62
+ });
61
63
});
62
64
63
65
// Add data
@@ -93,8 +95,8 @@ To add templates to the `templates` instance, use the `compile` method.
93
95
var bemxjst = require (' bem-xjst' );
94
96
95
97
// Instantiating the 'templates' class
96
- var templates = bemxjst .bemhtml .compile (function () {
97
- block (' header' ). tag ()( ' h1' );
98
+ var templates = bemxjst .bemhtml .compile (() => {
99
+ block (' header' )({ tag : ' h1' } );
98
100
});
99
101
100
102
// Add data
@@ -105,7 +107,7 @@ var html = templates.apply(bemjson);
105
107
106
108
// Add templates to the created instance of the 'templates' class
107
109
templates .compile (function () {
108
- block (' header' ). tag ()( ' h2' );
110
+ block (' header' )({ tag : ' h2' } );
109
111
});
110
112
111
113
html = templates .apply (bemjson);
@@ -121,7 +123,7 @@ If you need to [bundle](https://en.bem.info/methodology/build/#build-results) al
121
123
122
124
``` js
123
125
var bemxjst = require (' bem-xjst' );
124
- var templates = bemxjst .bemhtml .compile (function () {
126
+ var templates = bemxjst .bemhtml .compile (() => {
125
127
// This example doesn’t add any templates.
126
128
// HTML will be rendered using the default behavior of the template engine.
127
129
}, {
@@ -158,7 +160,7 @@ bem-xjst have `elemJsInstances` option for support JS instances for elems ([bem-
158
160
159
161
``` js
160
162
var bemxjst = require (' bem-xjst' );
161
- var templates = bemxjst .bemhtml .compile (function () {
163
+ var templates = bemxjst .bemhtml .compile (() => {
162
164
// In this example we will add no templates.
163
165
// Default behaviour is used for HTML rendering.
164
166
}, {
@@ -199,7 +201,7 @@ Example for v6.2.0:
199
201
200
202
``` js
201
203
var bemxjst = require (' bem-xjst' );
202
- var templates = bemxjst .bemhtml .compile (function () {
204
+ var templates = bemxjst .bemhtml .compile (() => {
203
205
// In this example we didn’t add templates
204
206
// bem-xjst will render by default
205
207
}, {
@@ -228,7 +230,7 @@ You can find list of optional end tags in specifications:
228
230
229
231
``` js
230
232
var bemxjst = require (' bem-xjst' );
231
- var templates = bemxjst .bemhtml .compile (function () {
233
+ var templates = bemxjst .bemhtml .compile (() => {
232
234
// In this example we will add no templates.
233
235
// Default behaviour is used for HTML rendering.
234
236
}, {
@@ -266,7 +268,7 @@ You can use `unquotedAttrs` option to do so.
266
268
267
269
``` js
268
270
var bemxjst = require (' bem-xjst' );
269
- var templates = bemxjst .bemhtml .compile (function () {
271
+ var templates = bemxjst .bemhtml .compile (() => {
270
272
// In this example we will add no templates.
271
273
// Default behaviour is used for HTML rendering.
272
274
}, {
@@ -293,7 +295,7 @@ You can set `escapeContent` option to `true` to escape string values of `content
293
295
294
296
``` js
295
297
var bemxjst = require (' bem-xjst' );
296
- var templates = bemxjst .bemhtml .compile (function () {
298
+ var templates = bemxjst .bemhtml .compile (() => {
297
299
// In this example we will add no templates.
298
300
// Default behaviour is used for HTML rendering.
299
301
}, {
@@ -322,7 +324,7 @@ If you want avoid escaping in content [use special value](4-data.md#content): `{
322
324
323
325
``` js
324
326
var bemxjst = require (' bem-xjst' );
325
- var templates = bemxjst .bemhtml .compile (function () {
327
+ var templates = bemxjst .bemhtml .compile (() => {
326
328
// In this example we will add no templates.
327
329
// Default behaviour is used for HTML rendering.
328
330
}, {
@@ -359,12 +361,14 @@ About these warnings you can read [migration guide](https://github.com/bem/bem-x
359
361
var bemxjst = require (' bem-xjst' );
360
362
var bemhtml = bemxjst .bemhtml ;
361
363
362
- var templates = bemhtml .compile (function () {
363
- block (' b' ). content ()( ' yay' );
364
+ var templates = bemhtml .compile (() => {
365
+ block (' b' )({ content : ' yay' } );
364
366
365
- block (' mods-changes' ).def ()(function () {
366
- this .ctx .mods .one = 2 ;
367
- return applyNext ();
367
+ block (' mods-changes' )({
368
+ def : (ctx , json ) => {
369
+ json .mods .one = 2 ;
370
+ return applyNext ();
371
+ }
368
372
});
369
373
}, { runtimeLint: true });
370
374
@@ -406,11 +410,13 @@ You can use option `production` to render whole BEMJSON even if one template con
406
410
** Example**
407
411
408
412
``` js
409
- var template = bemxjst .compile (function () {
410
- block (' b1' ).attrs ()(function () {
411
- var attrs = applyNext ();
412
- attrs .undef .foo = ' bar' ;
413
- return attrs;
413
+ var template = bemxjst .compile (() => {
414
+ block (' b1' )({
415
+ attrs : () => {
416
+ var attrs = applyNext ();
417
+ attrs .undef .foo = ' bar' ;
418
+ return attrs;
419
+ }
414
420
});
415
421
}, { production: true });
416
422
var html = template .apply ({ block: ' page' , content: { block: ' b1' } });
@@ -472,10 +478,12 @@ For example:
472
478
` lib-name ` module will be accessible in templates body like this:
473
479
474
480
``` js
475
- block (' button' ).content ()(function () {
476
- var lib = this .require (' lib-name' );
481
+ block (' button' )({
482
+ content : (node ) => {
483
+ var lib = node .require (' lib-name' );
477
484
478
- return lib .hello ();
485
+ return lib .hello ();
486
+ }
479
487
});
480
488
```
481
489
@@ -511,7 +519,7 @@ You don’t need to to provide path to module:
511
519
{
512
520
requires: {
513
521
moment: {
514
- commonJS: ' moment' , // path to CommonJS module, relative bundle file
522
+ commonJS: ' moment' // path to CommonJS module, relative bundle file
515
523
}
516
524
}
517
525
}
@@ -521,11 +529,13 @@ In templates body the module will be acessible as `this.require('moment')`.
521
529
You can use the template in any browser or in ` Node.js ` :
522
530
523
531
``` js
524
- block (' post' ).elem (' data' ).content ()(function () {
525
- var moment = this .require (' moment' );
532
+ block (' post' ).elem (' data' )({
533
+ content : (node , ctx ) => {
534
+ var moment = node .require (' moment' );
526
535
527
- return moment (this .ctx .date ) // Time in ms from server
528
- .format (' YYYY-MM-DD HH:mm:ss' );
536
+ return moment (ctx .date ) // Time in ms from server
537
+ .format (' YYYY-MM-DD HH:mm:ss' );
538
+ }
529
539
});
530
540
```
531
541
@@ -543,9 +553,9 @@ templates.BEMContext.prototype.hi = function(name) {
543
553
};
544
554
545
555
// Add templates
546
- templates .compile (function () {
547
- block (' b' ). content ()( function () {
548
- return this .hi (' templates' );
556
+ templates .compile (() => {
557
+ block (' b' )( {
558
+ content : ( node ) => node .hi (' templates' )
549
559
});
550
560
});
551
561
@@ -569,7 +579,7 @@ browser to get the `templates` object.
569
579
570
580
``` js
571
581
var bemxjst = require (' bem-xjst' );
572
- var bundle = bemxjst .bemhtml .generate (function () {
582
+ var bundle = bemxjst .bemhtml .generate (() => {
573
583
// user-defined templates
574
584
// …
575
585
});
0 commit comments