Index: openacs-4/packages/acs-templating/tcl/parse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/parse-procs.tcl,v diff -u -r1.55 -r1.56 --- openacs-4/packages/acs-templating/tcl/parse-procs.tcl 27 Jul 2015 12:19:14 -0000 1.55 +++ openacs-4/packages/acs-templating/tcl/parse-procs.tcl 7 Aug 2017 23:48:02 -0000 1.56 @@ -1,19 +1,22 @@ ad_library { ADP to Tcl Compiler for the ArsDigita Templating System, - Based on the original ADP to Tcl compiler by Jon Salz (jsalz@mit.edu) - Copyright (C) 1999-2000 ArsDigita Corporation - - This is free software distributed under the terms of the GNU Public - License. Full text of the license is available from the GNU Project: - http://www.fsf.org/copyleft/gpl.html - @author Karl Goldstein @author Stanislav Freidin + @author Jon Salz @cvs-id $Id$ } +# Based on the original ADP to Tcl compiler by Jon Salz (jsalz@mit.edu) + +# Copyright (C) 1999-2000 ArsDigita Corporation + +# This is free software distributed under the terms of the GNU Public +# License. Full text of the license is available from the GNU Project: +# http://www.fsf.org/copyleft/gpl.html + + namespace eval template {} ad_proc -public template::adp_include { @@ -32,7 +35,7 @@ The [list &book "bookdata" ...] tells adp_include to pass the book array by reference to the adp include, where it is - refered to via @book.field@. + referred to via @book.field@. @param uplevel how far up the stack should the adp_level be set to (default is the calling procedures level) @@ -478,25 +481,26 @@ return $formatted_message } -ad_proc -public template::adp_compile { source_type source } { +ad_proc -public template::adp_compile { {-file ""} {-string ""} } { Converts an ADP template into a chunk of Tcl code. Caching this code avoids the need to reparse the ADP template with each request. - @param source_type Indicates the source of the Tcl code to compile. - Valid options are -string or -file - @param source A string containing either the template itself - (for -string) or the path to the file containing the template (for -file) - + @param file The file name of the source + @param string string to be compliled @return The compiled code. + + Valid options are either -string or -file } { variable parse_list # initialize the compiled code set parse_list [list "set __adp_output {}; set __ad_conn_locale \[ad_conn locale\]"] - switch -exact -- $source_type { - -file { set chunk [template::util::read_file $source] } - -string { set chunk $source } - default { error "Source type must be -string or -file" } + 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 @@ -506,7 +510,7 @@ # avoid substituting when it is a percentage attribute to an HTML tag. regsub -all {([^0-9])%>} $chunk {\1} chunk # warn about the first ambiguity in the source - if [regexp {[0-9]+%>} $chunk match] { + 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