util-procs.tcl

Utility procedures for the ArsDigita Templating System

Location:
packages/acs-templating/tcl/util-procs.tcl
Authors:
Karl Goldstein <karlg@arsdigita.com>
Stanislav Freidin <sfreidin@arsdigita.com>
CVS Identification:
$Id: util-procs.tcl,v 1.46 2024/12/05 16:13:02 antoniop Exp $

Procedures in this file

Detailed information

anchor_form (public)

 anchor_form [ -id id ] [ -vars vars ] [ -action action ] \
    [ -label label ]

return an inline form with the appearance of an anchor

Switches:
-id (optional)
-vars (optional)
-action (optional)
-label (optional, defaults to "link")

Testcases:
No testcase defined.

stack_dump (public, deprecated)

 stack_dump
Deprecated. Invoking this procedure generates a warning.

return the whole call stack as HTML DEPRECATED: does not comply with OpenACS naming convention.

See Also:

Testcases:
No testcase defined.

template::resource_path (public)

 template::resource_path [ -verbose ] -type type -style style \
    [ -relative ] [ -subsite_id subsite_id ] [ -theme_dir theme_dir ]

Process the templating "style" and return the stub (path without extensions). When the style is not an absolute path, check if the resource can be obtained from the theme, if not fallback to the resources directory of acs-templating.

Switches:
-verbose (optional, boolean, defaults to "false")
-type (required)
type of resource (e.g. "forms" or "lists")
-style (required)
name of the resource within the type (e.g. "standard")
-relative (optional, boolean)
return optionally the path relative to the OpenACS root directory
-subsite_id (optional)
subsite_id to determine theming information
-theme_dir (optional)
theming directory (alternative to determination via subsite), higher priority
Returns:
path of the resource (without extension)
Author:
Gustaf Neumann

Testcases:
No testcase defined.

template::stack_dump (public)

 template::stack_dump

Return the whole call stack as HTML

Testcases:
No testcase defined.

template::stack_frame_values (private)

 template::stack_frame_values level

return the variables and arrays of one frame as HTML

Parameters:
level (required)

Testcases:
No testcase defined.

template::streaming_template (public)

 template::streaming_template [ -subsite_id subsite_id ]

Return the path of the streaming template

Switches:
-subsite_id (optional)
id of the subsite. Defaults to [ad_conn subsite_id]
Returns:
path to themed template

Testcases:
No testcase defined.

template::themed_template (public)

 template::themed_template [ -verbose ] path

Given a path like /packages/acs-admin/www/index pointing to an .adp file, this function tries to locate this path in the ResourceDir of the subsite (determined by the theme). If found the themed template is returned, otherwise the passed template path.

Switches:
-verbose (optional, boolean, defaults to "false")
Parameters:
path (required)
absolute path within the open acs tree (without extension)
Returns:
path to themed template or input value (without extension)

Testcases:
No testcase defined.

template::util::array_to_vars (public, deprecated)

 template::util::array_to_vars arrayname
Deprecated. Invoking this procedure generates a warning.

Declare local variables for every key in an array.

Parameters:
arrayname (required)
The name of an array in the calling frame. DEPRECATED: this is a trivial idiom that can just be inlined.
See Also:
  • array

Testcases:
No testcase defined.

template::util::get_opts (public)

 template::util::get_opts argv

Builds an array named "opts" in the calling frame, containing all switches passed at the end of a proc. The array values are either switch parameters or 1 if no parameter was specified. Problem: there is currently no way to specify an option parameter that begins with a dash. This particularly problematic for negative numbers.

Parameters:
argv (required)

Testcases:
get_opts

template::util::get_url_directory (public)

 template::util::get_url_directory url

Get the directory portion of a URL. If the URL has a trailing slash, then return the entire URL.

Parameters:
url (required)

Testcases:
get_url_directory

template::util::is_nil (public)

 template::util::is_nil ref

Determines whether a variable both exists and is not an empty string.

Parameters:
ref (required)
The name of a variable to test in the calling frame.
Returns:
1 if the variable either not exist or is an empty string. 0 if the variable is either an array reference or a nonempty scalar.

Testcases:
util_is_nil

template::util::is_true (public, deprecated)

 template::util::is_true x
Deprecated. Invoking this procedure generates a warning.

interprets its argument as a boolean.

Parameters:
x (required)
the value to test DEPRECATED 5.10.1: since October 2015 this proc is implemented via the standard Tcl idiom "string is true -strict ..." that can be easily inlined.
Returns:
0 if the variable can be interpreted as false; 1 for true if it can't.
See Also:
  • string

Testcases:
No testcase defined.

template::util::is_unique (public)

 template::util::is_unique table columns values

Queries a database table for the existence of a particular row. Useful for validating form input to reduce the possibility of unique constraint violations.

Parameters:
table (required)
The name of a database table.
columns (required)
A list of columns on which to select the row.
values (required)
A list of values for each specified column.
Returns:
1 if the row exists, 0 if not

Testcases:
No testcase defined.

template::util::list_of_lists_to_array (public)

 template::util::list_of_lists_to_array lists array_ref

Converts a list of lists in the form { { key value } { key value } ... } to an array.

Parameters:
lists (required)
array_ref (required)

Testcases:
No testcase defined.

template::util::list_of_ns_sets_to_multirow (public)

 template::util::list_of_ns_sets_to_multirow -rows rows \
    -var_name var_name [ -level level ]

Transform a list of ns_sets (e.g. produced by db_list_of_ns_sets) into a multirow datasource.

Switches:
-rows (required)
The data to be transformed
-var_name (required)
The name of the multirow to create
-level (optional, defaults to "1")
How many levels up the stack to place the new datasource, defaults to 1 level up.

Testcases:
No testcase defined.

template::util::list_to_array (public, deprecated)

 template::util::list_to_array values array_ref columns
Deprecated. Invoking this procedure generates a warning.

Converts a list of values into an array, using a list of corresponding column names for the array keys.

Parameters:
values (required)
A list of values
array_ref (required)
The name of the array to create in the calling frame.
columns (required)
A list of column names to use for the array keys. The length of this list should be the same as the values list. DEPRECATED: as of August 2022 no OpenACS code is using this proc. The operation it implements can be easily achieved via plain Tcl idioms.
See Also:
  • array

Testcases:
No testcase defined.

template::util::list_to_lookup (public)

 template::util::list_to_lookup values array_ref

Turn a list into an array where each key corresponds to an element of the list... Sort of like a sparse bitmap. Each value corresponds to the key's position in the input list.

Parameters:
values (required)
A list of values
array_ref (required)
The name of the array to create in the calling frame.

Testcases:
util_list_to_lookup

template::util::list_to_multirow (public)

 template::util::list_to_multirow name rows [ level ]

populate a multirow data source from a list string gotten from a call to template::util::multirow_to_list

Parameters:
name (required)
the name of a multirow data source
rows (required)
a representation of a multirow data source as a list, suitable for passing by value in the form { { row } { row } { row } ... }
level (optional, defaults to "1")
See Also:

Testcases:
lists_and_multirows

template::util::lnest (public)

 template::util::lnest listref value next [ args... ]

Recursive procedure for building a hierarchical or multidimensional data structure in a list.

Parameters:
listref (required)
value (required)
Either a list or scalar value to store in the list.
next (required)
A key value that determines the next node to traverse outward in the data structure.

Testcases:
No testcase defined.

template::util::lpop (public)

 template::util::lpop ref

Removes the last item from a list. The operation is performed in-place, rather than returning the new list.

Parameters:
ref (required)
The name of a list in the calling frame on which to operate.

Testcases:
xowiki_test_cases, create_form_with_form_instance

template::util::master_to_file (public)

 template::util::master_to_file url [ reference_url ]

Resolve a URL into an absolute file path, but respect styled master configuration for named masters (e.g. acs-templating/resources/masters/... containing 2cols.adp)

Parameters:
url (required)
reference_url (optional)

Testcases:
No testcase defined.

template::util::multirow_quote_html (public)

 template::util::multirow_quote_html multirow_ref column_ref

implements template::util::quote_html on the designated column of a multirow

Parameters:
multirow_ref (required)
name of the multirow
column_ref (required)
name of the column to be
Author:
simon

Testcases:
No testcase defined.

template::util::multirow_to_list (public)

 template::util::multirow_to_list [ -level level ] name

generate a list structure representative of a multirow data source NB: if the multirow is generated by db_multirow, db_multirow must be called with the -local option

Switches:
-level (optional, defaults to "1")
Parameters:
name (required)
the name of an existing multirow data source
Returns:
a representation of a multirow data source as a list, suitable for passing by value in the form { { row } { row } { row } ... }
See Also:

Testcases:
lists_and_multirows

template::util::number_list (public)

 template::util::number_list last_number [ start_at ]

Return a list of numbers, {1 2 3 ... n}

Parameters:
last_number (required)
start_at (optional, defaults to "0")

Testcases:
number_list

template::util::nvl (public, deprecated)

 template::util::nvl value value_if_null
Deprecated. Invoking this procedure generates a warning.

Analogous to SQL NVL DEPRECATED: a plain Tcl oneliner can easily replace this proc

Parameters:
value (required)
value_if_null (required)
See Also:
  • expr {$value ne "" ? $value : $value_if_null}

Testcases:
No testcase defined.

template::util::read_file (public)

 template::util::read_file path

Reads a text file.

Parameters:
path (required)
The absolute path to the file
Returns:
A string with the contents of the file.

Testcases:
sync_file_get_document, read_write_file

template::util::resolve_directory_url (public)

 template::util::resolve_directory_url url

Resolve the filename for a directory URL

Parameters:
url (required)

Testcases:
No testcase defined.

template::util::set_file_encoding (public)

 template::util::set_file_encoding file_channel_id

Set encoding of the given file channel based on the OutputCharset parameter of AOLserver. All ADP, Tcl, and txt files are assumed to be in the same charset.

Parameters:
file_channel_id (required)
The id of the file to set encoding for.
Author:
Peter Marklund

Testcases:
read_write_file

template::util::url_to_file (public)

 template::util::url_to_file url [ reference_url ]

Resolve a URL into an absolute file path.

Parameters:
url (required)
reference_url (optional)

Testcases:
No testcase defined.

template::util::vars_to_array (public, deprecated)

 template::util::vars_to_array arrayname [ args... ]
Deprecated. Invoking this procedure generates a warning.

Place local variables into an array

Parameters:
arrayname (required)
The name of an array in the calling frame.
See Also:
  • array

Testcases:
No testcase defined.

template::util::write_file (public)

 template::util::write_file path text

Writes a text file

Parameters:
path (required)
The absolute path to the file
text (required)
A string containing the text to write to the file.

Testcases:
read_write_file
[ show source ]