![]() |
Qore WebUtil Module Reference 1.6.2
|
A container for holding static text templates (ie that do not change once created in the template manager) with mixed text and Qore code. More...
Public Member Functions | |
string | add (string name, string src, *string ct) |
adds a template to the object | |
constructor (int po=DefaultProgramOptions) | |
sets up the object | |
*hash< string, bool > | getTemplateHash () |
returns a hash of template names, values are True or nothing if no templates are currently cached | |
list< string > | getTemplateList () |
returns a list of template names, an empty list is returned if there are no templates | |
bool | hasTemplate (string tname) |
returns True if the given template exists, False if not | |
hash< HttpResponseInfo > | render (string tname, hash< auto > ctx, int code=200, *hash< auto > hdr) |
explicitly renders the given template with the given argument | |
setupProgram (Program p) | |
override in subclasses to customize the setup of template Programs; this method performs no action | |
*hash< HttpResponseInfo > | tryRender (string tname, hash< auto > ctx, int code=200, *hash< auto > hdr) |
explicitly renders the given template with the given argument context hash if the template exists; if not, returns nothing | |
Protected Member Functions | |
Sequence | seq () |
Sequence for template function names. | |
Protected Attributes | |
int | po |
parse options for template containers | |
hash< string, hash< auto > > | th |
Maps template names to function names. | |
hash< string, TextTemplateBase > | toh |
Maps template names to TextTemplateBase objects. | |
Additional Inherited Members | |
![]() | |
static string | add (Qore::Program p, string fn, string name, string src) |
adds a template function to a template Program object | |
static string | getContentType (string name) |
returns the content type from the file name, ignores any leading "q" in the extensions, assuming a template | |
![]() | |
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 | |
![]() | |
static bool | doBlock (string end, reference< string > src, string type, reference< int > i, reference< list< hash > > l) |
a helper method used in parsing | |
static string | getCode (bool bare_refs, string fmt,...) |
a helper method that strips dollar signs from code when PO_ALLOW_BARE_REFS is set in the template program | |
A container for holding static text templates (ie that do not change once created in the template manager) with mixed text and Qore code.
To give the template programs a specific imported API, subclass this object and use the following methods to import an API into the template Program object in your subclass's constructor:
string WebUtil::StaticTemplateManager::add | ( | string | name, |
string | src, | ||
*string | ct ) |
adds a template to the object
name | the name of the template |
src | the source of the template; Qore source code is delimited as follows:
|
ct | the Content-Type of the rendered output; if not given then the content-type is derived from the extension in the name if possible; if the content-type cannot be derived from the extension, then content-type "text/plain" is assumed |
The ctx hash variable is always present in the template code; this is the call context variable, and is set to the same value as the cx argument in HttpServer::AbstractHttpRequestHandler::handleRequest() plus any context added by the actual handler handing the request. In the example above, a "workflows"
key assigned to a hash has been added to the call context variable.
hash< HttpResponseInfo > WebUtil::StaticTemplateManager::render | ( | string | tname, |
hash< auto > | ctx, | ||
int | code = 200, | ||
*hash< auto > | hdr ) |
explicitly renders the given template with the given argument
tname | the template name |
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) |
code:
the HTTP response code corresponding to the code argumentbody:
the rendered templatehdr:
a hash of headers corresponding to the hdr argument plus the "Content-Type"
key set from the template's "Content-Type" value)TEMPLATE-ERROR | the given template does not exist |
*hash< HttpResponseInfo > WebUtil::StaticTemplateManager::tryRender | ( | string | tname, |
hash< auto > | ctx, | ||
int | code = 200, | ||
*hash< auto > | hdr ) |
explicitly renders the given template with the given argument context hash if the template exists; if not, returns nothing
tname | the template name |
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) |
code:
the HTTP response code corresponding to the code argumentbody:
the rendered templatehdr:
a hash of headers corresponding to the hdr argument plus the "Content-Type"
key set from the template's "Content-Type" value)