-
Notifications
You must be signed in to change notification settings - Fork 9
/
render.py
executable file
·51 lines (41 loc) · 1010 Bytes
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
"""
20170330 Elias / Vanissoft
render templates
"""
import string
def template():
return response_html(open(pfil).read())
class Render():
"""
t = Render('index.html').render()
Sustituye marcadores ${var} por su valor o por el fichero que referencia
${v1} ${header.html}
"""
def __init__(self, fname):
self.filename = fname.split('/')[-1]
self.path = '/'.join([x for x in fname.split('/')[:-1]]) + '/'
self.template = self.path + self.filename
self.file_o = open(self.template).read()
self.output = None
self.files = None
async def parse(self):
self.output = ''
self.files = []
fo = self.file_o.split('${')
if len(fo) < 2:
return fo[0]
for i in fo:
if '}' in i:
f1 = i.find('}')
fname = i[:f1]
self.files.append(fname)
self.output += open(self.path+fname).read()
self.output += i[f1+1:]
else:
self.output += i
return self.output
def froga(self):
tmp = self.file_o
print(tmp)
if __name__ == '__main__':
print("import in main")