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
9b103172
authored
2012-10-23 17:41:40 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
s/routines/binders
1 parent
372a30f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
28 deletions
spec/rivets/binding.js
spec/rivets/routines.js
src/rivets.coffee
spec/rivets/binding.js
View file @
9b10317
...
...
@@ -19,7 +19,7 @@ describe('Rivets.Binding', function() {
});
it
(
'gets assigned the proper binder routine matching the identifier'
,
function
()
{
expect
(
binding
.
binder
.
routine
).
toBe
(
rivets
.
routine
s
.
text
);
expect
(
binding
.
binder
.
routine
).
toBe
(
rivets
.
binder
s
.
text
);
});
describe
(
'bind()'
,
function
()
{
...
...
spec/rivets/routines.js
View file @
9b10317
...
...
@@ -18,13 +18,13 @@ describe('Routines', function() {
describe
(
'text'
,
function
()
{
it
(
"sets the element's text content"
,
function
()
{
rivets
.
routine
s
.
text
(
el
,
'<em>gluten-free</em>'
);
rivets
.
binder
s
.
text
(
el
,
'<em>gluten-free</em>'
);
expect
(
el
.
textContent
||
el
.
innerText
).
toBe
(
'<em>gluten-free</em>'
);
expect
(
el
.
innerHTML
).
toBe
(
'<em>gluten-free</em>'
);
});
it
(
"sets the element's text content to zero when a numeric zero is passed"
,
function
()
{
rivets
.
routine
s
.
text
(
el
,
0
);
rivets
.
binder
s
.
text
(
el
,
0
);
expect
(
el
.
textContent
||
el
.
innerText
).
toBe
(
'0'
);
expect
(
el
.
innerHTML
).
toBe
(
'0'
);
});
...
...
@@ -32,13 +32,13 @@ describe('Routines', function() {
describe
(
'html'
,
function
()
{
it
(
"sets the element's HTML content"
,
function
()
{
rivets
.
routine
s
.
html
(
el
,
'<strong>fixie</strong>'
);
rivets
.
binder
s
.
html
(
el
,
'<strong>fixie</strong>'
);
expect
(
el
.
textContent
||
el
.
innerText
).
toBe
(
'fixie'
);
expect
(
el
.
innerHTML
).
toBe
(
'<strong>fixie</strong>'
);
});
it
(
"sets the element's HTML content to zero when a zero value is passed"
,
function
()
{
rivets
.
routine
s
.
html
(
el
,
0
);
rivets
.
binder
s
.
html
(
el
,
0
);
expect
(
el
.
textContent
||
el
.
innerText
).
toBe
(
'0'
);
expect
(
el
.
innerHTML
).
toBe
(
'0'
);
});
...
...
@@ -46,17 +46,17 @@ describe('Routines', function() {
describe
(
'value'
,
function
()
{
it
(
"sets the element's value"
,
function
()
{
rivets
.
routine
s
.
value
.
routine
(
input
,
'pitchfork'
);
rivets
.
binder
s
.
value
.
routine
(
input
,
'pitchfork'
);
expect
(
input
.
value
).
toBe
(
'pitchfork'
);
});
it
(
"applies a default value to the element when the model doesn't contain it"
,
function
()
{
rivets
.
routine
s
.
value
.
routine
(
input
,
undefined
);
rivets
.
binder
s
.
value
.
routine
(
input
,
undefined
);
expect
(
input
.
value
).
toBe
(
''
);
});
it
(
"sets the element's value to zero when a zero value is passed"
,
function
()
{
rivets
.
routine
s
.
value
.
routine
(
input
,
0
);
rivets
.
binder
s
.
value
.
routine
(
input
,
0
);
expect
(
input
.
value
).
toBe
(
'0'
);
});
});
...
...
@@ -64,14 +64,14 @@ describe('Routines', function() {
describe
(
'show'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'shows the element'
,
function
()
{
rivets
.
routine
s
.
show
(
el
,
true
);
rivets
.
binder
s
.
show
(
el
,
true
);
expect
(
el
.
style
.
display
).
toBe
(
''
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'hides the element'
,
function
()
{
rivets
.
routine
s
.
show
(
el
,
false
);
rivets
.
binder
s
.
show
(
el
,
false
);
expect
(
el
.
style
.
display
).
toBe
(
'none'
);
});
});
...
...
@@ -80,14 +80,14 @@ describe('Routines', function() {
describe
(
'hide'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'hides the element'
,
function
()
{
rivets
.
routine
s
.
hide
(
el
,
true
);
rivets
.
binder
s
.
hide
(
el
,
true
);
expect
(
el
.
style
.
display
).
toBe
(
'none'
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'shows the element'
,
function
()
{
rivets
.
routine
s
.
hide
(
el
,
false
);
rivets
.
binder
s
.
hide
(
el
,
false
);
expect
(
el
.
style
.
display
).
toBe
(
''
);
});
});
...
...
@@ -96,14 +96,14 @@ describe('Routines', function() {
describe
(
'enabled'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'enables the element'
,
function
()
{
rivets
.
routine
s
.
enabled
(
el
,
true
);
rivets
.
binder
s
.
enabled
(
el
,
true
);
expect
(
el
.
disabled
).
toBe
(
false
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'disables the element'
,
function
()
{
rivets
.
routine
s
.
enabled
(
el
,
false
);
rivets
.
binder
s
.
enabled
(
el
,
false
);
expect
(
el
.
disabled
).
toBe
(
true
);
});
});
...
...
@@ -112,14 +112,14 @@ describe('Routines', function() {
describe
(
'disabled'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'disables the element'
,
function
()
{
rivets
.
routine
s
.
disabled
(
el
,
true
);
rivets
.
binder
s
.
disabled
(
el
,
true
);
expect
(
el
.
disabled
).
toBe
(
true
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'enables the element'
,
function
()
{
rivets
.
routine
s
.
disabled
(
el
,
false
);
rivets
.
binder
s
.
disabled
(
el
,
false
);
expect
(
el
.
disabled
).
toBe
(
false
);
});
});
...
...
@@ -128,14 +128,14 @@ describe('Routines', function() {
describe
(
'checked'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'checks the element'
,
function
()
{
rivets
.
routine
s
.
checked
.
routine
(
el
,
true
);
rivets
.
binder
s
.
checked
.
routine
(
el
,
true
);
expect
(
el
.
checked
).
toBe
(
true
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'unchecks the element'
,
function
()
{
rivets
.
routine
s
.
checked
.
routine
(
el
,
false
);
rivets
.
binder
s
.
checked
.
routine
(
el
,
false
);
expect
(
el
.
checked
).
toBe
(
false
);
});
});
...
...
@@ -144,14 +144,14 @@ describe('Routines', function() {
describe
(
'unchecked'
,
function
()
{
describe
(
'with a truthy value'
,
function
()
{
it
(
'unchecks the element'
,
function
()
{
rivets
.
routine
s
.
unchecked
.
routine
(
el
,
true
);
rivets
.
binder
s
.
unchecked
.
routine
(
el
,
true
);
expect
(
el
.
checked
).
toBe
(
false
);
});
});
describe
(
'with a falsey value'
,
function
()
{
it
(
'checks the element'
,
function
()
{
rivets
.
routine
s
.
unchecked
.
routine
(
el
,
false
);
rivets
.
binder
s
.
unchecked
.
routine
(
el
,
false
);
expect
(
el
.
checked
).
toBe
(
true
);
});
});
...
...
src/rivets.coffee
View file @
9b10317
...
...
@@ -15,8 +15,8 @@ class Rivets.Binding
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor
:
(
@
el
,
@
type
,
@
model
,
@
keypath
,
@
options
=
{})
->
unless
@
binder
=
Rivets
.
routine
s
[
type
]
for
identifier
,
value
of
Rivets
.
routine
s
unless
@
binder
=
Rivets
.
binder
s
[
type
]
for
identifier
,
value
of
Rivets
.
binder
s
if
identifier
isnt
'*'
and
identifier
.
indexOf
(
'*'
)
isnt
-
1
regexp
=
new
RegExp
"^
#{
identifier
.
replace
(
'*'
,
'.+'
)
}
$"
if
regexp
.
test
type
...
...
@@ -24,7 +24,7 @@ class Rivets.Binding
@
args
=
new
RegExp
(
"^
#{
identifier
.
replace
(
'*'
,
'(.+)'
)
}
$"
).
exec
type
@
args
.
shift
()
@
binder
or=
Rivets
.
routine
s
[
'*'
]
@
binder
or=
Rivets
.
binder
s
[
'*'
]
if
@
binder
instanceof
Function
@
binder
=
{
routine
:
@
binder
}
...
...
@@ -121,14 +121,14 @@ class Rivets.View
for
attribute
in
node
.
attributes
if
bindingRegExp
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
unless
binder
=
Rivets
.
routine
s
[
type
]
for
identifier
,
value
of
Rivets
.
routine
s
unless
binder
=
Rivets
.
binder
s
[
type
]
for
identifier
,
value
of
Rivets
.
binder
s
if
identifier
isnt
'*'
and
identifier
.
indexOf
(
'*'
)
isnt
-
1
regexp
=
new
RegExp
"^
#{
identifier
.
replace
(
'*'
,
'.+'
)
}
$"
if
regexp
.
test
type
binder
=
value
binder
or=
Rivets
.
routine
s
[
'*'
]
binder
or=
Rivets
.
binder
s
[
'*'
]
if
binder
.
block
skipNodes
.
push
n
for
n
in
node
.
getElementsByTagName
'*'
...
...
@@ -231,7 +231,7 @@ getInputValue = (el) ->
else
el
.
value
# Core binding routines.
Rivets
.
routine
s
=
Rivets
.
binder
s
=
enabled
:
(
el
,
value
)
->
el
.
disabled
=
!
value
...
...
@@ -345,7 +345,7 @@ Rivets.formatters = {}
# The rivets module. This is the public interface that gets exported.
rivets
=
# Exposes the core binding routines that can be extended or stripped down.
routines
:
Rivets
.
routine
s
binders
:
Rivets
.
binder
s
# Exposes the formatters object to be extended.
formatters
:
Rivets
.
formatters
...
...
Please
register
or
sign in
to post a comment