Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes for blocks and filters #8

Merged
merged 2 commits into from

2 participants

@paularmstrong

Commits explain this pretty well :-)

paularmstrong added some commits
@paularmstrong paularmstrong Fixing a bug where not defining a block in a template would cause it …
…to use the last block of the same name that was merged into the parent template (extends template). Added in helper clone method and tests.
17d5b28
@paularmstrong paularmstrong make sure to escape filter params and do proper splitting of those pa…
…rams
1d88723
@skid skid merged commit ee5faab into skid:master
@sufianrhazi sufianrhazi referenced this pull request from a commit in sufianrhazi/swig
@paularmstrong paularmstrong `extends` throws for circular extends. closes gh-8 390738c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2011
  1. @paularmstrong

    Fixing a bug where not defining a block in a template would cause it …

    paularmstrong authored
    …to use the last block of the same name that was merged into the parent template (extends template). Added in helper clone method and tests.
Commits on Aug 16, 2011
  1. @paularmstrong
This page is out of date. Refresh to see the latest.
View
12 lib/filters.js
@@ -3,15 +3,15 @@ var helpers = require('./helpers'),
_dateFormats;
_dateFormats = {
- _months: {
- full: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
- abbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
- },
- _days: {
+ _months: {
+ full: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
+ abbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
+ },
+ _days: {
full: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
abbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
alt: {'-1': 'Yesterday', 0: 'Today', 1: 'Tomorrow'}
- },
+ },
// Day
d: function (input) {
return (input.getDate() < 10 ? '0' : '') + input.getDate();
View
22 lib/helpers.js
@@ -125,21 +125,37 @@ exports.escape = function (variable, context) {
return chain.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
};
+exports.clone = function (obj) {
+ var clone = {},
+ key;
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ if (typeof(obj[key]) === "object") {
+ clone[key] = exports.clone(obj[key]);
+ } else {
+ clone[key] = obj[key];
+ }
+ }
+ }
+ return clone;
+};
+
/**
* Merges b into a and returns a
*/
exports.merge = function (a, b) {
- var key;
+ var key, temp = null;
if (a && b) {
+ temp = exports.clone(a);
for (key in b) {
if (b.hasOwnProperty(key)) {
- a[key] = b[key];
+ temp[key] = b[key];
}
}
}
- return a;
+ return temp;
};
exports.isLiteral = isLiteral;
View
8 lib/parser.js
@@ -43,7 +43,7 @@ exports.parse = function (data, tags) {
part = parts[part];
filter_name = part.match(/^\w+/);
if (/\(/.test(part)) {
- filters.push({ name: filter_name[0], args: part.replace(/^\w+\(|\'|\"|,|\)$/g, '').split(' ') });
+ filters.push({ name: filter_name[0], args: part.replace(/^\w+\(|\'|\"|\)$/g, '').split(',') });
} else {
filters.push({ name: filter_name[0], args: [] });
}
@@ -101,9 +101,9 @@ function wrapFilter(variable, filter) {
if (filters.hasOwnProperty(filter.name)) {
args = [variable];
- if (filter.args.length) {
- args.push(filters.args);
- }
+ filter.args.forEach(function (f) {
+ args.push('\'' + f + '\'');
+ });
output = '__filters.' + filter.name + '.apply(this, [' + args.toString() + '])';
}
View
21 tests/helpers.test.js
@@ -0,0 +1,21 @@
+var helpers = require('../lib/helpers');
+
+exports.clone = function (test) {
+ var obj = { foo: 1, bar: 2, baz: { bop: 3 } },
+ out = helpers.clone(obj);
+
+ test.deepEqual(out, { foo: 1, bar: 2, baz: { bop: 3 } });
+ test.done();
+};
+
+exports.merge = function (test) {
+ var a = { foo: 1, bar: 2 },
+ b = { foo: 2 },
+ out;
+
+ out = helpers.merge(a, b);
+ test.deepEqual(out, { foo: 2, bar: 2 }, 'returns merged object');
+ test.deepEqual(a, { foo: 1, bar: 2 }, 'does not overwrite original object');
+
+ test.done();
+};
Something went wrong with that request. Please try again.