pengxing / javascript-template Goto Github PK
View Code? Open in Web Editor NEWJavaScript Template for Front end
JavaScript Template for Front end
TODO: 1. Optimize the compiled function by abandoning using keyword "with". ( Every commit will be considered ) ( 欢迎任何人提交代码 ) Feature: 1. Support comment <%# comment %> 2. Support encodeURIComponent <%:u=href %> 3. Support encodeHTML <% var s = "<script>var s= 'encodeHTML'<\/script>"; %> <%:h=str %> 4. Support developers custom template function var template = '<% output("custom function"); %>'; app.tpl(template, {}, { fns : { output : 'function(str){__s += str}' } }) 5. Good performance 6. Support error tips 使用方法: 语法类似JSP,在JSP的基础上增加了一些特性,当然也去掉了很多 1. 注释 <%# comment %> <% /* comment */ %> <% /** comment */ %> 不支持(Not support) <% //comment %> 2. 普通语句 <% var s = 'template'; /* 代码块里是JavaScript语句 */ if(s == 'template'){ %> template <% } %> 3. 输出变量 a. 直接输出 <% var str = "HelloWorld!"; %> <%=str %> 程序将直接输出"HelloWorld!" b. encodeURIComponent <% var str = "HelloWorld! "; %> <%:u=str %> 程序将输出"HelloWorld!%20" c. encodeHTML <% var str = "<script>var s = 'HelloWorld!';<\/script>"; %> <%:h=str %> 程序将输出"<script>var s = 'HelloWorld!';</script>" 4. 内置模板函数 目前内置了两个模板函数,分别是print和encodeHTML a. print <% var s = "HelloWorld!"; print(s); %> 等价于 <% var s = "HelloWorld!"; %> <%=s%> b. encodeHTML <% var str = "<script>var s = 'HelloWorld!';<\/script>"; print(encodeHTML(str)); %> 等价于 <% var str = "<script>var s = 'HelloWorld!';<\/script>"; %> <%:h=str %> 5. 自定义模板函数 开发者可以根据自己的喜好,自定义模板内可使用的函数,如下: <% var str = "<script>var s = 'HelloWorld!';<\/script>"; encodeHTMLAndPrint(str); %> app.tpl(template, {}, { fns : { encodeHTMLAndPrint : 'function(s){print(encodeHTML(s))}' } }); 在这里encodeHTMLAndPrint函数为开发者自定义函数,调用了内置函数print和encodeHTML输出一个转义好的字符串 注意:开发者尽量不要应用内置变量"__s" Good Luck
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.