代码改变世界

Ader Template Engine exstact

2012-12-05 10:39  露珠的微笑  阅读(969)  评论(0编辑  收藏  举报

from http://www.codeproject.com/Articles/8141/Ader-Template-Engine

中文参考boke:http://www.cnblogs.com/caicaihui/archive/2008/07/07/1237756.html

Ader TemplateEngine is a .NET class library (written in C#) for generating text output from source template and input parameters.

 Functions :

  • equals(obj1, obj2) - invokes equals method on obj1 with obj2 as parameter. Returns boolean value.
  • cint(value) - return an int of value ,same as :Convert.toInt32() in C#
  • cdouble(value)  -return an double data
  • cdata(value)
  • createtypereference(type) - reference a static type 

                  exp:     #createtypereference("System.Math").Round(3.39789)#
                             #createtypereference("System.Math").PI#
                       or
                            < ad:set name="MyMath" value="#createtypereference("System.Math")#" />
                            #MyMath.Round(3.3)#
                            #MyMath.PI#

  • notequals(obj1, obj2) - Returns !equals(obj1, obj2). Is equivalent to calling: not(equals(obj1, obj2)).
  • iseven(num) - tests whether number is an even number.
  • isodd(num) - tests whether number is an odd number.
  • isempty(string) - tests whether string has 0 characters. Same as equals(string.Length, 0).
  • isnotempty(string) - tests whether string has at least 1 character.
  • isnumber(num) - tests whether num is of numeric type.
  • toupper(string) - converts string to upper case.
  • tolower(string) - converts string to lower case.
  • isdefined(varname) - tests whether variable named varname is defined.
  • ifdefined(varname, value) - returns value if varname is defined. Especially useful: #ifdefined("name", name)# - will output value of name if it's defined, otherwise will output nothing.
  • len(string) - returns length of string.
  • tolist(collection, property, delim) - will convert collection to string with delim as separator. If you pass property, the value of the property will be evaluated on each element of the collection. If you omit property, then the object itself will be used.
  • typeof(object) -returns type of  object,exp:typeof("abcd234") return"string" ,  typeof(3) return int
  • isnull(obj) - tests whether obj is null

  • not(boolvalue) - returns not (!) of boolean value.
  • iif(booleanExpression, iftruevalue, iffalsevalue) - same as booleanExpression ? iftruevalue : iffalsevalue in C#.
  • format(object, formatstring) - will call ToString(formatstring) on object. object has to implement IFormattable interface, otherwise ToString() will be called.
  • trim(string) - will trim string object

  • filter(collection, booleanproperty) - will return new List from collection for those objects whose boolean property property evaluates to true.

  • gt(obj1, obj2)- will return true if obj1 > obj2. (obj1 and obj2 must implement IComparable. All numeric types do).

  • lt(obj1, obj2) - will return true if obj1 < obj2. (obj1 and obj2 must implement IComparable. All numeric types do).

  • compare(obj1, obj2) - will return -1 if obj1 < obj2, 0 if obj1 = obj2, and 1 if obj1 > obj2. (obj1 and obj2 must implement IComparable. All numeric types do).

  • comparenocase(string1, string2) - will do case insensitive comparison of string1 and string2 and return true if they are equal.
  • or(bool1, bool2) - will return true if either bool1 or bool2 are true.

  • and(bool1, bool2) -will return true if both bool1 and bool2 are true.
  • stripnewlines(string) - will return all \r\n instances and replace them with space.

Built In Tags:

  •   IF
 <ad:if test="#equals(cust.country, "US"))#">
    You are US customer.
<ad:else>
    You are from: #cust.country# country.
</ad:if>
  •    FOREACH

You can loop through collection of elements (any object that implements IEnumerable interface) using FOREACH tag.

<ad:foreach collection="#collection#" var="cust" index="i">
#i#: #cust.lastname#, 
        #cust.firstname#
</ad:foreach>

 

 

基于.NET的免费开源的另模板引擎---VTemplate参考Kingthy's blog  http://www.cnblogs.com/kingthy/archive/2009/08/17/net-vtemplate.html