Qore WebUtil Module Reference  1.6.1
WebUtil::TemplateFileManager Class Reference

this class manages templates based on files More...

Inheritance diagram for WebUtil::TemplateFileManager:

Public Member Methods

 constructor (int parse_opts=StaticTextTemplateBase::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< HttpResponseInfo > render (string tname, string path, date mtime, hash< auto > ctx, int code=200, *hash< auto > hdr)
 explicitly renders the given template with the given path and context argument More...
 

Private Member Methods

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< string, AbstractTemplate > 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

◆ constructor()

WebUtil::TemplateFileManager::constructor ( int  parse_opts = StaticTextTemplateBase::DefaultProgramOptions,
*code  pgm_setup 
)

creates the object with optional Program options

Parameters
parse_optsthe Program parse options for the template file programs
pgm_setupan 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

◆ render()

hash<HttpResponseInfo> WebUtil::TemplateFileManager::render ( string  tname,
string  path,
date  mtime,
hash< auto >  ctx,
int  code = 200,
*hash< auto >  hdr 
)

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

Example:
hash<auto> h = tm.render(resource_path, path, mtime, ctx);
Parameters
tnamethe template name, normally a relative path for a template file, however this could also be the absolute path
paththe path to the template file
mtimethe 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
ctxthe context argument for the template
codethe HTTP response code for the response, if not present then 200 "OK" is assumed
hdrany 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)