Avoid parsing the template again and again by cloning it

This commit is contained in:
Grégory Soutadé 2012-12-31 17:45:21 +01:00
parent 0cef65c4e1
commit 224faf5dc4
2 changed files with 9 additions and 4 deletions

View File

@ -315,15 +315,18 @@ class Index(DynastieGenerator):
os.mkdir(output + self.dirname)
filename = self.dirname + '/' + self.filename + '.html'
impl = xml.dom.getDOMImplementation()
while self.cur_page <= self.nb_pages:
#print 'Generate ' + filename
dom_ = impl.createDocument('', 'xml', None)
dom_.replaceChild(dom.firstChild.cloneNode(0), dom_.firstChild)
nodes = dom.getElementsByTagName("*")
nodes[0] = self.parse(src, self.hooks, posts, dom, nodes[0])
nodes[0] = self.parse(src, self.hooks, posts, dom_, nodes[0])
self.writeIfNotTheSame(output + filename, nodes[0])
self.cur_page = self.cur_page + 1
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
dom = parse(src + '/_%s.html' % name)
filename = output + filename

View File

@ -158,10 +158,13 @@ class Post(Index):
self.addError('Error parsing _%s.html : ' + e)
return self.report
impl = xml.dom.getDOMImplementation()
for post in posts:
#print 'Generate ' + filename
dom_ = impl.createDocument('', 'xml', None)
dom_.replaceChild(dom.firstChild.cloneNode(0), dom_.firstChild)
nodes = dom.getElementsByTagName("*")
nodes[0] = self.parse(src, self.hooks, post, dom, nodes[0])
nodes[0] = self.parse(src, self.hooks, post, dom_, nodes[0])
filename = output + '/post/'
filename = filename + post.creation_date.strftime("%Y") + '/' + post.creation_date.strftime("%m") + '/'
@ -169,7 +172,6 @@ class Post(Index):
os.makedirs(filename)
filename = filename + post.title_slug + '.html'
self.writeIfNotTheSame(filename, nodes[0])
dom = parse(src + '/_post.html')
if not self.somethingWrote:
self.addReport('Nothing changed')