ramka.templates package#
Submodules#
ramka.templates.engine module#
- class ramka.templates.engine.BaseTemplateEngine(root_dir: Optional[str] = None, template_dir_name: Optional[str] = 'templates')#
Bases:
ABC
The base template engine class.
The template engine is responsible for loading templates and rendering them.
This class can be subclassed to implement a custom template engine.
- abstract has_template(template_name: str) bool #
Check if the template engine has a template with the given name.
- Parameters:
template_name (str) – The name of the template to check.
- Returns:
- True if the template engine has a template with the given name,
False otherwise.
- Return type:
bool
- abstract render(template_name: str, context: Optional[Dict] = None) Any #
Render a template.
Information provided in the context dictionary will be available in the template.
- Parameters:
template_name (str) – The name of the template to render.
context (Optional[Dict]) – The context to use when rendering the template.
- Returns:
The rendered template.
- Return type:
Any
- class ramka.templates.engine.JinjaTemplateEngine(root_dir: Optional[str] = None, template_dir_name: Optional[str] = 'templates')#
Bases:
BaseTemplateEngine
The Jinja template engine class.
The template engine is responsible for loading templates and rendering them. This engine uses Jinja2 library to load, parse, and render templates.
- has_template(template_name: str) bool #
Check if the template engine has a template with the given name.
- Parameters:
template_name (str) – The name of the template to check.
- Returns:
- True if the template engine has a template with the given name,
False otherwise.
- Return type:
bool
- render(template_name: str, context: Optional[Dict] = None) Template #
Render a template.
Information provided in the context dictionary will be available in the template.
- Parameters:
template_name (str) – The name of the template to render.
context (Optional[Dict]) – The context to use when rendering the template.
- Returns:
The rendered template.
- Return type:
Template
Module contents#
- class ramka.templates.BaseTemplateEngine(root_dir: Optional[str] = None, template_dir_name: Optional[str] = 'templates')#
Bases:
ABC
The base template engine class.
The template engine is responsible for loading templates and rendering them.
This class can be subclassed to implement a custom template engine.
- abstract has_template(template_name: str) bool #
Check if the template engine has a template with the given name.
- Parameters:
template_name (str) – The name of the template to check.
- Returns:
- True if the template engine has a template with the given name,
False otherwise.
- Return type:
bool
- abstract render(template_name: str, context: Optional[Dict] = None) Any #
Render a template.
Information provided in the context dictionary will be available in the template.
- Parameters:
template_name (str) – The name of the template to render.
context (Optional[Dict]) – The context to use when rendering the template.
- Returns:
The rendered template.
- Return type:
Any
- class ramka.templates.JinjaTemplateEngine(root_dir: Optional[str] = None, template_dir_name: Optional[str] = 'templates')#
Bases:
BaseTemplateEngine
The Jinja template engine class.
The template engine is responsible for loading templates and rendering them. This engine uses Jinja2 library to load, parse, and render templates.
- has_template(template_name: str) bool #
Check if the template engine has a template with the given name.
- Parameters:
template_name (str) – The name of the template to check.
- Returns:
- True if the template engine has a template with the given name,
False otherwise.
- Return type:
bool
- render(template_name: str, context: Optional[Dict] = None) Template #
Render a template.
Information provided in the context dictionary will be available in the template.
- Parameters:
template_name (str) – The name of the template to render.
context (Optional[Dict]) – The context to use when rendering the template.
- Returns:
The rendered template.
- Return type:
Template