All Classes Namespaces Functions Variables Groups Pages
WebUtil::TemplateFileManager Class Reference

this class manages templates based on files More...

Inheritance diagram for WebUtil::TemplateFileManager:
[legend]

## Public Member Functions

| constructor (int parse_opts=TextTemplateBase::DefaultProgramOptions, *code pgm_setup)
| creates the object with optional Program options More...
| purge (string tname)
| this method can be called when a resource is requested that no longer exists in case a template is stored for a file that was deleted
hash | render (string tname, string path, date mtime, hash ctx, int code=200, *hash hdr)
| explicitly renders the given template with the given path and context argument More...

## Private Member Functions

RWLock | rwl ()
| read-write lock for managing template access

## Private Attributes

int | po
| parse options used on the program
*code | psetup
| code to perform Program initialization when creating a new Program object (inport API, etc)
hash | th
| hash for template storage

## Detailed Description

this class manages templates based on files

Appropriate locking is used so that requests to existing templates based on files that have been updated on the filesystem are recompiled on demand and any requests that come in contemporaneously will block until the template is recompiled from the updated source on the filesystem

## Member Function Documentation

WebUtil::TemplateFileManager::constructor | ( | int | parse_opts = `TextTemplateBase::DefaultProgramOptions`,
|  | *code | pgm_setup
| ) |  |

creates the object with optional Program options

Parameters

  parse_opts | the Program parse options for the template file programs
  pgm_setup | an optional closure or call reference taking a single Program argument to be called when initializing template programs to set up a custom template API, etc

hash WebUtil::TemplateFileManager::render | ( | string | tname,
|  | string | path,
|  | date | mtime,
|  | hash | ctx,
|  | int | code = `200`,
|  | *hash | hdr
| ) |  |

explicitly renders the given template with the given path and context argument

Example:
  hash h = tm.render(resource_path, path, mtime, ctx);

Parameters

  tname | the template name, normally a relative path for a template file, however this could also be the absolute path
  path | the path to the template file
  mtime | the last modified date/time for the file, if this date is after any stored last modified date/time for the template, then the template is recompiled from source
  ctx | the context argument for the template
  code | the HTTP response code for the response, if not present then 200 `"OK"` is assumed
  hdr | any optional headers for the response (the `"Content-Type"` header is set from the templates `"Content-Type"` value automatically)

Returns
  a hash with the following keys:
  - `code:` the HTTP response code corresponding to the code argument
  - `body:` the rendered template
  - `hdr:` a hash of headers corresponding to the hdr argument plus the `"Content-Type"` key set from the template's "Content-Type" value)