Take both the start and end delimiter into account when tokenizing a text template. [#219]
Showing
1 changed file
with
4 additions
and
5 deletions
... | @@ -33,7 +33,6 @@ class Rivets.TextTemplateParser | ... | @@ -33,7 +33,6 @@ class Rivets.TextTemplateParser |
33 | @parse: (template, delimiters) -> | 33 | @parse: (template, delimiters) -> |
34 | tokens = [] | 34 | tokens = [] |
35 | length = template.length | 35 | length = template.length |
36 | delimiterOffset = delimiters[1].length | ||
37 | index = 0 | 36 | index = 0 |
38 | lastIndex = 0 | 37 | lastIndex = 0 |
39 | 38 | ||
... | @@ -47,11 +46,11 @@ class Rivets.TextTemplateParser | ... | @@ -47,11 +46,11 @@ class Rivets.TextTemplateParser |
47 | if index > 0 and lastIndex < index | 46 | if index > 0 and lastIndex < index |
48 | tokens.push type: @types.text, value: template.slice lastIndex, index | 47 | tokens.push type: @types.text, value: template.slice lastIndex, index |
49 | 48 | ||
50 | lastIndex = index + 2 | 49 | lastIndex = index + delimiters[0].length |
51 | index = template.indexOf delimiters[1], lastIndex | 50 | index = template.indexOf delimiters[1], lastIndex |
52 | 51 | ||
53 | if index < 0 | 52 | if index < 0 |
54 | substring = template.slice lastIndex - 2 | 53 | substring = template.slice lastIndex - delimiters[1].length |
55 | lastToken = tokens[tokens.length - 1] | 54 | lastToken = tokens[tokens.length - 1] |
56 | 55 | ||
57 | if lastToken?.type is @types.text | 56 | if lastToken?.type is @types.text |
... | @@ -61,8 +60,8 @@ class Rivets.TextTemplateParser | ... | @@ -61,8 +60,8 @@ class Rivets.TextTemplateParser |
61 | 60 | ||
62 | break | 61 | break |
63 | 62 | ||
64 | value = template.slice(lastIndex, index).trim() | 63 | value = template.slice(lastIndex, index) |
65 | tokens.push type: @types.binding, value: value | 64 | tokens.push type: @types.binding, value: value |
66 | lastIndex = index + delimiterOffset | 65 | lastIndex = index + delimiters[1].length |
67 | 66 | ||
68 | tokens | 67 | tokens | ... | ... |
-
Please register or sign in to post a comment