How to use the ttp.ttp._template_class function in ttp

To help you get started, we’ve selected a few ttp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmulyalin / ttp / ttp / ttp.py View on Github external
def parse_template(element, template_index):
            # skip child templates that are not in requested children list
            if self.filter:
                if not element.attrib.get("name", None) in self.filter:
                    return
            self.templates.append(
                _template_class(
                    template_text=ET.tostring(element, encoding="UTF-8"),
                    base_path=self.base_path,
                    ttp_vars=self.ttp_vars,
                    name=str(template_index),
                )
github dmulyalin / ttp / ttp / ttp.py View on Github external
**Parameters**
        
        * ``template`` file object or OS path to text file with template
        * ``template_name`` (str) name of the template
        * ``filter`` (list) list of templates' names to load,
        
        ``filter`` attribute allow to filter the list of template names that 
        should be loaded. Checks done against child templates as well. For 
        templates specified in filter list, groups/macro/inputs/etc. will not 
        be loaded and no results produced.
        """
        log.debug("ttp.add_template - loading template '{}'".format(template_name))
        # get a list of [(type, text,)] tuples or empty list []
        items = _ttp_["utils"]["load_files"](path=template, read=True)
        for i in items:
            template_obj = _template_class(
                template_text=i[1],
                base_path=self.base_path,
                ttp_vars=self.vars,
                name=template_name,
                filter=filter,
            )
            # if not template_obj.templates - no 'template' tags in template
            self._templates += (
                template_obj.templates if template_obj.templates else [template_obj]
            )