Use ~ rather than () for whitespace control.

This commit is contained in:
kpdecker
2013-10-14 11:11:24 -05:00
parent c776f171ab
commit 31f7c25a8f
3 changed files with 30 additions and 30 deletions
+24 -24
View File
@@ -2,61 +2,61 @@ describe('whitespace control', function() {
it('should strip whitespace around mustache calls', function() {
var hash = {foo: 'bar<'};
shouldCompileTo(' {{(foo)}} ', hash, 'bar&lt;');
shouldCompileTo(' {{(foo}} ', hash, 'bar&lt; ');
shouldCompileTo(' {{foo)}} ', hash, ' bar&lt;');
shouldCompileTo(' {{~foo~}} ', hash, 'bar&lt;');
shouldCompileTo(' {{~foo}} ', hash, 'bar&lt; ');
shouldCompileTo(' {{foo~}} ', hash, ' bar&lt;');
shouldCompileTo(' {{(&foo)}} ', hash, 'bar<');
shouldCompileTo(' {{({foo})}} ', hash, 'bar<');
shouldCompileTo(' {{~&foo~}} ', hash, 'bar<');
shouldCompileTo(' {{~{foo}~}} ', hash, 'bar<');
});
describe('blocks', function() {
it('should strip whitespace around simple block calls', function() {
var hash = {foo: 'bar<'};
shouldCompileTo(' {{(#if foo)}} bar {{(/if)}} ', hash, 'bar');
shouldCompileTo(' {{#if foo)}} bar {{/if)}} ', hash, ' bar ');
shouldCompileTo(' {{(#if foo}} bar {{(/if}} ', hash, ' bar ');
shouldCompileTo(' {{~#if foo~}} bar {{~/if~}} ', hash, 'bar');
shouldCompileTo(' {{#if foo~}} bar {{/if~}} ', hash, ' bar ');
shouldCompileTo(' {{~#if foo}} bar {{~/if}} ', hash, ' bar ');
shouldCompileTo(' {{#if foo}} bar {{/if}} ', hash, ' bar ');
});
it('should strip whitespace around inverse block calls', function() {
var hash = {};
shouldCompileTo(' {{(^if foo)}} bar {{(/if)}} ', hash, 'bar');
shouldCompileTo(' {{^if foo)}} bar {{/if)}} ', hash, ' bar ');
shouldCompileTo(' {{(^if foo}} bar {{(/if}} ', hash, ' bar ');
shouldCompileTo(' {{~^if foo~}} bar {{~/if~}} ', hash, 'bar');
shouldCompileTo(' {{^if foo~}} bar {{/if~}} ', hash, ' bar ');
shouldCompileTo(' {{~^if foo}} bar {{~/if}} ', hash, ' bar ');
shouldCompileTo(' {{^if foo}} bar {{/if}} ', hash, ' bar ');
});
it('should strip whitespace around complex block calls', function() {
var hash = {foo: 'bar<'};
shouldCompileTo('{{#if foo)}} bar {{(^)}} baz {{(/if}}', hash, 'bar');
shouldCompileTo('{{#if foo)}} bar {{^)}} baz {{/if}}', hash, 'bar ');
shouldCompileTo('{{#if foo}} bar {{(^)}} baz {{(/if}}', hash, ' bar');
shouldCompileTo('{{#if foo}} bar {{^)}} baz {{/if}}', hash, ' bar ');
shouldCompileTo('{{#if foo~}} bar {{~^~}} baz {{~/if}}', hash, 'bar');
shouldCompileTo('{{#if foo~}} bar {{^~}} baz {{/if}}', hash, 'bar ');
shouldCompileTo('{{#if foo}} bar {{~^~}} baz {{~/if}}', hash, ' bar');
shouldCompileTo('{{#if foo}} bar {{^~}} baz {{/if}}', hash, ' bar ');
shouldCompileTo('{{#if foo)}} bar {{(else)}} baz {{(/if}}', hash, 'bar');
shouldCompileTo('{{#if foo~}} bar {{~else~}} baz {{~/if}}', hash, 'bar');
hash = {};
shouldCompileTo('{{#if foo)}} bar {{(^)}} baz {{(/if}}', hash, 'baz');
shouldCompileTo('{{#if foo}} bar {{(^)}} baz {{/if}}', hash, 'baz ');
shouldCompileTo('{{#if foo)}} bar {{(^}} baz {{(/if}}', hash, ' baz');
shouldCompileTo('{{#if foo)}} bar {{(^}} baz {{/if}}', hash, ' baz ');
shouldCompileTo('{{#if foo~}} bar {{~^~}} baz {{~/if}}', hash, 'baz');
shouldCompileTo('{{#if foo}} bar {{~^~}} baz {{/if}}', hash, 'baz ');
shouldCompileTo('{{#if foo~}} bar {{~^}} baz {{~/if}}', hash, ' baz');
shouldCompileTo('{{#if foo~}} bar {{~^}} baz {{/if}}', hash, ' baz ');
shouldCompileTo('{{#if foo)}} bar {{(else)}} baz {{(/if}}', hash, 'baz');
shouldCompileTo('{{#if foo~}} bar {{~else~}} baz {{~/if}}', hash, 'baz');
});
});
it('should strip whitespace around partials', function() {
shouldCompileToWithPartials('foo {{(> dude)}} ', [{}, {}, {dude: 'bar'}], true, 'foobar');
shouldCompileToWithPartials('foo {{> dude)}} ', [{}, {}, {dude: 'bar'}], true, 'foo bar');
shouldCompileToWithPartials('foo {{~> dude~}} ', [{}, {}, {dude: 'bar'}], true, 'foobar');
shouldCompileToWithPartials('foo {{> dude~}} ', [{}, {}, {dude: 'bar'}], true, 'foo bar');
shouldCompileToWithPartials('foo {{> dude}} ', [{}, {}, {dude: 'bar'}], true, 'foo bar ');
});
it('should only strip whitespace once', function() {
var hash = {foo: 'bar'};
shouldCompileTo(' {{(foo)}} {{foo}} {{foo}} ', hash, 'barbar bar ');
shouldCompileTo(' {{~foo~}} {{foo}} {{foo}} ', hash, 'barbar bar ');
});
});
+4 -4
View File
@@ -9,11 +9,11 @@ function strip(start, end) {
%}
LEFT_STRIP "("
RIGHT_STRIP ")"
LEFT_STRIP "~"
RIGHT_STRIP "~"
LOOKAHEAD [=)}\s\/.]
LITERAL_LOOKAHEAD [)}\s]
LOOKAHEAD [=~}\s\/.]
LITERAL_LOOKAHEAD [~}\s]
/*
ID is the inverse of control characters.
+2 -2
View File
@@ -6,8 +6,8 @@
function stripFlags(open, close) {
return {
left: open[2] === '(',
right: close[0] === ')' || close[1] === ')'
left: open[2] === '~',
right: close[0] === '~' || close[1] === '~'
};
}