Skip to content

Instantly share code, notes, and snippets.

@narqo
Last active December 22, 2015 00:58
Show Gist options
  • Save narqo/6392690 to your computer and use it in GitHub Desktop.
Save narqo/6392690 to your computer and use it in GitHub Desktop.
Test for bem-xjst
var bemxjst = require('bem-xjst'),
FN_RE = /^function(?:\s+\w+)?\s*\([^\)]*\)\s*\{|\}$/g;
function noop() {
return '[sorry]';
}
function parse(fn) {
var body = fn.toString().replace(FN_RE, '').trim();
if(!body) {
return noop;
}
return bemxjst.compile(body, { optimize : false });
}
exports.parse = parse;
var parser = require('./parser');
function run(fn, data) {
return parser.parse(fn).apply(data);
}
exports.run = run;
module.exports = function() {
block('b1')(function() {
var content = apply('content', { ctx : 'my-content' });
return '<span class="b1">' + content + '</span>';
});
block('b1').content(function() {
return this.ctx.toUpperCase();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment