comparison jadestache.py @ 30:e86642cf7393

style and requirements.txt cleanup
author drewp@bigasterisk.com
date Sun, 12 Jul 2020 13:33:54 -0700
parents 7c82ffbca5d0
children 293a694304b8
comparison
equal deleted inserted replaced
29:890584020372 30:e86642cf7393
1 import pyjade, pyjade.exceptions, pystache 1 import pyjade
2 import pyjade.exceptions
3 import pystache
2 4
3 5
4 class _JadeLoader(pystache.loader.Loader): 6 class _JadeLoader(pystache.loader.Loader):
5 """ 7 """
6 expands jade of incoming files. Also includes a cache so it doesn't 8 expands jade of incoming files. Also includes a cache so it doesn't
7 read the same file twice 9 read the same file twice
8 """ 10 """
9 def __init__(self, *args, **kw): 11 def __init__(self, *args, **kw):
10 pystache.renderer.Loader.__init__(self, *args, **kw) 12 pystache.renderer.Loader.__init__(self, *args, **kw)
11 self.seen = {} # path : expanded jade 13 self.seen = {} # path : expanded jade
12 14
13 def read(self, path, encoding=None): 15 def read(self, path, encoding=None):
14 if path in self.seen: 16 if path in self.seen:
15 return self.seen[path] 17 return self.seen[path]
16 18
17 b = pystache.common.read(path) 19 b = pystache.common.read(path)
18 20
19 if encoding is None: 21 if encoding is None:
20 encoding = self.file_encoding 22 encoding = self.file_encoding
21 23
22 src = self.str(b, encoding) 24 src = self.str(b, encoding)
23 25
24 expanded = pyjade.utils.process(src) 26 expanded = pyjade.utils.process(src)
25 self.seen[path] = expanded 27 self.seen[path] = expanded
26 return expanded 28 return expanded
29
27 30
28 class Renderer(pystache.renderer.Renderer): 31 class Renderer(pystache.renderer.Renderer):
29 """ 32 """
30 pystache renderer that expands base jade syntax on its input 33 pystache renderer that expands base jade syntax on its input
31 files. No jade data interpolation happens, so you could use these 34 files. No jade data interpolation happens, so you could use these
39 if 'debug' in kw: 42 if 'debug' in kw:
40 debug = kw['debug'] 43 debug = kw['debug']
41 del kw['debug'] 44 del kw['debug']
42 pystache.renderer.Renderer.__init__(self, *args, **kw) 45 pystache.renderer.Renderer.__init__(self, *args, **kw)
43 self._loader = None if debug else self._new_loader() 46 self._loader = None if debug else self._new_loader()
44 47
45 def _new_loader(self): 48 def _new_loader(self):
46 return _JadeLoader( 49 return _JadeLoader(file_encoding=self.file_encoding,
47 file_encoding=self.file_encoding, extension=self.file_extension, 50 extension=self.file_extension,
48 to_unicode=self.str, search_dirs=self.search_dirs) 51 to_unicode=self.str,
49 52 search_dirs=self.search_dirs)
53
50 def _make_loader(self): 54 def _make_loader(self):
51 if self._loader is not None: 55 if self._loader is not None:
52 return self._loader 56 return self._loader
53 else: 57 else:
54 # this is for debug mode, to make the templates get reread 58 # this is for debug mode, to make the templates get reread