zoukankan      html  css  js  c++  java
  • 模板渲染引擎

     1  var template = (function () {
     2             /*  Simple JavaScript Templating
     3              John Resig - http://ejohn.org/ - MIT Licensed */
     4             var cache = {};
     5             return tmpl = function (str, data) {
     6                 /* Figure out if we're getting a template, or if we need to */
     7                 /* load the template - and be sure to cache the result. */
     8                 var fn = !/W/.test(str) ? cache[str] = cache[str] || tmpl(document.getElementById(str).innerHTML) :
     9 
    10                     /* Generate a reusable function that will serve as a template */
    11                     /*  generator (and which will be cached). */
    12                         new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" +
    13 
    14                                     /* Introduce the data as local variables using with(){} */
    15                                 "with(obj){p.push('" +
    16 
    17                                     /* Convert the template into pure JavaScript */
    18                                     /* modified by yiguo .for extension function */
    19                                 str.replace(/[
    	
    ]/g, " ").split("<%").join("	").replace(/((^|%>)[^	]*)'/g, "$1
    ").replace(/	=(.*?)%>/g, function (a, b, c) {
    20                                     var arr = b.split("|");
    21                                     if (arr.length > 1) {
    22                                         b = "tmpl.fns['" + arr[1] + "' ](" + arr[0] + ",'" + arr[2] + "')";
    23                                     }
    24                                     return "'," + b + ",'";
    25 
    26                                 }).split("	").join("');").split("%>").join("p.push('").split("
    ").join("\'") + "');}return p.join('');");
    27 
    28                 /* Provide some basic currying to the user*/
    29                 return data ? fn(data) : fn;
    30             };
    31         })();
  • 相关阅读:
    ES6常用语法
    nodejs中exports与module.exports的区别
    CSS animation动画
    CSS user-select文本是否可复制
    VUE 滚动插件(better-scroll)
    VUE 父组件与子组件交互
    CSS div内文字显示两行,超出部分省略号显示
    linux下使用tar命令
    linux fdisk命令使用
    关于SUID、SGID、Sticky
  • 原文地址:https://www.cnblogs.com/hanfei-cn/p/5199083.html
Copyright © 2011-2022 走看看