Commit 3621ec39 authored by Oskar Kalbag's avatar Oskar Kalbag

Improved the error message for empty data-tally-attribute attributes to...

Improved the error message for empty data-tally-attribute attributes to include the outerHTML of the element in question (to aid users in debugging).
parent 30d020ed
......@@ -364,7 +364,7 @@ tally = (root, obj) ->
# console.log('Attr: >' + attr + '<')
if attr == ''
throw new Error('empty data-tally-attribute definition on node ' + node)
throw new Error('empty data-tally-attribute definition on element: ' + node.outerHTML)
name = undefined
value = undefined
......@@ -379,8 +379,7 @@ tally = (root, obj) ->
throw new Error('missing attribute name for attribute ' + i)
if not attr[1]
console.log('>'+ attr + '<')
throw new Error('missing attribute value for attribute' + i)
throw new Error('missing attribute value for attribute ' + i)
value = resolve(obj, attr[1])
value = "" if value is `undefined`
......@@ -407,7 +406,7 @@ tally = (root, obj) ->
# Try and catch any empty data-tally-attribute attributes to help the user debug.
if node.hasAttribute
if node.hasAttribute(qattr)
throw new Error('empty data-tally-attribute definition on node ' + node)
throw new Error('empty data-tally-attribute definition on element: ' + node.outerHTML)
# Sets the innerHTML on the node.
# e.g., <div data-tally-text='html item.description'>
......
......@@ -303,7 +303,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
if (attr) {
attr = attr.trim();
if (attr === '') {
throw new Error('empty data-tally-attribute definition on node ' + node);
throw new Error('empty data-tally-attribute definition on element: ' + node.outerHTML);
}
name = void 0;
value = void 0;
......@@ -316,8 +316,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
throw new Error('missing attribute name for attribute ' + i);
}
if (!attr[1]) {
console.log('>' + attr + '<');
throw new Error('missing attribute value for attribute' + i);
throw new Error('missing attribute value for attribute ' + i);
}
value = resolve(obj, attr[1]);
if (value === undefined) {
......@@ -359,7 +358,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
} else {
if (node.hasAttribute) {
if (node.hasAttribute(qattr)) {
throw new Error('empty data-tally-attribute definition on node ' + node);
throw new Error('empty data-tally-attribute definition on element: ' + node.outerHTML);
}
}
}
......
{
"name": "tally",
"description": "Tally is a simple, unobtrusive JavaScript template engine for Express/Node and browser.",
"version": "0.0.1-40",
"version": "0.0.1-41",
"author": "Aral Balkan <aral@aralbalkan.com>",
"repository": {
"type": "git",
......
......@@ -57,19 +57,35 @@ describe 'Tally', ->
tally('<html><p data-tally-if="operand isLessThanny 2"></p></html>', {operand: 1})).should.throw('[ P ]')
#
# data-tally-attribute error checking tests.
# Error checking tests for data-tally-attribute.
#
it 'should not fail if a single attribute ends with a semi-colon', ->
(->
tally('<html><p data-tally-attribute="href theURL;"></p></html>', {theURL: 'http://aralbalkan.com'})).should.not.throw()
it 'should not fail if multiple attributes ends with a semi-colon', ->
(->
tally('<html><p data-tally-attribute="href theURL; class theClass;"></p></html>', {theURL: 'http://aralbalkan.com', theClass: 'classy'})).should.not.throw()
it 'should fail if an attribute just has a semi‐colon in it', ->
(->
tally('<html><p data-tally-attribute=";"></p></html>', {})).should.throw('missing attribute value for attribute 0')
it 'should fail if an attribute just multiple semi‐colons in it', ->
(->
tally('<html><p data-tally-attribute=";;"></p></html>', {})).should.throw('missing attribute value for attribute 0')
it 'should fail if an attribute just multiple semi‐colons with spaces between them in it', ->
(->
tally('<html><p data-tally-attribute="; ;"></p></html>', {})).should.throw('missing attribute name for attribute 1')
it 'should fail when data-tally-attribute is empty', ->
(->
tally('<html><p data-tally-attribute=""></p></html>', {theURL: 'http://aralbalkan.com'})).should.throw('empty data-tally-attribute definition on node [ P ]')
tally('<html><p data-tally-attribute=""></p></html>', {theURL: 'http://aralbalkan.com'})).should.throw('empty data-tally-attribute definition on element: <p data-tally-attribute=""></p>')
it 'should fail when data-tally-attribute is just whitespace', ->
(->
tally('<html><p data-tally-attribute=" "></p></html>', {theURL: 'http://aralbalkan.com'})).should.throw('empty data-tally-attribute definition on node [ P ]')
tally('<html><p data-tally-attribute=" "></p></html>', {theURL: 'http://aralbalkan.com'})).should.throw('empty data-tally-attribute definition on element: <p data-tally-attribute=" "></p>')
it 'should not fail when there is whitespace at ends of a data-tally-attribute attribute.', ->
(->
......
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