class TemplateLookup(TemplateCollection): (source)
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: .. sourcecode:: python lookup = TemplateLookup(["/path/to/templates"]) some_template = lookup.get_template("/index.html") The :class:`.TemplateLookup` can also be given :class:`.Template` objects programatically using :meth:`.put_string` or :meth:`.put_template`: .. sourcecode:: python lookup = TemplateLookup() lookup.put_string("base.html", ''' <html><body>${self.next()}</body></html> ''') lookup.put_string("hello.html", ''' <%include file='base.html'/> Hello, world ! ''') :param 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. :param 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 :class:`.Template` instances. Otherwise, a least-recently-used cache object is used which will maintain the size of the collection approximately to the number given. :param filesystem_checks: When at its default value of ``True``, each call to :meth:`.TemplateLookup.get_template()` will compare the filesystem last modified time to the time in which an existing :class:`.Template` object was created. This allows the :class:`.TemplateLookup` to regenerate a new :class:`.Template` whenever the original source has been updated. Set this to ``False`` for a very minor performance increase. :param 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. All other keyword parameters available for :class:`.Template` are mirrored here. When new :class:`.Template` objects are created, the keywords established with this :class:`.TemplateLookup` are passed on to each new :class:`.Template`.
Method | __init__ |
Undocumented |
Method | adjust |
Adjust the given ``uri`` based on the given relative URI. |
Method | filename |
Convert the given ``filename`` to a URI relative to this :class:`.TemplateCollection`. |
Method | get |
Return a :class:`.Template` object corresponding to the given ``uri``. |
Method | put |
Place a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given string of ``text``. |
Method | put |
Place a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given :class:`.Template` object. |
Instance Variable | collection |
Undocumented |
Instance Variable | directories |
Undocumented |
Instance Variable | filesystem |
Undocumented |
Instance Variable | module |
Undocumented |
Instance Variable | modulename |
Undocumented |
Instance Variable | template |
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 |
Undocumented |
Inherited from TemplateCollection
:
Method | has |
Return ``True`` if this :class:`.TemplateLookup` is capable of returning a :class:`.Template` object for the given ``uri``. |
Undocumented
Return a :class:`.Template` object corresponding to the given ``uri``. .. note:: The ``relativeto`` argument is not supported here at the moment.
Place a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given string of ``text``.
Place a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given :class:`.Template` object.