def __init__(self, project, error_context=None):
        """Constructor.

        Args:
            project: The project to which this template engine relates.
        """
        self.project = project
        self.error_context = error_context or StatikErrorContext()
        self.supported_providers = project.config.template_providers
        if project.safe_mode:
            self.supported_providers = [provider for provider in self.supported_providers \
                                        if provider in SAFER_TEMPLATE_PROVIDERS]

        if len(self.supported_providers) == 0:
            raise NoSupportedTemplateProvidersError(
                SAFER_TEMPLATE_PROVIDERS if project.safe_mode else DEFAULT_TEMPLATE_PROVIDERS,
                project.safe_mode
            )

        self.provider_classes = dict()
        self.providers_by_ext = dict()
        self.exts = []
        for provider in self.supported_providers:
            self.provider_classes[provider] = get_template_provider_class(provider)
            # track which provider to use for which file extension
            for ext in TEMPLATE_PROVIDER_EXTS[provider]:
                if ext not in self.providers_by_ext:
                    self.providers_by_ext[ext] = provider
                    self.exts.append(ext)

        self.providers = dict()
        self.cached_templates = dict()

        # build up our expected template paths
        # we allow the templates/ folder to take highest precedence
        self.template_paths = [os.path.join(project.path, project.TEMPLATES_DIR)]
        # if this project has a theme associated with it
        if project.config.theme is not None:
            self.template_paths.append(os.path.join(
                project.path,
                project.THEMES_DIR,
                project.config.theme,
                project.TEMPLATES_DIR
            ))

        logger.debug(
            "Looking in the following path(s) (in the following order) for templates:\n%s",
            "\n".join(self.template_paths)
        )

        # now make sure that all of the relevant template paths actually exist
        for path in self.template_paths:
            if not os.path.exists(path) or not os.path.isdir(path):
                raise MissingProjectFolderError(path)

        logger.debug(
            "Configured the following template providers: %s",
            ", ".join(self.supported_providers)
        )
def __init__ ( self , project , error_context = None ) : self . project = project self . error_context = error_context or StatikErrorContext ( ) self . supported_providers = project . config . template_providers if project . safe_mode : self . supported_providers = [ provider for provider in self . supported_providers if provider in SAFER_TEMPLATE_PROVIDERS ] if len ( self . supported_providers ) == 0 : raise NoSupportedTemplateProvidersError ( SAFER_TEMPLATE_PROVIDERS if project . safe_mode else DEFAULT_TEMPLATE_PROVIDERS , project . safe_mode ) self . provider_classes = dict ( ) self . providers_by_ext = dict ( ) self . exts = [ ] for provider in self . supported_providers : self . provider_classes [ provider ] = get_template_provider_class ( provider ) for ext in TEMPLATE_PROVIDER_EXTS [ provider ] : if ext not in self . providers_by_ext : self . providers_by_ext [ ext ] = provider self . exts . append ( ext ) self . providers = dict ( ) self . cached_templates = dict ( ) self . template_paths = [ os . path . join ( project . path , project . TEMPLATES_DIR ) ] if project . config . theme is not None : self . template_paths . append ( os . path . join ( project . path , project . THEMES_DIR , project . config . theme , project . TEMPLATES_DIR ) ) logger . debug ( "Looking in the following path(s) (in the following order) for templates:\n%s" , "\n" . join ( self . template_paths ) ) for path in self . template_paths : if not os . path . exists ( path ) or not os . path . isdir ( path ) : raise MissingProjectFolderError ( path ) logger . debug ( "Configured the following template providers: %s" , ", " . join ( self . supported_providers ) )
Constructor.

        Args:
            project: The project to which this template engine relates.