Anvil | Smiths Smiths | Register Register | Login Login |
Search:
Show links Show tools Show tree | Previous document Next document | njet.org > Anvil > Documentation > Language reference > Templates > Tag libraries

Tag libraries

XXX. An import tag specifies the location of file containing specification of taglib in xml format and name of tag namespace used when searching for custom tags. If namespace is left empty then tag appear in default namespace; wihtout any prefix.

Specification

 <taglib name="library-name">

   <version>library-version</version>
   <info>library-info</info>

   ( <tag name="tag-name">
   
      ( <attribute name="attr-name">
         <type>(boolean|int|double|string|expr)</type>
         <required>(false|true)</required>
       </attribute> )*
       
      <hascontent>(false|true)</hascontent>

      <inithandler>name-of-handler-function</inithandler> 

      [ <starthandler>name-of-handler-function</starthandler> 
      | <startmethod>name-of-handler-method</startmethod> ]
      
      [ <endhandler>name-of-handler-function</endhandler> 
      | <endmethod>name-of-handler-method</endmethod> ]

      [ <releasehandler>name-of-handler-function</releasehandler> 
      | <releasemethod>name-of-handler-method</releasemethod> ]
      
   </tag> )*

 </taglib>

Specification tags

tagilb
Defines a tag library
Attributes:
name
Name of library.


version
Specifies the version of the tag library. Not really used for anything, yet.

info
Specifies some information about the tag library. Not really used for anything, yet.

tag
Definition of one tag, can contains attributes.
Attributes:
name
Name of tag.


hascontent
Declares if this tag is to have content, i.e. it can contain character data and other tags. Given as ``true创 or ``false创.

inithandler
Declares the name of function doing the initialization. Function is looked up from the namespace specified in import statement.

starthandler
Declares the name of (optional) function doing the pre condition check. This atribute is mutually exclusive with startmethod.

endhandler
Declares the name of (optional) function doing the post condition check. This atribute is mutually exclusive with endmethod.

releasehandler
Declares the name of (optional) function doing the release operation. This atribute is mutually exclusive with releasemethod.

startmethod
Declares the name of (optional) method doing the pre condition check. Named method is invoked from the return value if inithandler. This atribute is mutually exclusive with starthandler.

endmethod
Declares the name of (optional) method doing the post condition check. Named method is invoked from the return value if inithandler. This atribute is mutually exclusive with endhandler.

releasemethod
Declares the name of (optional) function doing the release operation. Named method is invoked from the return value if inithandler. This atribute is mutually exclusive with releasehandler.

attribute
Definition of one attribute in tag. Attributes are evaluted to array passed as a third parameter to init handler. Attributes:
type
  • ``boolean创 for boolean as ``true创 or ``false创.
  • ``int创 for integer.
  • ``double创 for floating point number.
  • ``string创 for string.
  • ``expr创 for expression.
Default is ``string创.
required
Is this attribute required, default is ``false

Compilation with function handlers

  // first parameter contains the context of
  //   enclosing custom tag, or undefined if
  //   there is no such tag.
  // second parameter is name of tag as NS:NAME
  // third parameter contains array with attributes evaluted
  //   and mapped to their names, given in specification.
  var ctx = taglib.<<initHandler>>(anvil.lang.context(), tagname, attributes);
  // if starthandler, endhandler and releasehandler
  // are not given, following statements do not apply
  try {

    // while(true) if starthandler not given
    while(taglib.<<startHandler>>(ctx)) {

      // contained statements here

      // following is omitted, if endhandler not given
      if (!taglib.<<endHandler>>(ctx)) {
        break;
      } 
    }
    
  } finally {
    //omitted if releasehandler not given
    taglib.<<releaseHandler>>(ctx);
  }

Compilation with method handlers

  var ctx = taglib.<<initHandler>>(anvil.lang.context(), tagname, attributes);
  try {

    // while(true) if startmethod not given
    while(ctx.<<startmethod>()) {

      // contained statements here

      // following is omitted, if endmethod not given
      if (!ctx.<<endmethod>>()) {
        break;
      } 
    }
    
  } finally {
    //omitted if releasemethod not given
    ctx.<<releasemethod>>();
  }

Function and method handlers may be used together. A call to anvil.lang.context() returns the context of current tag (i.e. return value from inithandler)

See also  | Templates  | <import>  | Non-template tags
Contributes notes:
2002-11-28 Simo Handler function return values
As return values are significant, one should explicitly return true of false (start- and endhandler).
If you don't return anything the return value of last statement in your function is used. (a Anvil feature, nice in anonymous functions)
Add a note
What's new | Anvil