/********************************************************************* * 配置系统 在系统运行的开始就需要读取系统中require.config()这个方法中所配置的项目 * **********************************************************************/ //这里写在前面是为了更加方便阅读代码,在实际运行中,这几段代码必须放在下面
kernel.debug = true kernel.plugins = plugins kernel.plugins[‘interpolate‘](["{{", "}}"]) kernel.paths = {} kernel.shim = {} kernel.maxRepeatSize = 100 avalon.config = kernel
function kernel(settings) { for (var p in settings) { if (!ohasOwn.call(settings, p)) continue var val = settings[p] if (typeof kernel.plugins[p] === "function") { kernel.plugins[p](val) } else if (typeof kernel[p] === "object") { avalon.mix(kernel[p], val) } else { kernel[p] = val } } return this } var openTag, closeTag, rexpr, rexprg, rbind, rregexp = /[-.*+?^${}()|[\]\/\\]/g function escapeRegExp(target) { //http://stevenlevithan.com/regex/xregexp/ //将字符串安全格式化为正则表达式的源码 return (target + "").replace(rregexp, "\\$&") } var innerRequire = noop var plugins = { loader: function(builtin) { window.define = builtin ? innerRequire.define : otherDefine window.require = builtin ? innerRequire : otherRequire }, interpolate: function(array) { openTag = array[0] closeTag = array[1] if (openTag === closeTag) { throw new SyntaxError("openTag!==closeTag") } else if (array + "" === "<!--,-->") { kernel.commentInterpolate = true } else { var test = openTag + "test" + closeTag cinerator.innerHTML = test if (cinerator.innerHTML !== test && cinerator.innerHTML.indexOf("<") > -1) { throw new SyntaxError("此定界符不合法") } cinerator.innerHTML = "" } var o = escapeRegExp(openTag), c = escapeRegExp(closeTag) rexpr = new RegExp(o + "(.*?)" + c) rexprg = new RegExp(o + "(.*?)" + c, "g") rbind = new RegExp(o + ".*?" + c + "|\\sms-") } }
时间: 2024-11-02 15:44:42