cement.core.template
Cement core template module.
- class cement.core.template.TemplateHandler(*args: Any, **kwargs: Any)[source]
Bases:
TemplateInterface,HandlerBase class that all template implementations should sub-class from. Keyword arguments passed to this class will override meta-data options.
- copy(src: str, dest: str, data: Dict[str, Any], force: bool = False, exclude: List[str] | None = None, ignore: List[str] | None = None) bool[source]
Render
srcdirectory as template, including directory and file names, and copy todestdirectory.- Parameters:
src (str) – The source directory path.
dest (str) – The destination directory path.
data (dict) – The data dictionary to interpolate in the template.
force (bool) – Whether to overwrite existing files.
exclude (list) – List of regular expressions to match files that should only be copied, and not rendered as template.
ignore (list) – List of regular expressions to match files that should be completely ignored and not copied at all.
- Returns:
Returns
Trueif the copy completed successfully.- Return type:
- Raises:
AssertionError – If the
srctemplate directory path does not exists, and when adestfile already exists andforce is not True.
- load(template_path: str) Tuple[str | bytes, str, str | None][source]
Loads a template file first from
self.app._meta.template_dirsand secondly fromself.app._meta.template_module. Thetemplate_dirshave presedence.- Parameters:
template_path (str) – The secondary path of the template after either
template_moduleortemplate_dirsprefix (set viaApp.Meta)- Returns:
The content of the template (
str), the type of template (str:directory, ormodule), and the path (str) of the directory or module)- Return type:
- Raises:
cement.core.exc.FrameworkError – If the template does not exist in either the
template_moduleortemplate_dirs.
- class cement.core.template.TemplateInterface(**kw: Any)[source]
Bases:
InterfaceThis class defines the Template Interface. Handlers that implement this interface must provide the methods and attributes defined below. In general, most implementations should sub-class from the provided
TemplateHandlerbase class as a starting point.- abstractmethod copy(src: str, dest: str, data: Dict[str, Any]) bool[source]
Render the
srcdirectory path, and copy todest. This method must render directory and file names as template content, as well as the contents of files.
- abstractmethod load(path: str) Tuple[str | bytes, str, str | None][source]
Loads a template file first from
self.app._meta.template_dirsand secondly fromself.app._meta.template_module. Thetemplate_dirshave presedence.- Parameters:
path (str) – The secondary path of the template after either
template_moduleortemplate_dirsprefix (set viaApp.Meta)- Returns:
The content of the template (
str), the type of template (str:directory, ormodule), and the path (str) of the directory or module)- Return type:
- Raises:
cement.core.exc.FrameworkError – If the template does not exist in either the
template_moduleortemplate_dirs.