982e2361 by Michael Richards

Merge pull request #38 from paulj/local-formatters

Look for formatters on model object too
2 parents a4da05e6 8dabc199
......@@ -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() {
......@@ -72,6 +73,12 @@ describe('Rivets.Binding', function() {
binding.formatters.push('awesome');
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() {
......
......@@ -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
......