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):
%3 test_ad_dimensional ad_dimensional (test acs-templating) template::adp_compile template::adp_compile test_ad_dimensional->template::adp_compile test_template_widget_file template_widget_file (test acs-templating) test_template_widget_file->template::adp_compile test_xowiki_test_cases xowiki_test_cases (test xowiki) test_xowiki_test_cases->template::adp_compile lang::message::lookup lang::message::lookup (public) template::adp_compile->lang::message::lookup lang::util::localize lang::util::localize (public) template::adp_compile->lang::util::localize template::adp_array_variable_regexp template::adp_array_variable_regexp (public) template::adp_compile->template::adp_array_variable_regexp template::adp_array_variable_regexp_literal template::adp_array_variable_regexp_literal (public) template::adp_compile->template::adp_array_variable_regexp_literal template::adp_array_variable_regexp_noi18n template::adp_array_variable_regexp_noi18n (public) template::adp_compile->template::adp_array_variable_regexp_noi18n general_comments_get_comments general_comments_get_comments (public) general_comments_get_comments->template::adp_compile packages/acs-api-browser/www/content-page-view.tcl packages/acs-api-browser/ www/content-page-view.tcl packages/acs-api-browser/www/content-page-view.tcl->template::adp_compile rp_handle_request rp_handle_request (private) rp_handle_request->template::adp_compile template::adp_init template::adp_init (public) template::adp_init->template::adp_compile template::cmp_page_filter template::cmp_page_filter (private) template::cmp_page_filter->template::adp_compile

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 $code
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: