[UP]
Modules
 Wd_application_dtd
 Wd_cycle
 Wd_dialog
 Wd_dictionary
 Wd_encoding
 Wd_interactor
 Wd_run_cgi
 Wd_run_jserv
 Wd_run_fcgi
 Wd_stdlib
 Wd_template
 Wd_templrep
 Wd_transform
 Wd_types
 Wd_serialize_types
 Wd_universe
 Wd_upload
 Wd_var_functions
   
WDialog API for Objective Caml: Wd_templrep

Module Wd_templrep


module Wd_templrep: sig .. end
Template representation

type 'a Pxp_document.node #Pxp_document.extension as 'a t 
The type of prepared templates

type 'a Pxp_document.node #Pxp_document.extension as 'a param = {
   param_tree : 'a Pxp_document.node; (*parameter as XML tree*)
   param_text : string Lazy.t; (*parameter as string*)
}
The type of parameters to instantiate. In param_tree, the instantiation text must be passed as XML tree; in param_text, the same must be passed as string. The first component is used if a parameter is found in element context; the second component is used if a parameter is found in an attribute value. param_text is a lazy-evaluated value because it is unlikely that the string transcription is actually used.

type expr =
| Expr_var of string (*a variable in an expr*)
| Expr_strconst of string (*a string constant*)
| Expr_apply of (string * expr list) (*a function call*)
| Expr_param of (string * string list) (*a template parameter*)
Expressions inside $...
val prepare_tree_with_parameters : mk_uiencode:(unit ->
('a Pxp_document.node #Pxp_document.extension as 'a)
Pxp_document.node) ->
string ->
Wd_types.application_type -> 'a Pxp_document.node list -> 'a t
let pt = prepare_tree_with_parameters ~mk_uiencode name app nodes:

Prepares the node list nodes for the instantiation of parameters. nodes remains unmodified; but references to inner nodes of nodes are stored in pt (this should be transparent). app is the application. name is the name of the template; it is only used to generate error messages.

The preparation procedure scans all data nodes and all attribute values for '$' parameters. pt contains a restructured copy of nodes in which the parameters are specially marked up such that the instantiation procedure can find them quickly.

Recognized forms:

  • $name: Replaced by the parameter name here
  • ${name}: Same
  • ${name/enc1/enc2/...}: Apply the encodings enc1,enc2,... in turn before replacing
  • $[name]: Replaced by the value of the dialog variable name.
  • $[name/enc1/enc2/...]: Apply the encodings enc1,enc2,... in turn before replacing
~mk_uiencode: This function must return an empty <ui:encode/> node. Such nodes are generated for ${name/enc1/enc2/...} in element context.
val get_parameters : ('a Pxp_document.node #Pxp_document.extension as 'a) t ->
unit Wd_types.dict
Returns the parameters that have been found in the template as dictionary
val instantiate : ?eval_expr:(expr -> string) ->
('a Pxp_document.node #Pxp_document.extension as 'a) t ->
'a param Wd_types.dict list -> 'a Pxp_document.node -> unit
instantiate ~eval_expr pt params container:

Instantiates the already prepared tree pt, and sets the sub nodes of container to the new instance (the instance is a node list). The parameters are searched in params, strictly from left to right.

An Instantiation_error is raised if something goes wrong.

~eval_expr: Evaluates an expression found inside brackets $[expr] and returns the result as string. The expression never contains Expr_param nodes, because these have already been replaced by Expr_strconst nodes.