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
f7c291b5
authored
2013-06-22 02:32:32 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Rewrite the DOM template parser in Rivets.View#build to include text template parsing. [#181]
1 parent
6cb9af1e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
26 deletions
src/rivets.coffee
src/rivets.coffee
View file @
f7c291b
...
...
@@ -173,8 +173,47 @@ class Rivets.View
skipNodes
=
[]
bindingRegExp
=
@
bindingRegExp
()
buildBinding
=
(
node
,
type
,
declaration
)
=>
options
=
{}
pipes
=
(
pipe
.
trim
()
for
pipe
in
declaration
.
split
'|'
)
context
=
(
ctx
.
trim
()
for
ctx
in
pipes
.
shift
().
split
'<'
)
path
=
context
.
shift
()
splitPath
=
path
.
split
/\.|:/
options
.
formatters
=
pipes
options
.
bypass
=
path
.
indexOf
(
':'
)
!=
-
1
if
splitPath
[
0
]
key
=
splitPath
.
shift
()
else
key
=
null
splitPath
.
shift
()
keypath
=
splitPath
.
join
'.'
if
dependencies
=
context
.
shift
()
options
.
dependencies
=
dependencies
.
split
/\s+/
@
bindings
.
push
new
Rivets
.
Binding
@
,
node
,
type
,
key
,
keypath
,
options
parse
=
(
node
)
=>
unless
node
in
skipNodes
if
node
.
nodeType
is
Node
.
TEXT_NODE
if
(
tokens
=
Rivets
.
TextTemplateParser
.
parse
node
.
data
).
length
unless
tokens
.
length
is
1
and
tokens
[
0
].
type
is
0
[
startToken
,
restTokens
...]
=
tokens
node
.
data
=
startToken
.
value
switch
startToken
.
type
when
0
then
node
.
data
=
startToken
.
value
when
1
then
buildBinding
node
,
'textNode'
,
startToken
.
value
for
token
in
restTokens
node
.
parentNode
.
appendChild
(
text
=
document
.
createTextNode
token
.
value
)
buildBinding
text
,
'textNode'
,
token
.
value
if
token
.
type
is
1
else
if
node
.
attributes
?
for
attribute
in
node
.
attributes
if
bindingRegExp
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
...
...
@@ -188,39 +227,17 @@ class Rivets.View
binder
or=
@
binders
[
'*'
]
if
binder
.
block
skipNodes
.
push
n
for
n
in
node
.
getElementsByTagName
'*'
skipNodes
.
push
n
for
n
in
node
.
childNodes
attributes
=
[
attribute
]
for
attribute
in
attributes
or
node
.
attributes
if
bindingRegExp
.
test
attribute
.
name
options
=
{}
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
pipes
=
(
pipe
.
trim
()
for
pipe
in
attribute
.
value
.
split
'|'
)
context
=
(
ctx
.
trim
()
for
ctx
in
pipes
.
shift
().
split
'<'
)
path
=
context
.
shift
()
splitPath
=
path
.
split
/\.|:/
options
.
formatters
=
pipes
options
.
bypass
=
path
.
indexOf
(
':'
)
!=
-
1
if
splitPath
[
0
]
key
=
splitPath
.
shift
()
else
key
=
null
splitPath
.
shift
()
keypath
=
splitPath
.
join
'.'
buildBinding
node
,
type
,
attribute
.
value
if
not
key
or
@
models
[
key
]
?
if
dependencies
=
context
.
shift
()
options
.
dependencies
=
dependencies
.
split
/\s+/
@
bindings
.
push
new
Rivets
.
Binding
@
,
node
,
type
,
key
,
keypath
,
options
attributes
=
null
if
attributes
return
parse
childNode
for
childNode
in
node
.
childNodes
for
el
in
@
els
parse
el
parse
node
for
node
in
el
.
getElementsByTagName
'*'
when
node
.
attributes
?
parse
el
for
el
in
@
els
return
...
...
Please
register
or
sign in
to post a comment