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
d0ec373e
authored
2013-03-14 10:42:43 -0400
by
Zack Owens
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
allowing formatters to be passed in as options
1 parent
5cd20248
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
spec/rivets/binding.js
src/rivets.coffee
spec/rivets/binding.js
View file @
d0ec373
describe
(
'Rivets.Binding'
,
function
()
{
var
model
,
el
,
view
,
binding
;
var
model
,
el
,
view
,
binding
,
opts
;
beforeEach
(
function
()
{
rivets
.
configure
({
...
...
@@ -13,7 +13,8 @@ describe('Rivets.Binding', function() {
el
=
document
.
createElement
(
'div'
);
el
.
setAttribute
(
'data-text'
,
'obj.name'
);
view
=
rivets
.
bind
(
el
,
{
obj
:
{}});
opts
=
{};
view
=
rivets
.
bind
(
el
,
{
obj
:
{}},
opts
);
binding
=
view
.
bindings
[
0
];
model
=
binding
.
model
;
});
...
...
@@ -310,6 +311,12 @@ describe('Rivets.Binding', function() {
expect
(
binding
.
formattedValue
(
'hat'
)).
toBe
(
'model awesome hat'
);
});
it
(
'uses formatters from the bind options'
,
function
()
{
opts
.
formatters
=
{
optAwesome
:
function
(
value
)
{
return
'option awesome '
+
value
;
}
};
binding
.
formatters
.
push
(
"optAwesome"
);
expect
(
binding
.
formattedValue
(
'hat'
)).
toBe
(
'option awesome hat'
);
});
describe
(
'with a multi-argument formatter string'
,
function
()
{
beforeEach
(
function
()
{
rivets
.
formatters
.
awesome
=
function
(
value
,
prefix
)
{
...
...
src/rivets.coffee
View file @
d0ec373
...
...
@@ -40,6 +40,8 @@ class Rivets.Binding
formatter
=
if
@
model
[
id
]
instanceof
Function
@
model
[
id
]
else
if
@
options
?
.
bindingOptions
?
.
formatters
?
[
id
]
instanceof
Function
@
options
.
bindingOptions
.
formatters
[
id
]
else
Rivets
.
formatters
[
id
]
...
...
@@ -127,7 +129,7 @@ class Rivets.Binding
class
Rivets
.
View
# The DOM elements and the model objects for binding are passed into the
# constructor.
constructor
:
(
@
els
,
@
models
)
->
constructor
:
(
@
els
,
@
models
,
@
options
)
->
@
els
=
[
@
els
]
unless
(
@
els
.
jquery
||
@
els
instanceof
Array
)
@
build
()
...
...
@@ -166,6 +168,9 @@ class Rivets.View
if
bindingRegExp
.
test
attribute
.
name
options
=
{}
if
@
options
?
and
typeof
@
options
is
'object'
options
.
bindingOptions
=
@
options
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
pipes
=
(
pipe
.
trim
()
for
pipe
in
attribute
.
value
.
split
'|'
)
context
=
(
ctx
.
trim
()
for
ctx
in
pipes
.
shift
().
split
'<'
)
...
...
@@ -394,8 +399,8 @@ rivets =
# Binds a set of model objects to a parent DOM element. Returns a Rivets.View
# instance.
bind
:
(
el
,
models
=
{})
->
view
=
new
Rivets
.
View
(
el
,
models
)
bind
:
(
el
,
models
=
{}
,
options
)
->
view
=
new
Rivets
.
View
(
el
,
models
,
options
)
view
.
bind
()
view
...
...
Please
register
or
sign in
to post a comment