Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow whitespace within tags

  • Loading branch information...
commit ea08d1838adc72669c669920bda126d7a1f89b1b 1 parent 019aa4d
@rvagg rvagg authored
View
3  .gitignore
@@ -1 +1,2 @@
-node_modules
+node_modules
+test/
View
16 Cakefile
@@ -20,15 +20,15 @@ task 'test', 'Build and run the test suite', ->
'ln -sf ../src/test/index.html test',
'ln -sf ../src/test/vows.css test',
- 'npm install .',
- 'npm install --dev',
- 'ln -sfh ender-vows node_modules/vows',
+ 'npm install',
+ 'rm -f node_modules/wings node_modules/vows test/node_modules',
+ 'ln -sf ender-vows node_modules/vows',
- 'pushd test',
- 'ln -sfh ../node_modules node_modules',
- 'ln -sfh .. node_modules/wings',
+ 'cd test',
+ 'ln -sf ../node_modules node_modules',
+ 'ln -sf .. node_modules/wings',
#'node_modules/.bin/ender build ender-vows ..',
'node_modules/.bin/vows *-test.js',
- 'unlink node_modules/wings',
- 'popd test',
+ 'rm -f node_modules/wings node_modules/vows node_modules',
+ 'cd ..',
]
View
1  lib/ender.js
@@ -1,4 +1,3 @@
-// Generated by CoffeeScript 1.3.1
(function($) {
var renderTemplate;
View
7 lib/wings.js
@@ -1,4 +1,3 @@
-// Generated by CoffeeScript 1.3.1
(function(wings) {
var escapeXML, isArray, parsePattern, renderRawTemplate, replaceBraces, restoreBraces;
@@ -35,10 +34,10 @@
}
});
};
- parsePattern = /\{([:!])\s*([^}]*?)\s*\}([\S\s]+?)\s*\{\/\s*\2\}|\{(\#)[\S\s]+?\#\}|\{([@&]?)\s*([^}]*?)\s*\}/mg;
+ parsePattern = /\{([:!])\s*([^}\s]*?)\s*\}([\S\s]+?)\{\/\s*\2\s*\}|\{(\#)[\S\s]+?\#\}|\{([@&]?)\s*([^}\s]*?)\s*\}/mg;
return renderRawTemplate = function(template, data, links) {
return template.replace(parsePattern, function(all, sectionOp, sectionName, sectionContent, commentOp, tagOp, tagName) {
- var content, i, link, name, op, part, parts, rest, v, value, _i, _len, _ref;
+ var content, i, link, name, op, part, parts, rest, v, value, _len, _ref;
op = sectionOp || commentOp || tagOp;
name = sectionName || tagName;
content = sectionContent;
@@ -53,7 +52,7 @@
}
} else if (isArray(value)) {
parts = [];
- for (i = _i = 0, _len = value.length; _i < _len; i = ++_i) {
+ for (i = 0, _len = value.length; i < _len; i++) {
v = value[i];
v['#'] = i;
parts.push(renderRawTemplate(content, v, links));
View
56 src/test/wings-test.coffee
@@ -77,6 +77,20 @@ vows.add 'templates'
'should produce html': (topic) ->
equal topic, 'This should produce html: <b>bolded</b>'
+ 'a template with unescaped tags (whitespace in tag)':
+ topic: [
+ t('This should produce html: {& html }', {html: '<b>bolded</b>'}),
+ t('This should produce html: {& html}', {html: '<b>bolded</b>'}),
+ t('This should produce html: {&html }', {html: '<b>bolded</b>'}),
+ t('This should produce html: {& \thtml \t\t}', {html: '<b>bolded</b>'}),
+ ]
+
+ 'should produce html': (topics) ->
+ equal topics[0], 'This should produce html: <b>bolded</b>'
+ equal topics[1], 'This should produce html: <b>bolded</b>'
+ equal topics[2], 'This should produce html: <b>bolded</b>'
+ equal topics[3], 'This should produce html: <b>bolded</b>'
+
'a template with tags having the value 0':
topic: t('This is a zero: {zero}', {zero: 0})
@@ -91,6 +105,20 @@ vows.add 'templates'
'should follow the link': (topic) ->
equal topic, 'baz'
+ 'a template with a normal link (whitespace in tag)':
+ topic: [
+ t('{@ foo }', {bar: '1baz'}, {foo:'{ bar }'})
+ t('{@ foo}', {bar: '2baz'}, {foo:'{bar }'}),
+ t('{@foo }', {bar: '3baz'}, {foo:'{bar }'}),
+ t('{@ \tfoo\t\t}', {bar: '4baz'}, {foo:'{\tbar\t }'}),
+ ]
+
+ 'should produce html': (topics) ->
+ equal topics[0], '1baz'
+ equal topics[1], '2baz'
+ equal topics[2], '3baz'
+ equal topics[3], '4baz'
+
'a template with a function link':
topic: t('{@foo}', {bar: 'baz'}, {foo: () -> '{bar}'})
@@ -118,6 +146,20 @@ vows.add 'templates'
equal topics[4], 'foobar'
equal topics[5], 'foobar'
+ 'templates with regular sections (whitespace in tags)':
+ topic: [
+ t('{: falsy }foo{/falsy}1{: truthy }bang{/truthy }', {falsy: 0, truthy: 1}),
+ t('{: falsy}foo{/ falsy}2{: truthy }bang{/truthy }', {falsy: 0, truthy: 1}),
+ t('{:falsy}foo{/ falsy }3{: truthy }bang{/ truthy }', {falsy: 0, truthy: 1}),
+ t('{:\tfalsy\t}foo{/falsy}4{:\ttruthy\t}bang{/\ttruthy\t}', {falsy: 0, truthy: 1})
+ ]
+
+ 'should only include the section when the tag is truthy': (topics) ->
+ equal topics[0], '1bang'
+ equal topics[1], '2bang'
+ equal topics[2], '3bang'
+ equal topics[3], '4bang'
+
'templates with inverse sections':
topic: [
t('{!falsy}foo{/falsy}bar', {falsy: 0}),
@@ -137,6 +179,20 @@ vows.add 'templates'
equal topics[4], 'bar'
equal topics[5], 'bar'
+ 'templates with inverse sections (whitespace in tags)':
+ topic: [
+ t('{! falsy }foo{/falsy}1{! truthy }bang{/truthy }', {falsy: 0, truthy: 1}),
+ t('{! falsy}foo{/ falsy}2{! truthy }bang{/truthy }', {falsy: 0, truthy: 1}),
+ t('{!falsy}foo{/ falsy }3{! truthy }bang{/ truthy }', {falsy: 0, truthy: 1}),
+ t('{!\tfalsy\t}foo{/falsy}4{!\ttruthy\t}bang{/\ttruthy\t}', {falsy: 0, truthy: 1})
+ ]
+
+ 'should only include the section when the tag is not truthy': (topics) ->
+ equal topics[0], 'foo1'
+ equal topics[1], 'foo2'
+ equal topics[2], 'foo3'
+ equal topics[3], 'foo4'
+
'templates with array sections':
topic: [
t('{:array}foo{/array}bar', {array: [1, 2, 3]}),
View
4 src/wings/wings.coffee
@@ -24,9 +24,9 @@
else return s
parsePattern = ///
- \{([:!]) \s* ([^}]*?) \s* \} ([\S\s]+?) \s* \{/ \s* \2 \} | # sections
+ \{([:!]) \s* ([^}\s]*?) \s* \} ([\S\s]+?) \{/ \s* \2 \s* \} | # sections
\{(\#) [\S\s]+? \#\} | # comments
- \{([@&]?) \s* ([^}]*?) \s* \} # tags
+ \{([@&]?) \s* ([^}\s]*?) \s* \} # tags
///mg
renderRawTemplate = (template, data, links) ->
Please sign in to comment.
Something went wrong with that request. Please try again.