Template module

This module is the template expansion engine shared by the various scripts to display their results in a customisable HTML page.

gettemplate ($who, $surrogate)

Function gettemplate returns the contents of the designated template. In case the template name has not been defined in lxr.conf or if the target file does not exist, a replacement template is returned.

  1. $who

    a string containing the template name

  2. $surrogate

    a string containing the replacement template

Caveat:

expandtemplate ($templ, %expfunc)

Function expandtemplate returns a string where occurrences of simple template variables and template function parameter blocks are replaced by their expanded values.

  1. $templ

    a string containing the template

  2. %expfunc

    a hash where the key is the variable/function name and the value is a sub returning the expanded text

The template may contain substitution requests which are special sequences of characters in the form:

The content of a function argument is arbitrary. It may even contain substitution requests as variables or nested functions. The only restriction concerns the closing brace }: it cannot appear inside an argument because it would match the nearest unmatched opening brace {. No escape mechanism is presently implemented. Note, however, that if you are generating HTML you can use entity literals & #125; or & #x7D; (without spaces between & and the number sign #).

Notes:

Algorithm

$templ is repeatedly explored to replace matching { } (not containing other { }) which are preceded by a single { by characters \x01 and \x02 respectively.

It proceeds thus from the innermost block to the outermost, leaving only unnested variables, unnested function calls and stray unnested braces.

Then, the %expfunc subs are called based on the name of the variables or functions. Variable subs receive an undef argument, while function subs receive the block argument with its braces restored (or undef if it is empty). If the variable or function has no corresponding key in %expfunc, the variable or function call (including its argument) is left unchanged.

Finally, the leftover \x01 and \x02 are converted back into { and }.

Note:

Extra feature

HTML comments are removed from the template. However, SSI comments (coded as HTML comments) must not be removed lest the template would lose its functionality. Consequently, comments have two forms:

Note that the licence statement in the standard template is written as verbose comment. The licence is removed when the template is expanded because the generated page consists mostly of your private data (either replaced text or displayed source lines) which certainly are under a different licence than that of LXR.

targetexpand ($templ, $who)

Function targetexpand is a "$variable" substitution function. It returns a string representative of the displayed tree. The "name" of the tree is extracted from the URL (script-name component) according to the routing technique.

  1. $templ

    a string containing the template

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution

Note:

captionexpand ($templ, $who)

Function captionexpand is a "$variable" substitution function. It returns an HTML-safe string that can be used in a header as a caption for the page.

  1. $templ

    a string containing the template

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution

bannerexpand ($templ, $who)

Function bannerexpand is a "$variable" substitution function. It returns an HTML string displaying the path to the current file ($pathname) with < A > links in every portion of the path to allow quick access to the intermediate directories.

  1. $templ

    a string containing the template

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution

titleexpand ($templ, $who)

Function titleexpand is a "$variable" substitution function. It returns an HTML-safe string suitable for use in a < TITLE > element.

  1. $templ

    a string containing the template

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution

stylesheet ($templ)

Function thisurl is a "$variable" substitution function. It returns an HTML-encoded string suitable for use as the target href of a < LINK rel="stylesheet" > tag.

  1. $templ

    a string containing the template (i.e. argument)

The string comes from configuration parameter 'stylesheet'.

altstyleexpand ($templ, $who)

Function altstyleexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all the alternate stylesheet definitions found in the configuration file.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution; it is here considered as the "mode"

Algorithm

It retrieves the configuration array 'alternate_stylesheet' if it exists.

The argument template is then expanded through expandtemplate for each URL argument with a replacement rule for its name and value.

thisurl ()

Function thisurl is a "$variable" substitution function. It returns an HTML-encoded string suitable for use as the target href of an < A > tag.

The string is the URL used to access the current page (complete with the ?query string).

baseurl ()

Function baseurl is a "$variable" substitution function. It returns an HTML-encoded string suitable for use as the target href of a < A > or < BASE > tag.

The string is the base URL used to access the LXR server.

dotdoturl ()

Function dotdoturl is a "$variable" substitution function. It returns an HTML-encoded string suitable for use as the target href of an < A > or < BASE > tag.

The string is the ancestor of the base URL used to access the LXR server.

Caveat:

forestexpand ($templ, $who)

Function forestexpand is a "$function" substitution function. It returns an HTML string which contains links to the shareable trees of the configuration file.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution

Algorithm

It reads the configuration file into an array.

The elements, except the first (index 0), are scanned to see if parameter 'shortcaption' is defined, which means this tree is shareable.

If none is found, the template is not expanded. The returned string is void, thus avoiding any stray legend in the page.

Otherwise, the argument template is then expanded through expandtemplate with a replacement rule for the 'treelinks' attribute.

treesexpand ($templ, $who, $var)

Function treesexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all the shareable trees of the configuration file.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name

  3. $confgroups

    a array containing a copy of the configuration file

Algorithm

It uses the copy of the configuration file passed as an array argument.

The elements, except the first (index 0), are scanned to see if parameter 'shortcaption' is defined, which means this tree is shareable.

Depending on the result of Config.pm's treeurl, a mere highlighting of the name or a full link is generated.

The argument template is then expanded through expandtemplate with a replacement rule for each attribute.

The result is the concatenation of the repeated expansion.

urlexpand ($templ, $who)

Function urlexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all the URL arguments of the current page.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution; it is here considered as the "mode"

Algorithm

It makes use of sub urlargs to retrieve the filtered list of variables values. If necessary, other URL arguments may be added depending on the mode (known from $who).

The argument template is then expanded through expandtemplate for each URL argument with a replacement rule for its name and value.

modeexpand ($templ, $who)

Function modeexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all the LXR modes.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name (i.e. source, sourcedir, diff, ident or search) requesting this substitution; it is here considered as the "mode"

Algorithm

It first constructs a list (Perl @vector) of hashes describing the state of the mode: its name, selection state, link or action, CSS class.

The argument template is then expanded through expandtemplate for each mode with a replacement rule for each attribute.

The result is the concatenation of the repeated expansion.

Function varlinks is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all the values of $var.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name

  3. $var

    a string containing the name of a configuration variable (defined in the 'variables' configuration parameter)

Algorithm

It first constructs a list (Perl @vector) made of HTML fragments describing the values of the variable (with an indication of the current value).

The argument template is then expanded through expandtemplate for each value with a replacement rule allowing the inclusion of the HTML fragment.

The result is the concatenation of the repeated expansion.

varmenuexpand ($var)

Function varmenuexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of < OPTION > tags, each one corresponding to the values defined in variable $var's 'range'.

  1. $templ

    a string containing the template (i.e. argument)

  2. $var

    a string containing the variable name

To handle CVS case where directories are not managed version-wise, the value any variable has on entry is kept, even if this value is not listed in its 'range' attribute. Thus, the current version, for instance, is not lost through a directory display.

varbtnaction ($templ, $who)

Function varbtnaction is a "$variable" substitution function. It returns a string suitable for use in the action attribute of a < FORM > tag.

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name

varexpand ($templ, $who)

Function varexpand is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to all configuration variables (those defined in the 'variables' configuration parameter).

  1. $templ

    a string containing the template (i.e. argument)

  2. $who

    a string containing the script name

Algorithm

All variables are considered one after the other and template expansion is requested through expandtemplate with adequate replacement rules for the properties.

Some variables may be "conditional". They then have a 'when' attribute which value is a boolean expression. If the expression evaluates true, the block will be expanded for this variable; otherwise, the variable is skipped.

The expression is most useful to display variables only when others have a given value.

The result is the concatenation of the repeated expansion.

displayindexstate ($who)

Function displayindexstate is a "$variable" substitution function. It returns a HTML

element containing the indexing state of the current version.

  1. $who

    a string containing the caller script name

Algorithm

The times table record pertaining to the current version of the tree is read in and the various genxref's milestone dates are scanned to deduce the state.

devinfo ($templ)

Function devinfo is a "$variable" substitution function. It returns a string giving information about the LXR modules.

This is a developer debugging substitution. It is not meaningful for the average user.

  1. $templ

    a string containing the template

Function atticlink is a "$variable" substitution function. It returns an HTML-string containing an < A > link to display/hide CVS files in the "attic" directory.

  1. $templ

    a string containing the template

  2. $who

    a string containing the script name

makeheader ($who), $tmplpfx

Function makeheader outputs the HTML sequence for the top part of the page (a header) so that all pages have a similar appearance. It uses a template whose name is derived from the scriptname.

  1. $who

    a string containing the script name

  2. $tmplpfx

    an optional string containing the template prefix (by default, equal to script name)

In case the template is not found, an internal elementary template is generated to display something. An error is also logged for the administrator.

makefooter ($who)

Function makefooter outputs the HTML sequence for the bottom part of the page (a footer) so that all pages have a similar appearance. It uses a template whose name is derived from the scriptname.

  1. $who

    a string containing the script name

In case the template is not found, an internal elementary template is generated to display something. An error is also logged for the administrator.

makeerrorpage ($who)

Function makeerrorpage outputs an HTML error page when an incorrect URL has been submitted: no corresponding source-tree could be found in the configuration. It is primarily aimed at giving feedback to the user.

  1. $who

    a string containing the template name

In case the template is not found, an internal elementary template is generated to display something.

No assumption is made about the existence of other templates, e.g. header or footer, since they can be defined merely in the tree section without being defined in the global section. Consequently, there is no call to makeheader() or makefooter().

HTTP headers may or may not have been already emitted. Caller is responsible for checking that and eventually emit minimal HTTP headers for error page display.