Last active
December 22, 2015 00:58
-
-
Save narqo/6392690 to your computer and use it in GitHub Desktop.
Test for bem-xjst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = require('./parser'); | |
function run(fn, data) { | |
return parser.parse(fn).apply(data); | |
} | |
exports.run = run; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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