This commit is contained in:
harttle
2017-12-08 00:25:44 +08:00
parent a4126e7f10
commit 49cb7a8c36
3 changed files with 14 additions and 5 deletions
+12 -3
View File
@@ -37,8 +37,13 @@ var filters = {
return Array.prototype.concat.call(v, arg);
},
'date': function date(v, arg) {
if (v === 'now') v = new Date();
return v instanceof Date ? strftime(v, arg) : '';
var date = v;
if (v === 'now') {
date = new Date();
} else if (_.isString(v)) {
date = new Date(v);
}
return isValidDate(date) ? strftime(date, arg) : v;
},
'default': function _default(v, arg) {
return isTruthy(v) ? v : arg;
@@ -203,6 +208,10 @@ function registerAll(liquid) {
});
}
function isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime());
}
registerAll.filters = filters;
module.exports = registerAll;
@@ -921,7 +930,7 @@ var Scope = {
},
get: function get(str) {
if (str === 'liquid') {
throw new Error('NO LONGER SUPPORTED: use scope.opts instread of scope.get("liquid")');
throw new Error('NO LONGER SUPPORTED: use scope.opts instead of scope.get("liquid")');
}
try {
return this.getPropertyByPath(this.scopes, str);
+1 -1
View File
File diff suppressed because one or more lines are too long