Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
266a3308
authored
11 years ago
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implement Rivets.TextTemplateParser. [#181]
1 parent
f9a54207
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
src/rivets.coffee
src/rivets.coffee
View file @
266a330
...
...
@@ -250,6 +250,54 @@ class Rivets.View
@
models
[
key
]
=
model
binding
.
update
()
for
binding
in
@
select
(
b
)
->
b
.
key
is
key
# Rivets.TextTemplateParser
# -------------------------
# Rivets.js text template parser and tokenizer for mustache-style text content
# binding declarations.
class
Rivets
.
TextTemplateParser
types
=
text
:
0
binding
:
1
# Parses the template and returns a set of tokens, separating static portions
# of text from binding declarations.
@
parse
:
(
template
)
->
tokens
=
[]
length
=
template
.
length
index
=
0
lastIndex
=
0
while
lastIndex
<
length
index
=
template
.
indexOf
'{{'
,
lastIndex
if
index
<
0
tokens
.
push
type
:
types
.
text
,
value
:
template
.
slice
lastIndex
break
else
if
index
>
0
and
lastIndex
<
index
tokens
.
push
type
:
types
.
text
,
value
:
template
.
slice
lastIndex
,
index
lastIndex
=
index
+
2
index
=
template
.
indexOf
'}}'
,
lastIndex
if
index
<
0
substring
=
template
.
slice
lastIndex
-
2
lastToken
=
tokens
[
tokens
.
length
-
1
]
if
lastToken
?
.
type
is
types
.
text
lastToken
.
value
+=
substring
else
tokens
.
push
type
:
types
.
text
,
value
:
substring
break
value
=
template
.
slice
(
lastIndex
,
index
).
trim
()
tokens
.
push
type
:
types
.
binding
,
value
:
value
lastIndex
=
index
+
2
tokens
# Rivets.Util
# -----------
...
...
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment