Not mathcing whitespace bug fixed

This commit is contained in:
Bugra Onal 2022-07-13 16:38:22 -07:00
parent 5f45f7db15
commit d36f74a514
1 changed files with 8 additions and 7 deletions

View File

@ -12,6 +12,8 @@ class baseSection:
This is the base section class for other section classes to inherit. This is the base section class for other section classes to inherit.
It is also used as the top most section. It is also used as the top most section.
""" """
def __init__(self):
self.children = []
def expand(self, dict, fd): def expand(self, dict, fd):
for c in self.children: for c in self.children:
@ -25,6 +27,7 @@ class loopSection(baseSection):
""" """
def __init__(self, var, key): def __init__(self, var, key):
baseSection.__init__(self)
self.var = var self.var = var
self.key = key self.key = key
@ -43,6 +46,7 @@ class conditionalSection(baseSection):
element. element.
""" """
def __init__(self, cond): def __init__(self, cond):
baseSection.__init__(self)
self.cond = cond self.cond = cond
def expand(self, dict, fd): def expand(self, dict, fd):
@ -86,24 +90,21 @@ class template:
lines = f.readlines() lines = f.readlines()
self.baseSectionSection = baseSection() self.baseSectionSection = baseSection()
sections = []
context = [self.baseSectionSection] context = [self.baseSectionSection]
forRE = re.compile('\{% for (\S*) in (\S*) %\}') forRE = re.compile('\s*\{% for (\S*) in (\S*) %\}')
endforRE = re.compile('\{% endfor %\}') endforRE = re.compile('\s*\{% endfor %\}')
ifRE = re.compile('\{% if (.*) %\}') ifRE = re.compile('\s*{% if (.*) %\}')
endifRE = re.compile('\{% endif %\}') endifRE = re.compile('\s*\{% endif %\}')
for line in lines: for line in lines:
m = forRE.match(line) m = forRE.match(line)
if m: if m:
section = loopSection(m.group(1), m.group(2)) section = loopSection(m.group(1), m.group(2))
sections.append(section)
context[-1].children.append(section) context[-1].children.append(section)
context.append(section) context.append(section)
continue continue
m = ifRE.match(line) m = ifRE.match(line)
if m: if m:
section = conditionalSection(m.group(1)) section = conditionalSection(m.group(1))
section.append(section)
context[-1].children.append(section) context[-1].children.append(section)
context.append(section) context.append(section)
continue continue