UNPKG

bem-xjst

Version:

Declarative Template Engine for the browser and server

60 lines (44 loc) 1.36 kB
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); };