-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathcontext.js
59 lines (44 loc) · 1.33 KB
/
context.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var utils = require('./utils');
function Context(bemxjst) {
this._bemxjst = bemxjst;
this.ctx = null;
this.block = '';
// Save current block until the next BEM entity
this._currBlock = '';
this.elem = null;
this.mods = {};
this.elemMods = {};
this.position = 0;
this._listLength = 0;
this._notNewList = false;
this.escapeContent = bemxjst.options.escapeContent !== false;
}
exports.Context = Context;
Context.prototype._flush = null;
Context.prototype.isSimple = utils.isSimple;
Context.prototype.isShortTag = utils.isShortTag;
Context.prototype.extend = utils.extend;
Context.prototype.identify = utils.identify;
Context.prototype.xmlEscape = utils.xmlEscape;
Context.prototype.attrEscape = utils.attrEscape;
Context.prototype.jsAttrEscape = utils.jsAttrEscape;
Context.prototype.onError = function(context, e) {
console.error('bem-xjst rendering error:', {
block: context.ctx.block,
elem: context.ctx.elem,
mods: context.ctx.mods,
elemMods: context.ctx.elemMods
}, e);
};
Context.prototype.isFirst = function() {
return this.position === 1;
};
Context.prototype.isLast = function() {
return this.position === this._listLength;
};
Context.prototype.generateId = function() {
return utils.identify(this.ctx);
};
Context.prototype.reapply = function(ctx) {
return this._bemxjst.run(ctx);
};