0ecd9abc by Michael Richards

Merge pull request #220 from mikeric/template-tokenizer-improvements

Improve the text template tokenizer
2 parents 615d3296 d434dca9
......@@ -33,7 +33,6 @@ class Rivets.TextTemplateParser
@parse: (template, delimiters) ->
tokens = []
length = template.length
delimiterOffset = delimiters[1].length
index = 0
lastIndex = 0
......@@ -47,11 +46,11 @@ class Rivets.TextTemplateParser
if index > 0 and lastIndex < index
tokens.push type: @types.text, value: template.slice lastIndex, index
lastIndex = index + 2
lastIndex = index + delimiters[0].length
index = template.indexOf delimiters[1], lastIndex
if index < 0
substring = template.slice lastIndex - 2
substring = template.slice lastIndex - delimiters[1].length
lastToken = tokens[tokens.length - 1]
if lastToken?.type is @types.text
......@@ -61,8 +60,8 @@ class Rivets.TextTemplateParser
break
value = template.slice(lastIndex, index).trim()
value = template.slice(lastIndex, index)
tokens.push type: @types.binding, value: value
lastIndex = index + delimiterOffset
lastIndex = index + delimiters[1].length
tokens
......