Commit e4175d4b by Chris Jerdonek

Renamed "pos" to "end_index".

parent 021ab20a
...@@ -164,20 +164,20 @@ class Template(object): ...@@ -164,20 +164,20 @@ class Template(object):
# Save the literal text content. # Save the literal text content.
buffer.append(captures['content']) buffer.append(captures['content'])
pos = match.end() end_index = match.end()
tagPos = match.end('content') tagPos = match.end('content')
# Standalone (non-interpolation) tags consume the entire line, # Standalone (non-interpolation) tags consume the entire line,
# both leading whitespace and trailing newline. # both leading whitespace and trailing newline.
tagBeganLine = not tagPos or template[tagPos - 1] in ['\r', '\n'] tagBeganLine = not tagPos or template[tagPos - 1] in ['\r', '\n']
tagEndedLine = (pos == len(template) or template[pos] in ['\r', '\n']) tagEndedLine = (end_index == len(template) or template[end_index] in ['\r', '\n'])
interpolationTag = captures['tag'] in ['', '&', '{'] interpolationTag = captures['tag'] in ['', '&', '{']
if (tagBeganLine and tagEndedLine and not interpolationTag): if (tagBeganLine and tagEndedLine and not interpolationTag):
if pos < len(template): if end_index < len(template):
pos += template[pos] == '\r' and 1 or 0 end_index += template[end_index] == '\r' and 1 or 0
if pos < len(template): if end_index < len(template):
pos += template[pos] == '\n' and 1 or 0 end_index += template[end_index] == '\n' and 1 or 0
elif captures['whitespace']: elif captures['whitespace']:
buffer.append(captures['whitespace']) buffer.append(captures['whitespace'])
tagPos += len(captures['whitespace']) tagPos += len(captures['whitespace'])
...@@ -193,16 +193,16 @@ class Template(object): ...@@ -193,16 +193,16 @@ class Template(object):
buffer.append(partialTag(name, captures['whitespace'])) buffer.append(partialTag(name, captures['whitespace']))
elif captures['tag'] in ['#', '^']: elif captures['tag'] in ['#', '^']:
try: try:
self.parse_to_tree(template, index=pos) self.parse_to_tree(template, index=end_index)
except EndOfSection as e: except EndOfSection as e:
bufr = e.buffer bufr = e.buffer
tmpl = e.template tmpl = e.template
pos = e.position end_index = e.position
tag = { '#': sectionTag, '^': inverseTag }[captures['tag']] tag = { '#': sectionTag, '^': inverseTag }[captures['tag']]
buffer.append(tag(name, bufr, tmpl, (self.otag, self.ctag))) buffer.append(tag(name, bufr, tmpl, (self.otag, self.ctag)))
elif captures['tag'] == '/': elif captures['tag'] == '/':
raise EndOfSection(buffer, template[start_index:tagPos], pos) raise EndOfSection(buffer, template[start_index:tagPos], end_index)
elif captures['tag'] in ['{', '&']: elif captures['tag'] in ['{', '&']:
buffer.append(unescapedTag(name, (self.otag, self.ctag))) buffer.append(unescapedTag(name, (self.otag, self.ctag)))
elif captures['tag'] == '': elif captures['tag'] == '':
...@@ -210,7 +210,7 @@ class Template(object): ...@@ -210,7 +210,7 @@ class Template(object):
else: else:
raise Exception("'%s' is an unrecognized type!" % captures['tag']) raise Exception("'%s' is an unrecognized type!" % captures['tag'])
return pos return end_index
def render(self, encoding=None): def render(self, encoding=None):
result = render(self.template, self.view) result = render(self.template, self.view)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment