JavaScript 页面模板引擎
2024-08-25 14:54:16
var TemplateEngine = function(html, options) {
var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0;
var add = function(line, js) {
js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') :
(code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
return add;
}
while(match = re.exec(html)) {
add(html.slice(cursor, match.index))(match[1], true);
cursor = match.index + match[0].length;
}
add(html.substr(cursor, html.length - cursor));
code += 'return r.join("");';
return new Function(code.replace(/[\r\t\n]/g, '')).apply(options);
}</%([^%>
最新文章
- A new comer playing with Raspberry Pi 3B
- blade and soul factions
- android Java BASE64编码和解码一:基础
- 浅谈URLEncoder编码算法
- each的用法
- Android 进入页面默认定位到ListView的解决方法
- Sublime Text 3插件之SublimeTmpl:新建文件的模版插件
- 【libsvm学习】
- 巧用MySQL之Explain进行数据库优化
- Android 读取手机短信
- 怎样让HTML5调用手机摄像头拍照——实践就是一切
- Android 开发 AirPlay Server
- GDI+: Curved Shapes
- ios崩溃日志1
- js的this作用域
- 解决Ubuntu 16.04 上Android Studio2.3上面运行APP时提示DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs的问题
- Camtasia Studio CamStudio如何不录制鼠标
- ipad开发小结
- 启动Tomcat报错:class path resource cannot be opened
- postgresql----继承表INHERITS PARENT TABLE
热门文章
- python多进程程序之间交换数据的两种办法--Queue和Pipe
- JavaScript - call(this)
- js 节点 document html css 表单节点操作
- [转]svn常用命令
- ";Project facet Java version 1.7 is not supported";的问题解决的办法
- hdu 3183(贪心)
- kylin cube测试时,报错:org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode=";/user";:hdfs:supergroup:drwxr-xr-x
- 快速幂 fast_exp
- 创建一个Portlet工程
- DSP using MATLAB 随书示例Example2.8