Fixes for blocks and filters #8

Merged
merged 2 commits into from Aug 16, 2011
Jump to file or symbol
Failed to load files and symbols.
+50 −13
Split
View
@@ -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
@@ -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
@@ -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
@@ -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();
+};