annotate jadestache.py @ 33:b82432594778

skaffold config and other updates
author drewp@bigasterisk.com
date Sat, 21 Aug 2021 14:24:57 -0700
parents e86642cf7393
children 293a694304b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
1 import pyjade
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
2 import pyjade.exceptions
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
3 import pystache
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
4
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
5
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
6 class _JadeLoader(pystache.loader.Loader):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
8 expands jade of incoming files. Also includes a cache so it doesn't
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9 read the same file twice
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
11 def __init__(self, *args, **kw):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
12 pystache.renderer.Loader.__init__(self, *args, **kw)
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
13 self.seen = {} # path : expanded jade
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
14
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
15 def read(self, path, encoding=None):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 if path in self.seen:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
17 return self.seen[path]
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
18
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
19 b = pystache.common.read(path)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
20
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
21 if encoding is None:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
22 encoding = self.file_encoding
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
23
28
7c82ffbca5d0 py3 and k8s upgrade
drewp@bigasterisk.com
parents: 2
diff changeset
24 src = self.str(b, encoding)
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
25
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
26 expanded = pyjade.utils.process(src)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
27 self.seen[path] = expanded
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
28 return expanded
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
29
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
30
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
31 class Renderer(pystache.renderer.Renderer):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
32 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33 pystache renderer that expands base jade syntax on its input
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
34 files. No jade data interpolation happens, so you could use these
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
35 same templates in the browser with js mustache.
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
36
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37 Files need to end with .mustache since it's the mustache loader
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
38 that's going to look for them.
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
39 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
40 def __init__(self, *args, **kw):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
41 debug = False
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
42 if 'debug' in kw:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
43 debug = kw['debug']
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 del kw['debug']
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
45 pystache.renderer.Renderer.__init__(self, *args, **kw)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 self._loader = None if debug else self._new_loader()
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
47
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48 def _new_loader(self):
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
49 return _JadeLoader(file_encoding=self.file_encoding,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
50 extension=self.file_extension,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
51 to_unicode=self.str,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
52 search_dirs=self.search_dirs)
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
53
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
54 def _make_loader(self):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
55 if self._loader is not None:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
56 return self._loader
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
57 else:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
58 # this is for debug mode, to make the templates get reread
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
59 return self._new_loader()