JS 模板引擎

阅读更多
;!function() {
	"use strict";
	var f, b = { open: "{{", close: "}}" },
		c = { exp: function(a) { return new RegExp(a, "g") }, query: function(a, c, e) { var f = ["#([\\s\\S])+?", "([^{#}])*?"][a || 0]; return d((c || "") + b.open + f + b.close + (e || "")) }, escape: function(a) { return String(a || "").replace(/&(?!#?[a-zA-Z0-9]+;)/g, "&").replace(//g, ">").replace(/'/g, "'").replace(/"/g, """) }, error: function(a, b) { var c = "Laytpl Error:"; return "object" == typeof console && console.error(c + a + "\n" + (b || "")), c + a } },
		d = c.exp,
		e = function(a) { this.tpl = a };
	e.pt = e.prototype, e.pt.parse = function(a, e) {
		var f = this,
			g = a,
			h = d("^" + b.open + "#", ""),
			i = d(b.close + "$", "");
		a = a.replace(/[\r\t\n]/g, " ").replace(d(b.open + "#"), b.open + "# ").replace(d(b.close + "}"), "} " + b.close).replace(/\\/g, "\\\\").replace(/(?="|')/g, "\\").replace(c.query(), function(a) { return a = a.replace(h, "").replace(i, ""), '";' + a.replace(/\\/g, "") + '; view+="' }).replace(c.query(1), function(a) { var c = '"+('; return a.replace(/\s/g, "") === b.open + b.close ? "" : (a = a.replace(d(b.open + "|" + b.close), ""), /^=/.test(a) && (a = a.replace(/^=/, ""), c = '"+_escape_('), c + a.replace(/\\/g, "") + ')+"') }), a = '"use strict";var view = "' + a + '";return view;';
		try { return f.cache = a = new Function("d, _escape_", a), a(e, c.escape) } catch(j) { return delete f.cache, c.error(j, g) }
	}, e.pt.render = function(a, b) { var e, d = this; return a ? (e = d.cache ? d.cache(a, c.escape) : d.parse(d.tpl, a), b ? (b(e), void 0) : e) : c.error("no data") }, f = function(a) { return "string" != typeof a ? c.error("Template not found") : new e(a) }, f.config = function(a) { a = a || {}; for(var c in a) b[c] = a[c] }, f.v = "1.1", "function" == typeof define ? define(function() { return f }) : "undefined" != typeof exports ? module.exports = f : window.laytpl = f
}();

 





JS 模板引擎






 

PS:兼容IE6+,火狐,谷歌,欧朋,苹果

 

效果图:
JS 模板引擎_第1张图片
 

 

 

 

 

 

 

 

 

 

  • JS 模板引擎_第2张图片
  • 大小: 30.9 KB
  • demo.rar (2.5 KB)
  • 下载次数: 2
  • 查看图片附件

你可能感兴趣的:(JS,模板引擎,模板引擎,仿VUE)