1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

updated bunch of file paths and changed the way posts are loaded

This commit is contained in:
2016-01-05 12:28:04 -06:00
parent 4bb8cae81e
commit 6ab45fe935
13249 changed files with 317868 additions and 2101398 deletions

View File

@@ -3,11 +3,11 @@
* Module dependencies.
*/
var SchemaType = require('../schematype')
, CastError = SchemaType.CastError
, errorMessages = require('../error').messages
, utils = require('../utils')
, Document
var SchemaType = require('../schematype');
var CastError = SchemaType.CastError;
var errorMessages = require('../error').messages;
var utils = require('../utils');
var Document;
/**
* String SchemaType constructor.
@@ -18,11 +18,11 @@ var SchemaType = require('../schematype')
* @api private
*/
function SchemaString (key, options) {
function SchemaString(key, options) {
this.enumValues = [];
this.regExp = null;
SchemaType.call(this, key, options, 'String');
};
}
/**
* This schema type's name, to defend against minifiers that mangle
@@ -73,7 +73,7 @@ SchemaString.prototype.constructor = SchemaString;
* @api public
*/
SchemaString.prototype.enum = function () {
SchemaString.prototype.enum = function() {
if (this.enumValidator) {
this.validators = this.validators.filter(function(v) {
return v.validator != this.enumValidator;
@@ -103,13 +103,14 @@ SchemaString.prototype.enum = function () {
}
var vals = this.enumValues;
this.enumValidator = function (v) {
this.enumValidator = function(v) {
return undefined === v || ~vals.indexOf(v);
};
this.validators.push({
validator: this.enumValidator,
message: errorMessage,
type: 'enum'
type: 'enum',
enumValues: vals
});
return this;
@@ -129,9 +130,9 @@ SchemaString.prototype.enum = function () {
* @return {SchemaType} this
*/
SchemaString.prototype.lowercase = function () {
return this.set(function (v, self) {
if ('string' != typeof v) v = self.cast(v)
SchemaString.prototype.lowercase = function() {
return this.set(function(v, self) {
if ('string' != typeof v) v = self.cast(v);
if (v) return v.toLowerCase();
return v;
});
@@ -151,9 +152,9 @@ SchemaString.prototype.lowercase = function () {
* @return {SchemaType} this
*/
SchemaString.prototype.uppercase = function () {
return this.set(function (v, self) {
if ('string' != typeof v) v = self.cast(v)
SchemaString.prototype.uppercase = function() {
return this.set(function(v, self) {
if ('string' != typeof v) v = self.cast(v);
if (v) return v.toUpperCase();
return v;
});
@@ -177,9 +178,9 @@ SchemaString.prototype.uppercase = function () {
* @return {SchemaType} this
*/
SchemaString.prototype.trim = function () {
return this.set(function (v, self) {
if ('string' != typeof v) v = self.cast(v)
SchemaString.prototype.trim = function() {
return this.set(function(v, self) {
if ('string' != typeof v) v = self.cast(v);
if (v) return v.trim();
return v;
});
@@ -200,12 +201,12 @@ SchemaString.prototype.trim = function () {
* })
*
* // custom error messages
* // We can also use the special {MINLENGTH} token which will be replaced with the invalid value
* var minlength = [10, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum length ({MINLENGTH}).'];
* // We can also use the special {MINLENGTH} token which will be replaced with the minimum allowed length
* var minlength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
* var schema = new Schema({ postalCode: { type: String, minlength: minlength })
* var Address = mongoose.model('Address', schema);
* var address = new Address({ postalCode: '9512' });
* s.validate(function (err) {
* address.validate(function (err) {
* console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512`) is shorter than the minimum length (5).
* })
*
@@ -216,9 +217,9 @@ SchemaString.prototype.trim = function () {
* @api public
*/
SchemaString.prototype.minlength = function (value, message) {
SchemaString.prototype.minlength = function(value, message) {
if (this.minlengthValidator) {
this.validators = this.validators.filter(function (v) {
this.validators = this.validators.filter(function(v) {
return v.validator != this.minlengthValidator;
}, this);
}
@@ -227,11 +228,12 @@ SchemaString.prototype.minlength = function (value, message) {
var msg = message || errorMessages.String.minlength;
msg = msg.replace(/{MINLENGTH}/, value);
this.validators.push({
validator: this.minlengthValidator = function (v) {
validator: this.minlengthValidator = function(v) {
return v === null || v.length >= value;
},
message: msg,
type: 'minlength'
type: 'minlength',
minlength: value
});
}
@@ -253,13 +255,13 @@ SchemaString.prototype.minlength = function (value, message) {
* })
*
* // custom error messages
* // We can also use the special {MAXLENGTH} token which will be replaced with the invalid value
* var maxlength = [10, 'The value of path `{PATH}` (`{VALUE}`) exceeds the maximum allowed length ({MAXLENGTH}).'];
* // We can also use the special {MAXLENGTH} token which will be replaced with the maximum allowed length
* var maxlength = [9, 'The value of path `{PATH}` (`{VALUE}`) exceeds the maximum allowed length ({MAXLENGTH}).'];
* var schema = new Schema({ postalCode: { type: String, maxlength: maxlength })
* var Address = mongoose.model('Address', schema);
* var address = new Address({ postalCode: '9512512345' });
* address.validate(function (err) {
* console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512512345`) exceeds the maximum allowed length (10).
* console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512512345`) exceeds the maximum allowed length (9).
* })
*
* @param {Number} value maximum string length
@@ -269,9 +271,9 @@ SchemaString.prototype.minlength = function (value, message) {
* @api public
*/
SchemaString.prototype.maxlength = function (value, message) {
SchemaString.prototype.maxlength = function(value, message) {
if (this.maxlengthValidator) {
this.validators = this.validators.filter(function(v){
this.validators = this.validators.filter(function(v) {
return v.validator != this.maxlengthValidator;
}, this);
}
@@ -284,7 +286,8 @@ SchemaString.prototype.maxlength = function (value, message) {
return v === null || v.length <= value;
},
message: msg,
type: 'maxlength'
type: 'maxlength',
maxlength: value
});
}
@@ -329,19 +332,28 @@ SchemaString.prototype.maxlength = function (value, message) {
* @api public
*/
SchemaString.prototype.match = function match (regExp, message) {
SchemaString.prototype.match = function match(regExp, message) {
// yes, we allow multiple match validators
var msg = message || errorMessages.String.match;
var matchValidator = function(v) {
if (!regExp) {
return false;
}
var ret = ((null != v && '' !== v)
? regExp.test(v)
: true);
return ret;
};
this.validators.push({ validator: matchValidator, message: msg, type: 'regexp' });
this.validators.push({
validator: matchValidator,
message: msg,
type: 'regexp',
regexp: regExp
});
return this;
};
@@ -352,7 +364,7 @@ SchemaString.prototype.match = function match (regExp, message) {
* @api private
*/
SchemaString.prototype.checkRequired = function checkRequired (value, doc) {
SchemaString.prototype.checkRequired = function checkRequired(value, doc) {
if (SchemaType._isRef(this, value, doc, true)) {
return null != value;
} else {
@@ -366,7 +378,7 @@ SchemaString.prototype.checkRequired = function checkRequired (value, doc) {
* @api private
*/
SchemaString.prototype.cast = function (value, doc, init) {
SchemaString.prototype.cast = function(value, doc, init) {
if (SchemaType._isRef(this, value, doc, init)) {
// wait! we may need to cast this to a document
@@ -426,13 +438,16 @@ SchemaString.prototype.cast = function (value, doc, init) {
* ignore
*/
function handleSingle (val) {
function handleSingle(val) {
return this.castForQuery(val);
}
function handleArray (val) {
function handleArray(val) {
var self = this;
return val.map(function (m) {
if (!Array.isArray(val)) {
return [this.castForQuery(val)];
}
return val.map(function(m) {
return self.castForQuery(m);
});
}
@@ -442,11 +457,8 @@ SchemaString.prototype.$conditionalHandlers =
'$all': handleArray,
'$gt' : handleSingle,
'$gte': handleSingle,
'$in' : handleArray,
'$lt' : handleSingle,
'$lte': handleSingle,
'$ne' : handleSingle,
'$nin': handleArray,
'$options': handleSingle,
'$regex': handleSingle
});
@@ -459,7 +471,7 @@ SchemaString.prototype.$conditionalHandlers =
* @api private
*/
SchemaString.prototype.castForQuery = function ($conditional, val) {
SchemaString.prototype.castForQuery = function($conditional, val) {
var handler;
if (arguments.length === 2) {
handler = this.$conditionalHandlers[$conditional];
@@ -468,7 +480,9 @@ SchemaString.prototype.castForQuery = function ($conditional, val) {
return handler.call(this, val);
} else {
val = $conditional;
if (val instanceof RegExp) return val;
if (Object.prototype.toString.call(val) === '[object RegExp]') {
return val;
}
return this.cast(val);
}
};