Commit 74a480d9 authored by Oskar Kalbag's avatar Oskar Kalbag

Improved the error message for the missing collection name condition in a repeater.

parent 73cd1284
...@@ -214,7 +214,7 @@ tally = (root, obj) -> ...@@ -214,7 +214,7 @@ tally = (root, obj) ->
html = node.parentNode html = node.parentNode
html.removeChild tmpNode while (tmpNode = node.nextSibling) and (tmpNode.qdup or (tmpNode.nodeType is 1 and tmpNode.getAttribute(qdup))) html.removeChild tmpNode while (tmpNode = node.nextSibling) and (tmpNode.qdup or (tmpNode.nodeType is 1 and tmpNode.getAttribute(qdup)))
throw new Error(attr2) unless attr2[1] throw new Error('missing second attribute (collection name) in data-tally-repeat: ' + node.outerHTML + '. The correct syntax is data-tally-repeat="value collection". e.g., to iterate over an array called people: data-tally-repeat="person people". And then, from within the loop, you can access properties of the person object (e.g., person.name, person.age, etc.)') unless attr2[1]
objList = resolve(obj, attr2[1]) objList = resolve(obj, attr2[1])
if objList and objList.length if objList and objList.length
......
...@@ -197,7 +197,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/) ...@@ -197,7 +197,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
} }
} }
if (!attr2[1]) { if (!attr2[1]) {
throw new Error(attr2); throw new Error('missing second attribute (collection name) in data-tally-repeat: ' + node.outerHTML + '. The correct syntax is data-tally-repeat="value collection". e.g., to iterate over an array called people: data-tally-repeat="person people". And then, from within the loop, you can access properties of the person object (e.g., person.name, person.age, etc.)');
} }
objList = resolve(obj, attr2[1]); objList = resolve(obj, attr2[1]);
if (objList && objList.length) { if (objList && objList.length) {
......
...@@ -95,6 +95,19 @@ describe 'Tally', -> ...@@ -95,6 +95,19 @@ describe 'Tally', ->
(-> (->
tally('<html><p data-tally-attribute=" href theURL "></p></html>', {theURL: 'http://aralbalkan.com'})).should.not.throw() tally('<html><p data-tally-attribute=" href theURL "></p></html>', {theURL: 'http://aralbalkan.com'})).should.not.throw()
#
# Error checking tests for data-tally-repeat.
#
it 'should throw an error if the second attribute (collection name) in an iterator is missing', ->
template = '<html><ul><li data-tally-repeat="person"><span data-tally-text="person.name"></span></li></ul></html>'
data = { people:[ {name: 'Aral'}, {name: 'Laura'}, {name: 'Natalie'}, {name: 'Osky'} ] }
errorMessage = 'missing second attribute (collection name) in data-tally-repeat: <li data-tally-repeat="person"><span data-tally-text="person.name"></span></li>. The correct syntax is data-tally-repeat="value collection". e.g., to iterate over an array called people: data-tally-repeat="person people". And then, from within the loop, you can access properties of the person object (e.g., person.name, person.age, etc.)'
(->
tally(template, data)
).should.throw(errorMessage)
# it 'should not include data-tally-* attributes if renderStatic option is set', -> # it 'should not include data-tally-* attributes if renderStatic option is set', ->
it 'should not include data-tally-dummy elements', -> it 'should not include data-tally-dummy elements', ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment