5b6f9ed2 by Paul Jones

Look for formatters on model object too

1 parent 237f7d9b
...@@ -15,6 +15,7 @@ describe('Rivets.Binding', function() { ...@@ -15,6 +15,7 @@ describe('Rivets.Binding', function() {
15 el.setAttribute('data-text', 'obj.name'); 15 el.setAttribute('data-text', 'obj.name');
16 view = rivets.bind(el, {obj: {}}); 16 view = rivets.bind(el, {obj: {}});
17 binding = view.bindings[0]; 17 binding = view.bindings[0];
18 model = binding.model;
18 }); 19 });
19 20
20 it('gets assigned the routine function matching the identifier', function() { 21 it('gets assigned the routine function matching the identifier', function() {
...@@ -73,6 +74,12 @@ describe('Rivets.Binding', function() { ...@@ -73,6 +74,12 @@ describe('Rivets.Binding', function() {
73 expect(binding.formattedValue('hat')).toBe('awesome hat'); 74 expect(binding.formattedValue('hat')).toBe('awesome hat');
74 }); 75 });
75 76
77 it('uses formatters on the model', function() {
78 model.modelAwesome = function(value) { return 'model awesome ' + value };
79 binding.formatters.push('modelAwesome');
80 expect(binding.formattedValue('hat')).toBe('model awesome hat');
81 });
82
76 describe('with a multi-argument formatter string', function() { 83 describe('with a multi-argument formatter string', function() {
77 beforeEach(function() { 84 beforeEach(function() {
78 rivets.config.formatters = { 85 rivets.config.formatters = {
......
...@@ -26,7 +26,7 @@ class Rivets.Binding ...@@ -26,7 +26,7 @@ class Rivets.Binding
26 for formatter in @formatters 26 for formatter in @formatters
27 args = formatter.split /\s+/ 27 args = formatter.split /\s+/
28 id = args.shift() 28 id = args.shift()
29 value = Rivets.config.formatters[id] value, args... 29 value = (Rivets.config.formatters[id] || @model[id]) value, args...
30 30
31 value 31 value
32 32
......