Qore WebUtil Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
WebUtil::FileTemplate Class Reference

manages a template resource that may need to be recompiled if the file is updated in the filesystem; used by WebUtil::TemplateFileManager More...

Inheritance diagram for WebUtil::FileTemplate:

Public Member Functions

 constructor (string path, int po=DefaultProgramOptions, *code psetup)
 creates the object based on the pathname and Program options More...
 
hash render (date mtime, hash ctx, int code=200, *hash hdr)
 explicitly renders the given template with the given argument More...
 
- Public Member Functions inherited from WebUtil::TextTemplateBase
 constructor (int po=DefaultProgramOptions)
 sets up the object
 

Private Member Functions

RWLock rwl ()
 to ensure atomicity regarding contention between setup/recompiles and rendering requests
 

Private Attributes

string ct
 the content type of the rendered template
 
*date mtime
 file's modification time
 
string path
 the path to the template
 
int po
 parse options used on the program
 
*code psetup
 code to perform Program initialization when creating a new Program object (inport API, etc)
 
const TemplateFunc = "t"
 the name of the template function
 

Additional Inherited Members

- Static Public Member Functions inherited from WebUtil::TextTemplateBase
static string add (Program p, string fn, string name, string src)
 adds a template function to a template Program object More...
 
static string getContentType (string name)
 returns the content type from the file name, ignores any leading "q" in the extensions, assuming a template
 
- Public Attributes inherited from WebUtil::TextTemplateBase
const DefaultProgramOptions = PO_REQUIRE_OUR|PO_NO_TOP_LEVEL_STATEMENTS|PO_NO_INHERIT_USER_FUNC_VARIANTS|PO_NO_INHERIT_GLOBAL_VARS|PO_NO_USER_CLASSES|PO_NO_TERMINAL_IO
 default parse options for template Programs
 

Detailed Description

manages a template resource that may need to be recompiled if the file is updated in the filesystem; used by WebUtil::TemplateFileManager

Member Function Documentation

WebUtil::FileTemplate::constructor ( string  path,
int  po = DefaultProgramOptions,
*code  psetup 
)

creates the object based on the pathname and Program options

Parameters
paththe path to the resource
pothe Program parse options for the template file programs
psetupan 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::FileTemplate::render ( date  mtime,
hash  ctx,
int  code = 200,
*hash  hdr 
)

explicitly renders the given template with the given argument

Example:
my hash $h = $qft.render($ctx);
Parameters
mtimethe modified date/time of the file, used to determine if the template should be recomiled or not
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 template's "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)