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
982e2361
authored
2012-07-30 15:40:37 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #38 from paulj/local-formatters
Look for formatters on model object too
2 parents
a4da05e6
8dabc199
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletions
spec/rivets/binding.js
src/rivets.coffee
spec/rivets/binding.js
View file @
982e236
...
...
@@ -15,6 +15,7 @@ describe('Rivets.Binding', function() {
el
.
setAttribute
(
'data-text'
,
'obj.name'
);
view
=
rivets
.
bind
(
el
,
{
obj
:
{}});
binding
=
view
.
bindings
[
0
];
model
=
binding
.
model
;
});
it
(
'gets assigned the routine function matching the identifier'
,
function
()
{
...
...
@@ -73,6 +74,12 @@ describe('Rivets.Binding', function() {
expect
(
binding
.
formattedValue
(
'hat'
)).
toBe
(
'awesome hat'
);
});
it
(
'uses formatters on the model'
,
function
()
{
model
.
modelAwesome
=
function
(
value
)
{
return
'model awesome '
+
value
};
binding
.
formatters
.
push
(
'modelAwesome'
);
expect
(
binding
.
formattedValue
(
'hat'
)).
toBe
(
'model awesome hat'
);
});
describe
(
'with a multi-argument formatter string'
,
function
()
{
beforeEach
(
function
()
{
rivets
.
config
.
formatters
=
{
...
...
src/rivets.coffee
View file @
982e236
...
...
@@ -26,7 +26,10 @@ class Rivets.Binding
for
formatter
in
@
formatters
args
=
formatter
.
split
/\s+/
id
=
args
.
shift
()
value
=
Rivets
.
config
.
formatters
[
id
]
value
,
args
...
value
=
if
Rivets
.
config
.
formatters
&&
Rivets
.
config
.
formatters
[
id
]
Rivets
.
config
.
formatters
[
id
]
value
,
args
...
else
@
model
[
id
]
value
,
args
...
value
...
...
Please
register
or
sign in
to post a comment