Was this page helpful?

DekiScript Literals

    DekiScript Developer Documentation

    Home    Beginner's Guide    Tutorials/Samples/FAQ    Reference

    The following table lists the DekiScript literal values.

    DekiScript Literals

    Data Type Description
    nil The empty value, represented by _, nil, and null.
    bool A logical value, represented by true and false.
    num A 64-bit floating point value.
    str A character string.
    magic identifier An automatically generated string that is guaranteed to be unique across scopes.
    map An associative array that assigns a key to an expression.
    list An indexed array of expressions.

     

     

    Nil Literal

    The empty value is represented by _, nil, and null.  All tokens are synonymous and their variations are provided for convenience.

    Usage Restrictions

    1.8.1 or later.

    Samples

      Output

    To pass an empty value as an optional parameter value:


    Version 1

    {{ web.Link("http://wiki.opengarden.org", _ ) }}
    

    Version 2

    {{ web.Link("http://wiki.opengarden.org", nil ) }}
    

    Version 3

    {{ web.Link("http://wiki.opengarden.org", null ) }}
    

     

    http://wiki.opengarden.org

     

     

     

    Bool Literal

    A logical value, represented by true and false.

    Usage Restrictions

    1.8.1 or later.

    Samples

      Output

    To pass a bool as a parameter:

    {{ string.Compare("abc", "ABC", true) }}

    0

     

    To display different output depending on a bool value:

    {{ date.DayOfWeek(date.now) == 4 ? "Today is Thursday" : "Today is not Thursday" }}

    Today is not Thursday

     

     

     

    Num Literal

    Numbers must have a decimal part and may have an optional decimal exponent.  DekiScript also accepts hexadecimal constants, by prefixing them with 0x.  Numbers are stored as 64-bit floating point values.

    Examples of valid numbers are: 

    • 3
    • 3.1416
    • 314.16e-2
    • 0.31416E1
    • 0xff
    • 0xFFFFFF


    Refer here for a comprehensive list of DekiScript number functions and variables.

    Usage Restrictions

    1.8.1 or later.

    Samples

      Output

    To evaluate an arithmetic expression:

    {{ (0.31416E1*9) + 4 }}

    32.2744

    To display a number using the currency format string:

    {{ num.format(5.75, "C") }}

    $5.75

     

     

    Str Literal

    A character string.  Strings can be delimited by matching single or double quotes and can contain these escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\uXXXX' (encoded character where 'XXXX' is the hexadecimal unicode value), '\v' (vertical tab), '\\' (backslash), '/' (slash), '\"' (double quote), and '\'' (single quote).  Strings in DekiScript may contain any 16-bit value, including embedded zeros, which can be specified as '\0'.

    Starting in v1.9.1, the characteres  of a string can be accessed by using a numeric expression surrounded by brackets ([]).  The first character in a string has index 0.  If the index is not within range, the expression evaluates to nil.

    Refer here for a comprehensive list of DekiScript string functions.

    Usage Restrictions

    1.8.1 or later.

    Samples

      Output

    To display a string:

    Version 1

    {{ "Hello world!" }}

    Version 2

    {{ 'Hello world!' }}

    Hello world!

     

    To calculate the length of a string:

    {{ #'Hello world!' }}

    12

     

    To use quotes (no escape sequence required):

    {{ "This is a single quote: '"..' and this is a double quote: "'  }}

    This is a single quote: ' and this is a double quote: "

    To use quotes (escape sequence required):

    {{ 'This is a single quote: \''.." and this is a double quote: \""  }}

    This is a single quote: ' and this is a double quote: "

    To access the second character in a string:

    {{ 'Hello world!'[1] }}

    e

     

     

     

    Magic Identifier

    An automatically generated string that is guaranteed to be unique across scopes.  The scope of a magic identifier is a single page or template instance.  For example, if a page or template is loaded multiple times via inclusion, each page will have unique values for its magic identifiers.

    Magic identifiers are commonly used to create channels for PubSub communication.  By using magic identifiers, the channels are guaranteed to be unique and not interfere with similarly named channels on other included pages.

    Usage Restrictions

    1.8.2 or later.

    Samples

      Output

    To display a magic identifier:

    {{ @myid }}
    

    myid_Vucsnpo1

     

     

    To publish and suscribe to a channel that is guaranteed to be unique across scopes:

    {{ dhtml.button("Click me!", { "field1": "Clicked" }, @mychannel)}}
    {{ dhtml.div(@mychannel, "field1") }}
    

     

     

     

    Sample DekiScript extension to create and populate a div element.  Note that a magic identifier is used to uniquely identify the div:

    <extension>
      <function>
        <name>div</name> 
        <description>Simple DekiScript Sample to create and populate a div.</description> 
        <return>
          <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
            <body>
              <div eval:id="@id" />
            </body>
            <tail>
              <script type="text/javascript">
                  var container = document.getElementById(<eval:js>@id</eval:js>);
                  container.innerHTML = "Div id is:  " + container.id;
              </script>
            </tail>
          </html>
        </return>
      </function>
    </extension>
    N/A

     

     

    List Literal

    An indexed array of expressions.  The evaluation order of expressions inside a list is non-deterministic.  Examples of valid lists are:

    • [ ]
    • [ 1, 2, 3 ]
    • [ 1, _, "hi" ]

    The values of a list are accessed by using a numeric expression surrounded by brackets ([]).  If the index is not within range, the expression evaluates to nil.

    Usage Restrictions

    1.8.1 or later.

    Samples

      Output

    To calculate the length of a list:

    {{ #[ 1, _, "Hello".." World!" ] }}

    3

    To pass a list as a parameter:

    {{ string.Join(["item1", "item2", "item3"], "/") }}

    item1/item2/item3

    To access the second element of a list:

    {{ [ 1, [1, 2], 3 ][1] }}

    [ 1, 2 ]

     

     

    Map Literal

    An associative array that assigns a key to an expression.  The key can either be a name, a string, a number, or another expression.  If the key expression evaluates to a literal that has not string representation or is nil, the value expression is not evaluated.  The evaluation order of expressions inside a map is non-deterministic.  Examples of valid maps are:

    • { }
    • {  first: "Hi", second: "bye" }
    • { "#1": "First", '#2': { } }
    • { ("#" .. "1") : "First", (1 + 2) : "Second" }

    The values of a map are accessed by providing the key either as a name preceded by a dot (.) or as an expression surrounded by brackets ([]).  If the key is not found in the map, the expression evaluates to nil.

    Usage Restrictions

    1.8.1 or later.

    Samples

         

    To calculate the key for a map:

    {{ { (user.name): user.id } }}

    { SteveB : 6 }

    To calculate the length of a map:

    {{ #{ first: 1, second: _, third: "Hello".." World!" } }}

    3

    To access a map value by name:

    {{ { first: 1, second: _, third: "Hello".." World!" }.first }}

    1

    To access a map by index:

    {{ { first: 1, third: "Hello".." World!", second: _ }["third"] }}

    Hello World!

      

    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by