DekiScript HTML/XML Statements

DekiScript Developer Documentation

Home    Tutorials    Reference    Samples/FAQ

Table of Contents

Overview

DekiScript can be used in page HTML and in XML extensions.  With DekiScript you can generate dynamic HTML on the fly and embed real-time output into wiki pages.

DekiScript in HTML

The HTML attributes are used to dynamically convert the HTML content into a equivalent structure using DekiScript XML statements.  The following example shows the complete set of HTML attributes and how they affect the initial <elem> element (note: HTML attributes can be applied to any HTML element, such <p>, <ul>, <table>, etc.).

Before

<elem init="initialization1" if="condition1" foreach="var variable in collection" where="condition2" block="initialization2">inner</elem>

After

<eval:block value="initialization1">
	<eval:if test="condition1">
		<eval:foreach var="variable" in="collection" where="condition2">
			<eval:block value="initialization2">
				<elem>inner</elem>
			</block>
		</eval:foreach>
	</eval:if>
</eval:block>

 

If an attribute is missing then the corresponding DekiScript XML statement is omitted.  For example the following HTML content uses the foreach attribute to show a list of files attached to the current page.

<ul>
	<li foreach="var f in page.files">{{f.name}}</li>
</ul>

The HTML content is transformed into the following equivalent DekiScript XML content.

<ul>
	<eval:foreach var="f" in="page.files">
		<li>{{f.name}}</li>
	</eval:foreach>
</ul>

DekiScript in XML

DekiScript can also be used in XML extensions.  The syntax is slightly more verbose and alleviates the need for special attributes on HTML elements.

<eval:foreach [var="id"] in="list-or-map-expr" [where="bool-expr"]>

This construct loops over the contents of a list or map. (Note: this construct replaces the earlier <eval:for> construct; <eval:foreach> requires v1.9.1 or later)

Attribute
Type  Description 
var identifier (optional) Name of the variable to initialize for each iteration. (default: $)
in list/map Expression resulting in a list or map value.
where bool (optional) Condition for determining if the current item should be included in the iteration. (default: true)

Two additional variables are defined inside the foreach loop.

  • __count is the number of iterations where the "where" clause evaluated to true
  • __index is the number of iterations so far

Example

<eval:foreach var="x" in="[1, 2, 3, 4, 5, 6]" where="x % 2 == 0">
  <eval:expr value="x" /> is even.<br />
</eval:foreach>

<eval:if test="bool-expr"> <eval:elseif test="bool-expr"> <eval:else>

This contruct select a conditional branch. (Note: <eval:if> requires v1.8.3 or later; <eval:elseif> and <eval:else> where require v1.9.1 or later) 

Attribute
Type  Description 
test bool Condition for determining if the current item should be included in the iteration. (default: true)

Example

<eval:if test="value &lt; 0">Less than zero.</eval:if>
<eval:elseif test="value &gt; 0">Greater than zero.</eval:elseif>
<eval:elseif test="value == 0">Value is zero</eval:elseif>
<eval:else>Value is not a number.</eval:else>

<eval:expr [value="expr"]>

Evaluates an expression and renders its result. (Note: the form with the 'value' attribute requires v1.9.1 or later)

Attribute
Type  Description 
value any (optional) Expression to render. (default: use text contents of element)

Example 1

<eval:expr value="args.value" />

Example 2

<eval:expr>args.value</eval:expr>

<eval:js [value="expr"]>

Evaluates an expression and renders its result as a JavaScript value.  This construct is a shorthand for <eval:expr>json.emit(expr)</eval:expr> or <eval:expr value="json.emit(expr)" />. (Note: the form with the 'value' attribute requires v1.9.1 or later)

Attribute
Type  Description 
value any (optional) Expression to render. (default: text contents of construct)

Example 1

<eval:js value="args.value" />

Example 2

<eval:js>args.value</eval:js>

<eval:block value="expr">

Evaluates an expression and scopes the result to the elemen. (Note: this contruct requires v8.05.1 or later) 

Attribute
Type  Description 
value any Expression to evaluate.

Example

<eval:scope value="var x = 1 + 2">
  x has value <eval:expr value="x" />
</eval:scope>
 
Tag page
Viewing 1 of 1 comments: view all
Nice work merging the HTML and XML pages, much clearer!
Posted 18:26, 8 Aug 2008
Viewing 1 of 1 comments: view all
You must login to post a comment.