UNPKG

ceri-compiler

Version:

compiles template strings for ceriJS

37 lines (34 loc) 990 B
var isDirective; isDirective = (name) => { return name.match(/^[$:@~]/); }; module.exports = (camelize, marker) => { return (name, attr, options) => { var k, name1, opt, splitted, tmp, type, v, val; type = name.slice(0, 1); if (!isDirective(type)) { return false; } if (attr && options.length > 0) { opt = options[options.length - 1]; name = name.slice(1); splitted = name.split("="); tmp = opt[name1 = splitted[0]] != null ? opt[name1] : opt[name1] = {}; val = splitted[1] ? camelize(splitted[1]) : []; tmp = tmp[type] != null ? tmp[type] : tmp[type] = { val: val, mods: {} }; for (k in attr) { v = attr[k]; splitted = camelize(k).split("."); if (~(splitted.indexOf("expr"))) { tmp.mods[splitted[0]] = `${marker}function(){return ${v};}${marker}`; } else { tmp.mods[splitted[0]] = v || true; } } } return true; }; };