diff --git a/lib/tally.coffee b/lib/tally.coffee index f63d111d04b5082db3292dec1faaa7d5293001dd..1ee69f79e3dd77a5ba2e9be6d1984cd5e4ed2983 100644 --- a/lib/tally.coffee +++ b/lib/tally.coffee @@ -214,7 +214,7 @@ tally = (root, obj) -> html = node.parentNode 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]) if objList and objList.length diff --git a/lib/tally.js b/lib/tally.js index 5d1d6709876a5d74eb1e37fe345481496a8bd4e6..86626fbc8010f3a442ba143d01ae5b26fb941e7d 100644 --- a/lib/tally.js +++ b/lib/tally.js @@ -197,7 +197,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/) } } 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]); if (objList && objList.length) { diff --git a/test/render.coffee b/test/render.coffee index d1ca613774d961e8cf38b5b32829fdf17c013da0..3321eb1ffd648d4f7794ab833bfd0d9720b85945 100644 --- a/test/render.coffee +++ b/test/render.coffee @@ -95,6 +95,19 @@ describe 'Tally', -> (-> tally('

', {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 = '' + data = { people:[ {name: 'Aral'}, {name: 'Laura'}, {name: 'Natalie'}, {name: 'Osky'} ] } + errorMessage = 'missing second attribute (collection name) in data-tally-repeat:
  • . 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-dummy elements', ->