class TemplateLookup(TemplateCollection):
Represent a collection of templates that locates template source files from the local filesystem.
The primary argument is the directories argument, the list of directories to search:
lookup = TemplateLookup(["/path/to/templates"]) some_template = lookup.get_template("/index.html")
The .TemplateLookup
can also be given .Template
objects
programatically using .put_string
or .put_template
:
lookup = TemplateLookup() lookup.put_string("base.html", ''' <html><body>${self.next()}</body></html> ''') lookup.put_string("hello.html", ''' <%include file='base.html'/> Hello, world ! ''')
All other keyword parameters available for
.Template
are mirrored here. When new
.Template
objects are created, the keywords
established with this .TemplateLookup
are passed on
to each new .Template
.
Parameters | |
directories | A list of directory names which will be searched for a particular template URI. The URI is appended to each directory and the filesystem checked. |
collection_size | Approximate size of the collection used
to store templates. If left at its default of -1, the size
is unbounded, and a plain Python dictionary is used to
relate URI strings to .Template instances.
Otherwise, a least-recently-used cache object is used which
will maintain the size of the collection approximately to
the number given. |
filesystem_checks | When at its default value of True,
each call to .TemplateLookup.get_template() will
compare the filesystem last modified time to the time in
which an existing .Template object was created.
This allows the .TemplateLookup to regenerate a
new .Template whenever the original source has
been updated. Set this to False for a very minor
performance increase. |
modulename_callable | A callable which, when present, is passed the path of the source file as well as the requested URI, and then returns the full path of the generated Python module file. This is used to inject alternate schemes for Python module location. If left at its default of None, the built in system of generation based on module_directory plus uri is used. |
Method | adjust_uri |
Adjust the given uri based on the given relative URI. |
Method | filename_to_uri |
Convert the given filename to a URI relative to this .TemplateCollection . |
Method | get_template |
Return a .Template object corresponding to the given uri. |
Method | put_string |
Place a new .Template object into this .TemplateLookup , based on the given string of text. |
Method | put_template |
Place a new .Template object into this .TemplateLookup , based on the given .Template object. |
Method | __init__ |
Undocumented |
Method | _check |
Undocumented |
Method | _load |
Undocumented |
Method | _relativeize |
Return the portion of a filename that is 'relative' to the directories in this lookup. |
Instance Variable | _collection |
Undocumented |
Instance Variable | _mutex |
Undocumented |
Instance Variable | _uri_cache |
Undocumented |
Instance Variable | collection_size |
Undocumented |
Instance Variable | directories |
Undocumented |
Instance Variable | filesystem_checks |
Undocumented |
Instance Variable | module_directory |
Undocumented |
Instance Variable | modulename_callable |
Undocumented |
Instance Variable | template_args |
Undocumented |
Inherited from TemplateCollection
:
Method | has_template |
Return True if this .TemplateLookup is capable of returning a .Template object for the given uri. |
.TemplateCollection
.Return a .Template
object corresponding to the given
uri.
Note
The relativeto argument is not supported here at the moment.
.Template
object into this
.TemplateLookup
, based on the given string of
text..Template
object into this
.TemplateLookup
, based on the given
.Template
object.Undocumented