Merge pull request #38 from paulj/local-formatters
Look for formatters on model object too
Showing
2 changed files
with
11 additions
and
1 deletions
... | @@ -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,10 @@ class Rivets.Binding | ... | @@ -26,7 +26,10 @@ 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 = if Rivets.config.formatters && Rivets.config.formatters[id] |
30 | Rivets.config.formatters[id] value, args... | ||
31 | else | ||
32 | @model[id] value, args... | ||
30 | 33 | ||
31 | value | 34 | value |
32 | 35 | ... | ... |
-
Please register or sign in to post a comment