##// END OF EJS Templates
test-template-engine: do not evaluate unused keywords by custom engine...
Yuya Nishihara -
r36989:ff9cb706 default
parent child Browse files
Show More
@@ -1,65 +1,64 b''
1 1
2 2 $ cat > engine.py << EOF
3 3 >
4 4 > from mercurial import (
5 5 > pycompat,
6 6 > templater,
7 7 > templateutil,
8 8 > )
9 9 >
10 10 > class mytemplater(templater.engine):
11 11 > def _load(self, t):
12 12 > return self._loader(t)
13 13 >
14 14 > def process(self, t, map):
15 15 > tmpl = self._load(t)
16 16 > props = self._defaults.copy()
17 17 > props.update(map)
18 18 > for k, v in props.items():
19 > if k in (b'templ', b'ctx', b'repo', b'revcache', b'cache',
20 > b'troubles'):
19 > if b'{{%s}}' % k not in tmpl:
21 20 > continue
22 21 > if callable(v) and getattr(v, '_requires', None) is None:
23 22 > props = self._resources.copy()
24 23 > props.update(map)
25 24 > v = v(**pycompat.strkwargs(props))
26 25 > elif callable(v):
27 26 > v = v(self, props)
28 27 > v = templateutil.stringify(v)
29 28 > tmpl = tmpl.replace(b'{{%s}}' % k, v)
30 29 > yield tmpl
31 30 >
32 31 > templater.engines[b'my'] = mytemplater
33 32 > EOF
34 33 $ hg init test
35 34 $ echo '[extensions]' > test/.hg/hgrc
36 35 $ echo "engine = `pwd`/engine.py" >> test/.hg/hgrc
37 36 $ cd test
38 37 $ cat > mymap << EOF
39 38 > changeset = my:changeset.txt
40 39 > EOF
41 40 $ cat > changeset.txt << EOF
42 41 > {{rev}} {{node}} {{author}}
43 42 > EOF
44 43 $ hg ci -Ama
45 44 adding changeset.txt
46 45 adding mymap
47 46 $ hg log --style=./mymap
48 47 0 97e5f848f0936960273bbf75be6388cd0350a32b test
49 48
50 49 $ cat > changeset.txt << EOF
51 50 > {{p1rev}} {{p1node}} {{p2rev}} {{p2node}}
52 51 > EOF
53 52 $ hg ci -Ama
54 53 $ hg log --style=./mymap
55 54 0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
56 55 -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
57 56
58 57 invalid engine type:
59 58
60 59 $ echo 'changeset = unknown:changeset.txt' > unknownenginemap
61 60 $ hg log --style=./unknownenginemap
62 61 abort: invalid template engine: unknown
63 62 [255]
64 63
65 64 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now