-
Notifications
You must be signed in to change notification settings - Fork 12
Cht api
Please note that this page describes high-level and low-level facilities alike. In order to better understand the efficient ways of building your Web applications with CHT, refer to the Concepts section of this Wiki.
dojo.require( 'dojox.jtlc.compile' );
var evaluator = dojox.jtlc.compile( input, language, compile_time_options );
Invokes the jtlc compiler, producing a Javascript function object evaluator from the abstract syntax tree described by the input.
Due to the distributed nature of jtlc language definitions, the output is determined primarily by the types of the AST nodes while the language argument affects the interpretation of untyped nodes of the tree (values, objects that don’t define a compile() method, arrays) as well as provides a set of global options available to all node types. At present, jtlc language objects can be constructed by instantiating one of the following classes: dojox.jtlc.JXL, dojox.jtlc.qplus and dojox.jtlc.CHT.
Additionally, the optional argument compile_time_options may serve to pass in a dictionary of options to the specific compilation. These options are dependent on the nature of the language and node types used; for examle, CHT uses this mechanism to provide localization dictionaries to templates.
dojo.require( 'dojox.jtlc.JXL' );
Class encapsulating the global options for the Javascript Transformation Language. Note that JXL itself is mostly defined by the AST node types in the module dojox.jtlc.tags that are described in the JXL primitives section of this Wiki.
var jxl = new dojox.jtlc.JXL( options );
Instantiates language description for JXL that can be customized by specifying the following settings:
-
elideNulls: when true,nullvalues are not placed into array or dictionary sinks but are thrown away instead (with their corresponding keys in case of a dictionary); -
failOnDuplicateKeys: when true, an attempt to insert a duplicate key into the dictionary sink results in an exception; -
queryLanguage: by default this option is set todojox.json.query. You may substitute another query language compiler with a compatible API; -
replaceLanguage: by default this option is set todojo.replace. You may substitute a formatting function of your own with compatible API.
dojo.require( 'dojox.jtlc.qplus' );
Class implementing the parser and encapsulting the global options for the Q+ query language. Normally Q+ queries are used from within CHT templates, but dojox.jtlc.qplus can also be used on its own as a streamlined notation for JXL. Note however that Q+ can represent only a subset of all possible JXL trees and is not intended to be a functionally complete data transformation language.
var qplus = new dojox.jtlc.qplus( options );
Argument {{options}} is a bag of properties customizing the interpretation of the data query language. At the moment the only user-accessible option property is filters that can be used to pass in a dictionary containing user-defined functions or expressions encoded as strings:
var qplus = new dojox.jtlc.qplus( {
filters: {
fromHex: function(str){ parseInt(str,16); },
toHex: "$.toString(16)"
}
} );
More details regarding the custom filters are available within the Q+ query language reference.
var ast = qplus.parse( query, is_a_query_list );
Parses a single Q+ query into an abstract syntax tree that can be accepted as input by dojox.jtlc.compile(). If a truthy value is passed for the optional argument is_a_query_list, the query is expected to contain a comma-separated list of Q+ queries and the method will return an array of JXL trees.