Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.templateloader.TemplateLoader Class Reference
Inheritance diagram for scripts.templateloader.TemplateLoader:

Public Member Functions

def __init__ (self, root, subpaths, conditions={})
 
def TryLoad (self, name, more_conditions={})
 
def Load (self, name, more_conditions={})
 

Detailed Description

Loads template files from a path.

Definition at line 20 of file templateloader.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.templateloader.TemplateLoader.__init__ (   self,
  root,
  subpaths,
  conditions = {} 
)
Initializes loader.

Args:
root - a string, the directory under which the templates are stored.
subpaths - a list of strings, subpaths of root in search order.
conditions - a dictionary from strings to booleans.  Any conditional
expression must be a key in the map.

Definition at line 23 of file templateloader.py.

23 def __init__(self, root, subpaths, conditions={}):
24 """Initializes loader.
25
26 Args:
27 root - a string, the directory under which the templates are stored.
28 subpaths - a list of strings, subpaths of root in search order.
29 conditions - a dictionary from strings to booleans. Any conditional
30 expression must be a key in the map.
31 """
32 self._root = root
33 self._subpaths = subpaths
34 self._conditions = conditions
35 self._cache = {}
36

Member Function Documentation

◆ Load()

def scripts.templateloader.TemplateLoader.Load (   self,
  name,
  more_conditions = {} 
)
Returns contents of template file as a string, or raises an exception.

Definition at line 54 of file templateloader.py.

54 def Load(self, name, more_conditions={}):
55 """Returns contents of template file as a string, or raises an exception."""
56 template = self.TryLoad(name, more_conditions)
57 if template is not None: # Can be empty string
58 return template
59 raise Exception("Could not find template '%s' on %s / %s" %
60 (name, self._root, self._subpaths))
61

◆ TryLoad()

def scripts.templateloader.TemplateLoader.TryLoad (   self,
  name,
  more_conditions = {} 
)
Returns content of template file as a string, or None of not found.

Definition at line 37 of file templateloader.py.

37 def TryLoad(self, name, more_conditions={}):
38 """Returns content of template file as a string, or None of not found."""
39 conditions = dict(self._conditions, **more_conditions)
40 cache_key = (name, tuple(sorted(conditions.items())))
41 if cache_key in self._cache:
42 return self._cache[cache_key]
43
44 for subpath in self._subpaths:
45 template_file = os.path.join(self._root, subpath, name)
46 if os.path.exists(template_file):
47 template = ''.join(open(template_file).readlines())
48 template = self._Preprocess(template, template_file, conditions)
49 self._cache[cache_key] = template
50 return template
51
52 return None
53
static void readlines(const void *data, size_t size, F f)
Definition: editor.cpp:30
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

The documentation for this class was generated from the following file: