template::adp_compile (public)
template::adp_compile [ -file file ] [ -string string ]
Defined in packages/acs-templating/tcl/parse-procs.tcl
Converts an ADP template into a chunk of Tcl code. Caching this code avoids the need to reparse the ADP template with each request.
- Switches:
- -file (optional)
- The filename of the source
- -string (optional)
- string to be compiled
- Returns:
- The compiled code. Valid options are either -string or -file
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- ad_dimensional, template_widget_file, xowiki_test_cases
Source code: variable parse_list # initialize the compiled code set parse_list [list "set __adp_output {}; set __ad_conn_locale \[ad_conn locale\]"] if {$file ne "" && $string ne ""} { error "you must specify either -file or -string" } elseif {$file ne ""} { set chunk [template::util::read_file $file] } else { set chunk $string } # substitute <% ... %> blocks with registered tags so they can be handled # by our proc rather than evaluated. regsub -all -- {<%} $chunk {<tcl>} chunk # avoid substituting when it is a percentage attribute to an HTML tag. regsub -all -- {([^0-9])%>} $chunk {\1</tcl>} chunk # warn about the first ambiguity in the source if {[regexp {[0-9]+%>} $chunk match]} { ns_log warning "ambiguous '$match'; write Tcl escapes with a space like" {<% set x 50 %> and HTML tags with proper quoting, like <hr width="50%">} "when compiling ADP source: " [list template::adp_compile -file $file -string $string] } # recursively parse the template adp_compile_chunk $chunk # ensure that code returns with the output lappend parse_list "set __adp_output" # the parse list now contains the code set code [join $parse_list "\n"] #ns_log notice "CODE before i18n\n$code\n" # Substitute #foo# message keys with values from the message catalog # Since messages may read the variables of the adp page they go through # expand_percentage_signs which amongst other things does an uplevel subst while {[regsub -all {([^\\])\#([-[:alnum:]_:]+[.][-[:alnum:]_:]+)\#} $code {\1[template::expand_percentage_signs [lang::message::lookup $__ad_conn_locale {\2} {TRANSLATION MISSING} {} -1]]} code]} {} # # We do each substitution set in several pieces, separately for # normal variables and for variables having ";noquote", ";no18n", # and ";literal" attached to them. Specifically, @x@ gets # translated to [ns_quotehtml ${x}], whereas @x;noquote@ gets # translated to ${x}. The same goes for array variable # references. # # The approach with several regexp operations can be optimized, # but since this is happening only at ADP compile time, this does # not seem critical. # substitute array variable references while {[regsub -all -- [adp_array_variable_regexp_noquote] $code {\1[template::adp_parse_tags_and_localize $\2(\3)]} code]} {} while {[regsub -all -- [template::adp_array_variable_regexp_noi18n] $code {\1[ns_quotehtml $\2(\3)]} code]} {} while {[regsub -all -- [template::adp_array_variable_regexp_literal] $code {\1$\2(\3)} code]} {} while {[regsub -all -- [template::adp_array_variable_regexp] $code {\1[ns_quotehtml [lang::util::localize $\2(\3)]]} code]} {} # substitute simple variable references while {[regsub -all -- [adp_variable_regexp_noquote] $code {\1[template::adp_parse_tags_and_localize ${\2}]} code]} {} while {[regsub -all -- [template::adp_variable_regexp_noi18n] $code {\1[ns_quotehtml ${\2}]} code]} {} while {[regsub -all -- [template::adp_variable_regexp_literal] $code {\1${\2}} code]} {} while {[regsub -all -- [template::adp_variable_regexp] $code {\1[ns_quotehtml [lang::util::localize ${\2}]]} code]} {} # unescape protected "#" and "@" references set code [string map { \\@ @ \\# #} $code] return $codeXQL Not present: Generic, PostgreSQL, Oracle