Skip to content

LoaderMixin

Sub classes

Name Children Inherits
PrefixLoader
jinjarope.loaders
A loader for prefixing other loaders.
    ModuleLoader
    jinjarope.loaders
    This loader loads templates from precompiled templates.
      FunctionLoader
      jinjarope.loaders
      A loader for loading templates from a function.
        PackageLoader
        jinjarope.loaders
        A loader for loading templates from a package.
          FileSystemLoader
          jinjarope.loaders
          A loader to load templates from the file system.
            ChoiceLoader
            jinjarope.loaders
            A loader which combines multiple other loaders.
              DictLoader
              jinjarope.loaders
              A loader to load static content from a path->template-str mapping.
                RewriteLoader
                jinjarope.rewriteloader
                A loader which modifies templates based on a callable.
                  NestedDictLoader
                  jinjarope.configloaders
                  A jinja loader for loading templates from nested dicts.
                  FsSpecProtocolPathLoader
                  jinjarope.fsspecloaders
                  A jinja loader for fsspec filesystems.
                    FsSpecFileSystemLoader
                    jinjarope.fsspecloaders
                    A jinja loader for fsspec filesystems.

                      🛈 DocStrings

                      Loader mixin which allows to OR loaders into a choice loader.

                      Source code in src/jinjarope/loaders.py
                      17
                      18
                      19
                      20
                      21
                      22
                      23
                      24
                      25
                      26
                      27
                      28
                      29
                      30
                      31
                      32
                      33
                      34
                      35
                      36
                      37
                      38
                      39
                      40
                      41
                      42
                      43
                      44
                      45
                      46
                      47
                      48
                      49
                      50
                      51
                      52
                      class LoaderMixin:
                          """Loader mixin which allows to OR loaders into a choice loader."""
                      
                          ID: str
                          loader: jinja2.BaseLoader
                          list_templates: Callable
                          get_source: Callable
                          load: Callable
                      
                          def __or__(self, other: jinja2.BaseLoader) -> ChoiceLoader:
                              own = self.loaders if isinstance(self, jinja2.ChoiceLoader) else [self]  # type: ignore[list-item]
                              others = other.loaders if isinstance(other, jinja2.ChoiceLoader) else [other]
                              return ChoiceLoader([*own, *others])
                      
                          def __getitem__(self, val: str) -> jinja2.Template:
                              """Return the template object for given template path."""
                              return self.load(None, val)
                      
                          def __contains__(self, path: str):
                              """Check whether given path is loadable by this loader."""
                              return upath.UPath(path).as_posix() in self.list_templates()
                      
                          def __rtruediv__(self, path: str):
                              return self.prefixed_with(path)
                      
                          def prefixed_with(self, prefix: str):
                              """Return loader wrapped in a PrefixLoader instance with given prefix.
                      
                              Args:
                                  prefix: The prefix to use
                              """
                              return PrefixLoader({prefix: self})  # type: ignore[dict-item]
                      
                          def get_template_source(self, template_path: str):
                              """Return the source for given template path."""
                              return self.get_source(None, template_path)[0]
                      

                      __contains__

                      __contains__(path: str)
                      

                      Check whether given path is loadable by this loader.

                      Source code in src/jinjarope/loaders.py
                      35
                      36
                      37
                      def __contains__(self, path: str):
                          """Check whether given path is loadable by this loader."""
                          return upath.UPath(path).as_posix() in self.list_templates()
                      

                      __getitem__

                      __getitem__(val: str) -> Template
                      

                      Return the template object for given template path.

                      Source code in src/jinjarope/loaders.py
                      31
                      32
                      33
                      def __getitem__(self, val: str) -> jinja2.Template:
                          """Return the template object for given template path."""
                          return self.load(None, val)
                      

                      get_template_source

                      get_template_source(template_path: str)
                      

                      Return the source for given template path.

                      Source code in src/jinjarope/loaders.py
                      50
                      51
                      52
                      def get_template_source(self, template_path: str):
                          """Return the source for given template path."""
                          return self.get_source(None, template_path)[0]
                      

                      prefixed_with

                      prefixed_with(prefix: str)
                      

                      Return loader wrapped in a PrefixLoader instance with given prefix.

                      Parameters:

                      Name Type Description Default
                      prefix str

                      The prefix to use

                      required
                      Source code in src/jinjarope/loaders.py
                      42
                      43
                      44
                      45
                      46
                      47
                      48
                      def prefixed_with(self, prefix: str):
                          """Return loader wrapped in a PrefixLoader instance with given prefix.
                      
                          Args:
                              prefix: The prefix to use
                          """
                          return PrefixLoader({prefix: self})  # type: ignore[dict-item]
                      

                      Show source on GitHub