- 浏览: 293046 次
文章分类
- 全部博客 (148)
- Shell (2)
- Python (4)
- Java (31)
- Javascript (4)
- Android (7)
- SQL优化 (0)
- Linux (5)
- webOS (4)
- MySQL (18)
- memcach redis (1)
- memcach (0)
- redis (3)
- memcache (2)
- svn (1)
- UED (1)
- 网络 (1)
- virtual box (1)
- git (1)
- Gitosis (1)
- 云计算 (2)
- 12306 (1)
- google (1)
- spdy (1)
- nginx (1)
- tomcat (2)
- SSL (2)
- lucene (2)
- 空间搜索 (1)
- lzo (1)
- 数据压缩 (1)
- ios (1)
- maven (1)
- elasticsearch (1)
- scribe (1)
- flume (1)
- jni (1)
- jna (1)
- hadoop (2)
- 大数据 (1)
最新评论
-
aa80303857:
不错,学习了。互相关注一下。
Sitemesh学习笔记 -
xiaozang:
...
关于nginx的rewrite重写规则 -
coderuncle:
楼主有没有研究过cloudera flume和apache f ...
scribe,flume -
奔跑的犀牛:
...
linux下自动启动mysql -
lsn_1212:
网上装svn的资源太多了,这个挺好的,说的挺全的。
SVN Server安装部署攻略(Linux+SubVersion+Apache)
主页地址
http://code.google.com/p/trimpath/wiki/JavaScriptTemplateSyntax
代码下载
使用:
Updated Feb 04, 2010 by steve....@gmail.com JavaScriptTemplateAPI JavaScript Templates API { JavaScript Templates (JST) home | API | syntax | modifiers | download | community } Using JavaScript Templates First, in your HTML/JSP/PHP/ASP file, include the trimpath/template.js JavaScript file. <script language="javascript" src="trimpath/template.js"></script> The trimpath/template.js file can live anywhere you want and may be renamed. It has no dependencies to other files. For example, you might move it to lib/trimpath/template.js or js/trimpath/template.js. We suggest using a subdirectory named trimpath to help you remember what it's about and also give you a space to place more (future) TrimPath components. Future TrimPath components might depend on living in the same directory as trimpath/template.js. After including trimpath/template.js, a JavaScript variable named TrimPath will hold an Object ready for you to use. The TrimPath Object The TrimPath Object is the global singleton object that is the access point for all TrimPath components. Except for this TrimPath Object, we try to keep the global variable namespace clean for you. The TrimPath Object will have the following JST-related methods... TrimPath.parseDOMTemplate ( elementId, optionalDocument ) Retrieves the innerHTML of the document DOM element that has the given elementId. The innerHTML is then parsed as a template. This method returns a '''templateObject''', which is described later. Throws an exception on any parsing error. The method parameters are... '''elementId''' Id of the DOM element whose innerHTML is used as the template. '''optionalDocument''' An optional DOM document, which is useful when working with multiple documents with iframes, framesets or multiple browser windows. [BR] Defaults to document. The document DOM element is usually a hidden <textarea> . You can use a style attribute to hide a textarea. For example: <textarea id="elementId" style="display:none;"> template body </textarea> TrimPath.processDOMTemplate ( elementId, contextObject, optionalFlags, optionalDocument ) Helper function that calls TrimPath.parseDOMTemplate() and then the process() method on the returned '''templateObject'''. The output of templateObject.process() is returned. Throws an exception on any parsing error. The method parameters are... '''elementId''' Same as for TrimPath.parseDOMTemplate. '''contextObject''' See templateObject.process() '''optionalFlags''' See templateObject.process() '''optionalDocument''' Same as for TrimPath.parseDOMTemplate. TrimPath.parseTemplate ( templateContentStr, optionalTemplateName ) Parses a String as a template and returns a '''templateObject''' which is described later. Throws an exception on any parsing error. The method parameters are... '''templateContentStr''' String that has JST markup. For example: "Hello ${firstName} ${lastName}" '''optionalTemplateName''' An optional String of the template's name. [BR] Used to help in debugging. The templateObject A templateObject is returned by TrimPath.parseTemplate() and TrimPath.parseDOMTemplate(). It represents a successfully parsed template. A templateObject has one key method... templateObject.process ( contextObject, optionalFlags ) The process() method merges the template with the '''contextObject'''. The process() method may be called repeatedly, without any template parsing performance overhead, so the highest performance can be had by caching and reusing templateObjects. The return value of this method is a String of the 'rendered' template. The '''contextObject''' parameter must be an Object, which becomes part of the lookup "scope" of the template. If a template refers to ${a}, then contextObject.a is accessed. For ${a.b.c}, then contextObject.a.b.c is acccessed. Note that the '''contextObject''' can contain any JavaScript object, including strings, numbers, date, objects and functions. So, calling ${groupCalender(new Date())} would call contextObject.groupCalender(new Date()). Of course, you would have to supply the groupCalender() function, which should return a string value. The '''optionalFlags''' may be null, or an Object that with the following optional slots... throwExceptions Defaults to false. [BR] When true, the process() method will forward exceptions by re-throwing them. [BR] When false, any exceptions will stop template processing. The caught exception is converted to a String message, which is then appended onto the process()'s return value String, which has any partially processed results so far. keepWhitespace Defaults to false. [BR] When true, all whitespace characters are emitted during template processing. [BR] When false, various whitespace characters (newline, space, tab) that surround statement tags (such as {if}, {else}, {for}) are stripped out to make any output look "cleaner and prettier". The String.prototype.process() method String.prototype.process ( contextObject, optionalFlags ) As a convenience, the String prototype is enhanced with a process() method. It parses the String as a template and invokes process(). The arguments are the same as for templateObject.process(). var result = "hello ${firstName}".process(data) // ...is equivalent to... var result = TrimPath.parseTemplate("hello ${firstName}").process(data); Adding Custom Modifiers You may add your own custom modifiers by placing them into a '''MODIFERS''' Object, which should then be placed into the '''contextObject''' that is passed to the templateObject.process() method. Each custom modifier should be a function that takes minimally one String argument and returns a String. For example... var myModifiers = { hello : function(str, greeting) { if (greeting == null) greeting = "Hello"; return greeting + ", " + str; }, zeroSuffix : function(str, totalLength) { return (str + "000000000000000").substring(0, totalLength); } }; var myData = { firstName : "John", getCurrentPoints : function() { /* Do something here... */ return 12; } } myData._MODIFIERS = myModifiers; "${firstName}".process(myData) == "John" "${firstName|hello}".process(myData) == "Hello, John" "${firstName|hello:"Buenos Dias"}".process(myData) == "Buenos Dias, John" "${firstName|hello:"Buenos Dias"|capitalize}".process(myData) == "BUENOS DIAS, JOHN" "${getCurrentPoints()}".process(myData) == "12" "${getCurrentPoints()|zeroSuffix:4}".process(myData) == "1200"
帮助:
JavaScriptTemplateSyntax JavaScript Template Syntax { JavaScript Templates (JST) home | API | syntax | modifiers | download | community } This page describes the syntax for JavaScript Templates, including its expression markup and statement tags. Expressions and Expression Modifiers ${expr} ${expr|modifier} ${expr|modifier1|modifier2|...|modifierN} ${expr|modifier1:argExpr1_1} ${expr|modifier1:argExpr1_1,argExpr1_2,...,argExpr1_N} ${expr|modifier1:argExpr1_1,argExpr1_2|...|modifierN:argExprN_1,argExprN_2,...,argExprN_M} An expr is any valid JavaScript expression, except for close-brace characters ('}'). A modifier looks like modifierName:argExpr1[,argExpr2[,argExprN]] An argExpr is an expr. Examples: ${customer.firstName} ${customer.firstName|capitalize} ${customer.firstName|default:"no name"|capitalize} ${article.getCreationDate()|default:new Date()|toCalenderControl:"YYYY.MM.DD",true,"Creation Date"} ${(lastQuarter.calcRevenue() - fixedCosts) / 1000000} Please see also the list of standard modifiers and how to use the API to create your own custom modifiers. Expressions can also be optionally specified as "${% customer.firstName %}" syntax, which has the extra '%' delimiter characters. This syntax is useful if your expressions have brace characters. For example... Visit our ${% emitLink('Solutions and Products', { color: 'red', blink: false }) %} page. The extra spaces are actually not necessary, like... ${%customer.firstName%} ${%customer.firstName|capitalize%} Statements Statement tags are nestable in just like JavaScript statement blocks (if/else/for/function) are nestable. Control Flow {if testExpr} {elseif testExpr} {else} {/if} The testExpr is any valid JavaScript expression, but no close-brace characters. The testExpr does not require surrounding parenthesis. Examples: {if customer != null && customer.balance > 1000} We love you! {/if} {if user.karma > 100} Welcome to the Black Sun. {elseif user.isHero} Sir, yes sir! Welcome! {if user.lastName == "Yen"} Fancy some apple pie, sir? {/if} {/if} <a href="/login{if returnURL != null && returnURL != 'main'}?goto=${returnURL}{/if}">Login</a> The JavaScript Template engine also defines a helper function called "defined(str)", which checks its argument for equality with the JavaScript undefined value. It is useful to check if a value is defined in the evaluation context. For example... {if defined('adminMessage')} System Administrator Important NOTICE: ${adminMessage} {/if} Loops {for varName in listExpr} {/for} {for varName in listExpr} ...main body of the loop... {forelse} ...body when listExpr is null or listExpr.length is 0... {/for} A varName is any valid JavaScript variable name. A listExpr is a JavaScript expression which should evaluate to an Array, an Object, or to null. The listExpr is evaluated only once. Two variables are bound in the main body of the loop: __LIST__varName - holds the result of evaluating listExpr. varName_index - this is the key or counter used during iteration. Examples: {for x in customer.getRecentOrders()} ${x_index} : ${x.orderNumber} <br/> {forelse} You have no recent orders. {/for} Converted pseudo-code for the above... var __LIST__x = customer.getRecentOrders(); if (__LIST__x != null && __LIST__x.length > 0) { for (var x_index in __LIST__x) { var x = __LIST__x[x_index]; ${x_index} : {$x.orderNumber} <br/> } } else { You have no recent orders. } Variable Declarations {var varName} {var varName = varInitExpr} A varName is any valid JavaScript variable name. A varInitExpr may not have any close-brace characters. Examples: {var temp = crypto.generateRandomPrime(4096)} Your prime is ${temp}. Macro Declarations {macro macroName(arg1, arg2, ...argN)} ...body of the macro... {/macro} A macro is like a JavaScript function, except the body of the macro is another JavaScript Template, not JavaScript. That is, the body of the macro may contain JST expressions and statements. The macroName may be any valid JavaScript variable name. The return value of an invoked macro is a string. You invoke the macro using the ${macroName()} expression syntax. Examples: {macro htmlList(list, optionalListType)} {var listType = optionalListType != null ? optionalListType : "ul"} <${listType}> {for item in list} <li>${item}</li> {/for} </${listType}> {/macro} Using the macro... ${htmlList([ 1, 2, 3])} ${htmlList([ "Purple State", "Blue State", "Red State" ], "ol")} {var saved = htmlList([ 100, 200, 300 ])} ${saved} and ${saved} Regarding macro scope: by default, macros are defined private to each template. If you want to export a macro so that it can be reused in other templates (such as building up a helper library of macros), one approach is to save a reference to your macro into your ''contextObject''. For example, in the ''contextObject'' that's the argument to ''template.process(contextObject)'', you can set ''contextObject'exported' = {};'' before you call process(). Then, here's how you can capture a macro into ''contextObject'exported'''... {macro userName(user)} {if user.aliasName != null && user.aliasName.length > 0} ${user.aliasName} {else} ${user.login} {/if} {/macro} ${exported.userName = userName |eat} Cleverly, you might also set ''contextObject'exported' = contextObject;'' It's circular, but it works. CDATA Text Sections {cdata} ...text emitted without JST processing... {/cdata} {cdata EOF} ...text emitted without JST processing... EOF You can use the '''{cdata EOF}...EOF''' or '''{cdata}...{/cdata}''' markup syntax to tell JST to ignore processing for a block of text. The text will be emitted without any tag or markup processing. This can be useful if you're using a JavaScript Template to generate a JavaScript Template. The 'EOF' may be any marker string without a '}' character. The marker string is used to delineate or 'bookend' a section of text. The '...' is your text, which may contain newlines, which the JST engine will emit without any transformations. For example... Hello, ${user.firstName}. An example of expression markup in JST looks like... {cdata END_OF_THE_CDATA_SECTION} ${customer.firstName} ${customer.lastName} END_OF_THE_CDATA_SECTION ...which shows a customer's name. Let me repeat that... {cdata} ${customer.firstName} ${customer.lastName} {/cdata} ...will show a customer's name. The above will output... Hello, Steve. An example of expression markup in JST looks like... ${customer.firstName} ${customer.lastName} ...which shows a customer's name. Let me repeat that... ${customer.firstName} ${customer.lastName} ...will show a customer's name. In-line JavaScript eval blocks {eval} ...javascript evaluated during JST processing... {/eval {eval EOF} ...javascript evaluated during JST processing... EOF The EOF can be any text without a close-brace ('}') character. The {eval} markup block can be useful to define multi-line JavaScript event handler functions near where they are used. <select onchange="sel_onchange()"></select> {eval} sel_onchange = function() { ...Do some complicated javascript...; ...more js code here...; } {/eval} Note in the above example that the 'var' keyword is not used, like 'var sel_onchange = function() {...}'. This is to ensure that sel_onchange will be in global scope and hence usable as an event handler function. minify blocks {minify} ...multi-line text which will be stripped of line-breaks during JST processing... {/minify {minify EOF} ...multi-line text which will be stripped of line-breaks during JST processing... EOF The EOF can be any text without a close-brace ('}') character. A {minify} block allows you to inline long JavaScript or CSS code into your HTML attributes. For JavaScript, this is especially useful for event handlers like onchange, onmousedown, onfocus, onblur, etc. Without {minify}, handling linebreaks or newlines in long JavaScript code is possible but unwieldy. <select onchange="{minify} ...Do some complicated multi-line javascript...; ...more js code here...; this.enabled = false; {/minify}"> <select onchange="{minify END_OF_JS} ...Do some complicated multi-line javascript...; ...more js code here...; this.enabled = false; END_OF_JS"> The {minify} block is also useful to make long inline CSS <style> attributes readable and maintainable, which can sometimes be useful in Internet Explorer which does not seem to support dynamically generated <style> tags. <div id="commentPanel" style="{minify} display:none; margin: 1em; border: 1px solid #333; background: #eee; padding: 1em; {/minify}"> ... </div>
- trimpath-template-1.0.38.rar (5.3 KB)
- 下载次数: 8
相关推荐
基于java的开发源码-Beetl java模板引擎.zip 基于java的开发源码-Beetl java模板引擎.zip 基于java的开发源码-Beetl java模板引擎.zip 基于java的开发源码-Beetl java模板引擎.zip 基于java的开发源码-Beetl java...
Java模板引擎性能对比 Java模板引擎是Web应用程序中一个非常重要的组件,负责将数据绑定到模板中生成最终的HTML页面。不同的Java模板引擎具有不同的性能特点,因此选择合适的模板引擎对于Web应用程序的性能非常重要...
Handlebars.java是一款基于Java的模板引擎,其设计目标是提供一种简单、直观的方式来构建语义模板,使得开发者在处理视图层逻辑时可以更加高效。它借鉴了Mustache模板语言的许多概念,同时添加了一些特有的功能,以...
历史 (2009年HP 技术大会 提交的解决多环境部署问题>>:放在注释里的脚本) 应用范围 (全栈程序员或者前端或者美工) 功能概览 特色介绍 列表 ...其他同类比较(freemark,jsp,angularjs,nodejs 等)
卵石Pebble 是一个受Twig启发的 Java 模板引擎。它以继承功能和易于阅读的语法脱颖而出。它内置了自动转义功能以确保安全,并集成了对国际化的支持。欲了解更多信息,请访问网站。pebble-spring-boot-starter 的 ...
Java模板引擎之FreeMarker FreeMarker是一个开源的Java模板引擎,它被广泛应用于Web开发中,用于生成动态HTML、XML或其他格式的文本。这个强大的工具允许开发者将逻辑代码与表现层分离,使得网页设计人员可以专注于...
Beetl是一款强大的Java模板引擎,它旨在简化Java开发中的视图层逻辑,提供高效、易用、功能丰富的模板语言。这款开源库由国人开发,其设计目标是提高开发效率,减少开发工作量,使开发者可以更加专注于业务逻辑,而...
FreeMarker是一个强大的、开源的Java模板引擎,常用于Web应用中的动态内容生成,尤其是在MVC架构中,作为视图层的技术。它与JSP、JSTL等技术不同,FreeMarker是模型和视图完全分离的,使得开发者可以专注于业务逻辑...
Beetl是一款强大的Java模板引擎,它被设计用于简化Web应用中的视图层开发,将业务逻辑与表现层分离。Beetl的核心理念是“简洁、高效、易用”,为开发者提供了一种灵活且高性能的方式来生成HTML、XML、JSON等各种格式...
Handlebars.java 是一个不包含逻辑的,语义的 Java 模板引擎。 Maven: <groupId>com.github.jknack</groupId> <artifactId>handlebars ${handlebars-version} 示例代码: Handlebars handlebars = ...
JAVA源码Java模板引擎FreeMarker.tar
Beetl是一款强大的Java模板引擎,它为Java开发者提供了便捷的视图层开发方式,能够高效地处理HTML、XML、JSON等各种格式的模板。在Beetl v3.3.1版本中,开发者可以期待一系列优化和改进,使得模板渲染更加高效且易于...
Java模板引擎FreeMarker是一款强大的开源模板技术,常用于Web应用中的动态内容生成,尤其是在MVC架构中,作为视图层的解决方案。它与Spring、Struts等框架配合使用,能够将业务逻辑与页面展示分离,使得开发者可以...
java资源Java模板引擎 FreeMarker.tar提取方式是百度网盘分享地址
FreeMarker是一个强大的、开源的Java模板引擎,常用于Web应用中的动态内容生成,尤其是在MVC架构中,作为视图层的实现技术。它与JSP类似,但更专注于分离业务逻辑和显示逻辑,使得开发者可以编写更加清晰、独立于...
jetbrick-template-1x, Java模板引擎,快速轻松 jetbrick-template 2.0 已经 released,jetbrick-template 1.x 将不再提供新功能,只负责 Bug 修复。jetbrick模板 2.0文档:http://subchen.github.io
Java模板引擎Jetbrick-Template是Java Web开发中用于动态生成HTML或其他格式文本的工具,它在Spring MVC框架中的集成能够帮助开发者更高效地处理视图层的渲染工作。本篇文章将详细阐述如何在Spring MVC中配置和使用...
FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写,FreeMarker被设计用来生成HTML Web页面(为了提高页面的访问速度,把页面静态化),特别是基于MVC模式的应用程序