51c50695 by Michael Richards

Update the types access and use in the DOM template parser instead of 0. [#181]

1 parent 54ae655a
...@@ -212,10 +212,11 @@ class Rivets.View ...@@ -212,10 +212,11 @@ class Rivets.View
212 parse = (node) => 212 parse = (node) =>
213 unless node in skipNodes 213 unless node in skipNodes
214 if node.nodeType is Node.TEXT_NODE 214 if node.nodeType is Node.TEXT_NODE
215 if (tokens = Rivets.TextTemplateParser.parse node.data).length 215 parser = Rivets.TextTemplateParser
216 unless tokens.length is 1 and tokens[0].type is 0
217 [startToken, restTokens...] = tokens
218 216
217 if (tokens = parser.parse node.data).length
218 unless tokens.length is 1 and tokens[0].type is parser.types.text
219 [startToken, restTokens...] = tokens
219 node.data = startToken.value 220 node.data = startToken.value
220 221
221 switch startToken.type 222 switch startToken.type
...@@ -285,7 +286,7 @@ class Rivets.View ...@@ -285,7 +286,7 @@ class Rivets.View
285 # Rivets.js text template parser and tokenizer for mustache-style text content 286 # Rivets.js text template parser and tokenizer for mustache-style text content
286 # binding declarations. 287 # binding declarations.
287 class Rivets.TextTemplateParser 288 class Rivets.TextTemplateParser
288 types = 289 @types:
289 text: 0 290 text: 0
290 binding: 1 291 binding: 1
291 292
...@@ -301,11 +302,11 @@ class Rivets.TextTemplateParser ...@@ -301,11 +302,11 @@ class Rivets.TextTemplateParser
301 index = template.indexOf '{{', lastIndex 302 index = template.indexOf '{{', lastIndex
302 303
303 if index < 0 304 if index < 0
304 tokens.push type: types.text, value: template.slice lastIndex 305 tokens.push type: @types.text, value: template.slice lastIndex
305 break 306 break
306 else 307 else
307 if index > 0 and lastIndex < index 308 if index > 0 and lastIndex < index
308 tokens.push type: types.text, value: template.slice lastIndex, index 309 tokens.push type: @types.text, value: template.slice lastIndex, index
309 310
310 lastIndex = index + 2 311 lastIndex = index + 2
311 index = template.indexOf '}}', lastIndex 312 index = template.indexOf '}}', lastIndex
...@@ -314,15 +315,15 @@ class Rivets.TextTemplateParser ...@@ -314,15 +315,15 @@ class Rivets.TextTemplateParser
314 substring = template.slice lastIndex - 2 315 substring = template.slice lastIndex - 2
315 lastToken = tokens[tokens.length - 1] 316 lastToken = tokens[tokens.length - 1]
316 317
317 if lastToken?.type is types.text 318 if lastToken?.type is @types.text
318 lastToken.value += substring 319 lastToken.value += substring
319 else 320 else
320 tokens.push type: types.text, value: substring 321 tokens.push type: @types.text, value: substring
321 322
322 break 323 break
323 324
324 value = template.slice(lastIndex, index).trim() 325 value = template.slice(lastIndex, index).trim()
325 tokens.push type: types.binding, value: value 326 tokens.push type: @types.binding, value: value
326 lastIndex = index + 2 327 lastIndex = index + 2
327 328
328 tokens 329 tokens
......