This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0
anot.js/src/05-kernel.js

66 lines
1.7 KiB
JavaScript

/*********************************************************************
* 配置系统 *
**********************************************************************/
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') {
Anot.mix(kernel[p], val)
} else {
kernel[p] = val
}
}
return this
}
Anot.config = kernel
var openTag,
closeTag,
rexpr,
rexprg,
rbind,
rregexp = /[-.*+?^${}()|[\]\/\\]/g
function escapeRegExp(target) {
//http://stevenlevithan.com/regex/xregexp/
//将字符串安全格式化为正则表达式的源码
return (target + '').replace(rregexp, '\\$&')
}
var plugins = {
interpolate: function(array) {
openTag = array[0]
closeTag = array[1]
if (openTag === closeTag) {
throw new SyntaxError('openTag!==closeTag')
var test = openTag + 'test' + closeTag
cinerator.innerHTML = test
if (
cinerator.innerHTML !== test &&
cinerator.innerHTML.indexOf('<') > -1
) {
throw new SyntaxError('此定界符不合法')
}
cinerator.innerHTML = ''
}
kernel.openTag = openTag
kernel.closeTag = closeTag
var o = escapeRegExp(openTag),
c = escapeRegExp(closeTag)
rexpr = new RegExp(o + '([\\s\\S]*)' + c)
rexprg = new RegExp(o + '([\\s\\S]*)' + c, 'g')
rbind = new RegExp(o + '[\\s\\S]*' + c + '|\\s:') //此处有疑问
}
}
kernel.plugins = plugins
kernel.plugins['interpolate'](['{{', '}}'])
kernel.async = true
kernel.paths = {}
kernel.shim = {}
kernel.maxRepeatSize = 100
Anot 是Anot not only templateEngine的缩写。 它是一款迷你,易用、高性能的前端MVVM框架, fork于avalon。进行了大量的重构,精简部分冗余的API, 同时针对组件拓展进行了优化。
JavaScript 100%