30 lines
686 B
JavaScript
Executable File
30 lines
686 B
JavaScript
Executable File
/**
|
|
* 获取编译缓存(可由外部重写此方法)
|
|
* @param {String} 模板名
|
|
* @param {Function} 编译好的函数
|
|
*/
|
|
template.get = function (filename) {
|
|
|
|
var cache;
|
|
|
|
if (cacheStore[filename]) {
|
|
// 使用内存缓存
|
|
cache = cacheStore[filename];
|
|
} else if (typeof document === 'object') {
|
|
// 加载模板并编译
|
|
var elem = document.getElementById(filename);
|
|
|
|
if (elem) {
|
|
var source = (elem.value || elem.innerHTML)
|
|
.replace(/^\s*|\s*$/g, '');
|
|
cache = compile(source, {
|
|
filename: filename
|
|
});
|
|
}
|
|
}
|
|
|
|
return cache;
|
|
};
|
|
|
|
|