百度uedit禁止转义及关于模板语言 Mustache

来源:互联网 发布:adobe 3d软件 编辑:程序博客网 时间:2024/05/16 09:33

1.关于模板语言 Mustache

@Fenng A client-rendering framework for Facebook by Changhao Jianghttp://t.co/NIo6vCd

 

Fenng推荐了一款模板语言:mustache(意思是胡须)。

 

mustache官网是这么介绍的:

 

Logic-less templates.

Available in Ruby, JavaScript, Python,Erlang, PHP, Perl, Objective-C, Java, .NET,Android, C++, Go, Lua, ooc, ActionScript,ColdFusion, Scala, Clojure, Fantom,CoffeeScript, D, and for node.js.

Works great with TextMate, Vim, Emacs, andCoda.

The Manual: mustache(5) and mustache(1)

 

总而言之,支持很多语言,作者是facebook的蒋博士。

 

全部用法详见http://mustache.github.com/mustache.5.html

github的html彩蛋:

[xhtml] view plain copy
 print?
  1. <!--  
  2.                                       _  _  
  3.                             _____*~~~  **  ~~~*_____  
  4.                          __* ___     |/__/|     ___ *__  
  5.                        _*  / 888~~/__(8OO8)__/~~888 /  *_  
  6.                      _*   /88888888888888888888888888/   *_  
  7.                      *   |8888888888888888888888888888|   *  
  8.                     /~*  /8888/~/88/~/8888/~/88/~/8888/  *~  
  9.                    /  ~*  /88/   //   (88)   //   /88/  *~  
  10.                   /    ~*  //          //          //  *~  
  11.                  /       ~~*_                      _*~~/  
  12.                 /            ~~~~~*___ ** ___*~~~~~  /  
  13.                /                      ~  ~         /  
  14.               /                                  /  
  15.              /                                 /  
  16.             /                                /  
  17.            /                    t__n__r__  /  
  18.           /                    | ####### |  
  19.          /            ___      | ####### |             ____i__           /  
  20.         /  _____p_____l_l____  | ####### |            | ooooo |         qp  
  21. i__p__ /  |  ##############  | | ####### |__l___xp____| ooooo |      |~~~~|  
  22.  oooo |_I_|  ##############  | | ####### |oo%Xoox%ooxo| ooooo |p__h__|##%#|  
  23.  oooo |ooo|  ##############  | | ####### |o%xo%%xoooo%| ooooo |      |#xx%|  
  24.  oooo |ooo|  ##############  | | ####### |o%ooxx%ooo%%| ooooo |######|x##%|  
  25.  oooo |ooo|  ##############  | | ####### |oo%%x%oo%xoo| ooooo |######|##%x|  
  26.  oooo |ooo|  ##############  | | ####### |%x%%oo%/oo%o| ooooo |######|/#%x|  
  27.  oooo |ooo|  ##############  | | ####### |%%x/oo/xx%xo| ooooo |######|#%x/|  
  28.  oooo |ooo|  ##############  | | ####### |xxooo%%/xo%o| ooooo |######|#^x#|  
  29.  oooo |ooo|  ##############  | | ####### |oox%%o/x%%ox| ooooo |~~~$~~|x##/|  
  30.  oooo |ooo|  ##############  | | ####### |x%oo%x/o%//x| ooooo |_KKKK_|#x/%|  
  31.  ooo~/|ooo|~/##############  | ~/####### |oox%xo%%oox%~/ooooo |_|~|~/|xx%/|  
  32.  ooo ||oHo| |####AAAA######  |h||##XX### |x%x%WWx%%/ox||ooDoo |_| |Y||xGGx|  
  33.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  | ~~~~~~~  
  34. -->  
 

个人觉得比smarty好用多了。不为别的,因为简洁明了。

传闻 豆瓣说(http://shuo.douban.com) 运用了这种模板?关注中

简要介绍下用法:

 

1A typical Mustache template:

 

[xhtml] view plain copy
print?
  1. Hello {{name}}  
  2. You have just won ${{value}}!  
  3. {{#in_ca}}  
  4. Well, ${{taxed_value}}, after taxes.  
  5. {{/in_ca}}  

Given the following hash:

[javascript] view plain copy
print?
  1. {  
  2.   "name""Chris",  
  3.   "value": 10000,  
  4.   "taxed_value": 10000 - (10000 * 0.4),  
  5.   "in_ca"true  
  6. }  

Will produce the following:

[xhtml] view plain copy
print?
  1. Hello Chris  
  2. You have just won $10000!  
  3. Well, $6000.0, after taxes.  
Mustache可以用在包括html 配置文件 源代码之类的任何地方。通过提供hash或者对象可以渲染出模板中的变量。模板没有if-else,for-loop标记,只有标记(tag)。
常用标签有类似{{name}},{{#person}}这样语法的标签.如果不提供值,将不会渲染出来。{{{html}}}和{{& html}}将会渲染出没有转义的html内容。
区域渲染通过{{#person}} ... {{/person}}来实现。例如
[xhtml] view plain copy
print?
  1. Shown.  
  2. {{#nothin}}  
  3.   Never shown!  
  4. {{/nothin}}  
输出Shown.(如果没有提供nothin)
如果提供了非空列表或者数组,区域渲染将会重复渲染列表或数组每一项。例如

Template:

[xhtml] view plain copy
print?
  1. {{#repo}}  
  2.   <b>{{name}}</b>  
  3. {{/repo}}  

Hash:

[xhtml] view plain copy
print?
  1. {  
  2.   "repo": [  
  3.     { "name": "resque" },  
  4.     { "name": "hub" },  
  5.     { "name": "rip" },  
  6.   ]  
  7. }  

Output:

[xhtml] view plain copy
print?
  1. <b>resque</b>  
  2. <b>hub</b>  
  3. <b>rip</b>  
另外,Mustache支持lambda表达式

Template:

[xhtml] view plain copy
print?
  1. {{#wrapped}}  
  2.   {{name}} is awesome.  
  3. {{/wrapped}}  

Hash:

[xhtml] view plain copy
print?
  1. {  
  2.   "name": "Willy",  
  3.   "wrapped": function() {  
  4.     return function(text) {  
  5.       return "<b>" + render(text) + "</b>"  
  6.     }  
  7.   }  
  8. }  

Output:

[xhtml] view plain copy
print?
  1. <b>Willy is awesome.</b>  
打注释也很方便:{{! ignore me }}
导入别的文件只要像这样:
[xhtml] view plain copy
print?
  1. base.mustache:  
  2. <h2>Names</h2>  
  3. {{#names}}  
  4.   {{> user}}  
  5. {{/names}}  
  6.   
  7. user.mustache:  
  8. <strong>{{name}}</strong>  
便能输出
[xhtml] view plain copy
print?
  1. <h2>Names</h2>  
  2. {{#names}}  
  3.   <strong>{{name}}</strong>  
  4. {{/names}}  
另外的另外{{}}也是可以自行配置的!
转载自:http://blog.csdn.net/soasme/article/details/6297467

2.uedit禁止自动转移html标签

在Uedit中使用{{&name}},会被自动转换为{{&empname}},进行设置uedit属性,则可避免进行转义

UE.getEditor('editor', {    allHtmlEnabled:true});


0 0
原创粉丝点击