template::expand_percentage_signs (public)

 template::expand_percentage_signs message

Defined in packages/acs-templating/tcl/parse-procs.tcl

Expand variables marked with percentage signs in caller's scope. Some examples - if example and array(variable) has the values Erik and Oluf in the caller's scope - the following expansion will occur: Here is an %example% variable. -> Here is an Erik variable. Here is an %array.variable% for you -> Here is an Oluf for you

Parameters:
message
Author:
Christian Hvid

Partial Call Graph (max 5 caller/called nodes):
%3 test_expand_percentage_signs expand_percentage_signs (test acs-templating) template::expand_percentage_signs template::expand_percentage_signs test_expand_percentage_signs->template::expand_percentage_signs lang::message::embedded_vars_regexp lang::message::embedded_vars_regexp (public) template::expand_percentage_signs->lang::message::embedded_vars_regexp template::adp_compile template::adp_compile (public) template::adp_compile->template::expand_percentage_signs

Testcases:
expand_percentage_signs
Source code:
    set remaining_message $message
    set formatted_message ""
    while { [regexp [lang::message::embedded_vars_regexp$remaining_message  match before_percent percent_match remaining_message] } {
        append formatted_message $before_percent

        if {$percent_match eq "%%"} {
            # A quoted percentage sign
            set substitution "%"
        } else {
            # An embedded variable

            # Remove any noquote instruction
            set quote_p 1
            if { [regsub {;noquote} $percent_match {} substitution] } {
                # We removed a noquote instruction so don't quote
                set quote_p 0
            }

            # Convert syntax to Tcl syntax:
            # It's either an array variable or a Tcl variable
            #   array variables
            # TODO: ns_quotehtml
            # TODO: lang::util::localize
            regsub -all -- {[\]\[\{\}\"]\\$} $substitution {\\&} substitution
            if { [regexp {^%([[:alnum:]_]+)\.([[:alnum:]_]+)%$} $substitution match arr key] } {
                # the array key name is substitured by the Tcl parser s
                regsub -all -- {[\]\[\{\}\"]\\$} $key {\\&} key
                set command "set ${arr}(${key})"
                set substitution [uplevel $command]
            }
            if { [regexp {^%([[:alnum:]_:]+)%$} $substitution match var] } {
                set command "set $var"
                set substitution [uplevel $command]
            }
            if {$quote_p} {
                set substitution [ns_quotehtml $substitution]
            }
        }

        append formatted_message $substitution
    }

    append formatted_message $remaining_message

    return $formatted_message
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: