Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Introducing the escape character, as discussed in #427
Browse files Browse the repository at this point in the history
  • Loading branch information
ecaron committed Mar 5, 2014
1 parent 87bc42b commit 33be4ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ exports.date = function (input, format, offset, abbr) {

for (i; i < l; i += 1) {
cur = format.charAt(i);
if (dateFormatter.hasOwnProperty(cur)) {
if (cur === '\\') {
i += 1;
out += (i < l) ? format.charAt(i) : cur;
} else if (dateFormatter.hasOwnProperty(cur)) {
out += dateFormatter[cur](date, offset, abbr);
} else {
out += cur;
Expand Down
7 changes: 6 additions & 1 deletion tests/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ var n = new Swig(),
{ c: 'v|date("S")', v: makeDate(420, 2011, 8, 13), e: 'th' },
{ c: 'v|date("S")', v: makeDate(420, 2011, 8, 21), e: 'st' },
{ c: 'v|date("S")', v: makeDate(420, 2011, 8, 22), e: 'nd' },
{ c: 'v|date("S")', v: makeDate(420, 2011, 8, 23), e: 'rd' }
{ c: 'v|date("S")', v: makeDate(420, 2011, 8, 23), e: 'rd' },

// Week
{ c: 'v|date("\\D")', v: d, e: 'D' },
{ c: 'v|date("\\t\\e\\s\\t")', v: d, e: 'test' },
{ c: 'v|date("\\\\D")', v: d, e: '\\Tue' }
],
'default': [
{ c: 'v|default("tacos")', v: 'foo', e: 'foo' },
Expand Down

0 comments on commit 33be4ef

Please sign in to comment.