diff --git a/fields/types/Type.js b/fields/types/Type.js
index ae465bed29..485382b290 100644
--- a/fields/types/Type.js
+++ b/fields/types/Type.js
@@ -24,7 +24,7 @@ var DEFAULT_OPTION_KEYS = [
'indent',
'hidden',
'collapse',
- 'dependsOn'
+ 'dependsOn',
];
/**
@@ -75,7 +75,7 @@ function Field(list, path, options) {
Object.defineProperty(this, 'note', {
get: function() {
return (note === null) ? (note = (this.options.note) ? marked(this.options.note) : '') : note;
- }
+ },
});
}
diff --git a/fields/types/password/PasswordFilter.js b/fields/types/password/PasswordFilter.js
index f7efdd722d..47b0fcfcdd 100644
--- a/fields/types/password/PasswordFilter.js
+++ b/fields/types/password/PasswordFilter.js
@@ -22,7 +22,7 @@ var PasswordFilter = React.createClass({
propTypes: {
filter: React.PropTypes.shape({
exists: React.PropTypes.oneOf(TOGGLE_OPTIONS.map(i => i.value)),
- })
+ }),
},
getDefaultProps () {
@@ -38,7 +38,7 @@ var PasswordFilter = React.createClass({
render () {
const { field, filter } = this.props;
return ;
- }
+ },
});
diff --git a/fields/types/password/PasswordType.js b/fields/types/password/PasswordType.js
index e33bb32113..5cdf019230 100644
--- a/fields/types/password/PasswordType.js
+++ b/fields/types/password/PasswordType.js
@@ -34,7 +34,7 @@ password.prototype.addToSchema = function() {
this.paths = {
hash: this.options.hashPath || this._path.append('_hash'),
- confirm: this.options.confirmPath || this._path.append('_confirm')
+ confirm: this.options.confirmPath || this._path.append('_confirm'),
};
schema.path(this.path, _.defaults({
@@ -42,7 +42,7 @@ password.prototype.addToSchema = function() {
set: function(newValue) {
this[needs_hashing] = true;
return newValue;
- }
+ },
}, this.options));
schema.virtual(this.paths.hash).set(function(newValue) {
diff --git a/fields/types/relationship/RelationshipColumn.js b/fields/types/relationship/RelationshipColumn.js
index 986bbf5cbb..16eaa6d0e7 100644
--- a/fields/types/relationship/RelationshipColumn.js
+++ b/fields/types/relationship/RelationshipColumn.js
@@ -56,7 +56,7 @@ var RelationshipColumn = React.createClass({
{many ? this.renderMany(value) : this.renderValue(value)}
);
- }
+ },
});
module.exports = RelationshipColumn;
diff --git a/fields/types/relationship/RelationshipField.js b/fields/types/relationship/RelationshipField.js
index 1f9a391b06..6196ea1085 100644
--- a/fields/types/relationship/RelationshipField.js
+++ b/fields/types/relationship/RelationshipField.js
@@ -169,7 +169,7 @@ module.exports = Field.create({
// NOTE: this seems like the wrong way to add options to the Select
this.loadOptionsCallback(null, {
complete: true,
- options: Object.keys(this._itemsCache).map((k) => this._itemsCache[k])
+ options: Object.keys(this._itemsCache).map((k) => this._itemsCache[k]),
});
this.toggleCreate(false);
},
@@ -223,6 +223,6 @@ module.exports = Field.create({
} else {
return this.renderSelect();
}
- }
+ },
});
diff --git a/fields/types/select/SelectColumn.js b/fields/types/select/SelectColumn.js
index 9c1d9da395..0807c6f3b4 100644
--- a/fields/types/select/SelectColumn.js
+++ b/fields/types/select/SelectColumn.js
@@ -22,7 +22,7 @@ var SelectColumn = React.createClass({
);
- }
+ },
});
module.exports = SelectColumn;
diff --git a/fields/types/select/SelectField.js b/fields/types/select/SelectField.js
index 5819bd862c..3e0f0c015d 100644
--- a/fields/types/select/SelectField.js
+++ b/fields/types/select/SelectField.js
@@ -19,7 +19,7 @@ module.exports = Field.create({
}
this.props.onChange({
path: this.props.path,
- value: newValue
+ value: newValue,
});
},
@@ -33,6 +33,6 @@ module.exports = Field.create({
var ops = (this.props.numeric) ? this.props.ops.map(function(i) { return { label: i.label, value: String(i.value) }; }) : this.props.ops;
var value = ('number' === typeof this.props.value) ? String(this.props.value) : this.props.value;
return ;
- }
+ },
});
diff --git a/fields/types/select/SelectFilter.js b/fields/types/select/SelectFilter.js
index 7e4dc3240f..d5c77e330b 100644
--- a/fields/types/select/SelectFilter.js
+++ b/fields/types/select/SelectFilter.js
@@ -4,7 +4,7 @@ import PopoutList from '../../../admin/client/components/PopoutList';
const TOGGLE_OPTIONS = [
{ label: 'Matches', value: false },
- { label: 'Does NOT Match', value: true }
+ { label: 'Does NOT Match', value: true },
];
function getDefaultValue () {
@@ -25,7 +25,7 @@ var SelectFilter = React.createClass({
filter: React.PropTypes.shape({
inverted: React.PropTypes.boolean,
value: React.PropTypes.array,
- })
+ }),
},
getDefaultProps () {
@@ -94,7 +94,7 @@ var SelectFilter = React.createClass({
{this.renderOptions()}
);
- }
+ },
});
diff --git a/fields/types/select/SelectType.js b/fields/types/select/SelectType.js
index 8cc2671020..32a6b92fbd 100644
--- a/fields/types/select/SelectType.js
+++ b/fields/types/select/SelectType.js
@@ -58,14 +58,14 @@ select.prototype.addToSchema = function() {
data: this.options.dataPath || this._path.append('Data'),
label: this.options.labelPath || this._path.append('Label'),
options: this.options.optionsPath || this._path.append('Options'),
- map: this.options.optionsMapPath || this._path.append('OptionsMap')
+ map: this.options.optionsMapPath || this._path.append('OptionsMap'),
};
schema.path(this.path, _.defaults({
type: this._nativeType,
enum: this.values,
set: function(val) {
return (val === '' || val === null || val === false) ? undefined : val;
- }
+ },
}, this.options));
schema.virtual(this.paths.data).get(function () {
return field.map[this.get(field.path)];
diff --git a/fields/types/select/test/server.js b/fields/types/select/test/server.js
index 7875d1e792..375a914099 100644
--- a/fields/types/select/test/server.js
+++ b/fields/types/select/test/server.js
@@ -5,8 +5,8 @@ exports.initList = function(List) {
List.add({
select: { type: SelectType, options: 'one, two, three' },
nested: {
- select: { type: SelectType, options: 'one, two, three' }
- }
+ select: { type: SelectType, options: 'one, two, three' },
+ },
});
};
@@ -15,7 +15,7 @@ exports.testFieldType = function(List) {
it('should update top level fields', function(done) {
List.fields.select.updateItem(testItem, {
- select: 'one'
+ select: 'one',
}, function() {
demand(testItem.select).be('one');
testItem.select = undefined;
@@ -26,8 +26,8 @@ exports.testFieldType = function(List) {
it('should update nested fields', function(done) {
List.fields['nested.select'].updateItem(testItem, {
nested: {
- select: 'one'
- }
+ select: 'one',
+ },
}, function() {
demand(testItem.nested.select).be('one');
testItem.nested.select = undefined;
@@ -37,7 +37,7 @@ exports.testFieldType = function(List) {
it('should update nested fields with flat paths', function(done) {
List.fields['nested.select'].updateItem(testItem, {
- 'nested.select': 'one'
+ 'nested.select': 'one',
}, function() {
demand(testItem.nested.select).be('one');
testItem.nested.select = undefined;
diff --git a/fields/types/text/TextColumn.js b/fields/types/text/TextColumn.js
index 62faed20f9..b8be8f5e3d 100644
--- a/fields/types/text/TextColumn.js
+++ b/fields/types/text/TextColumn.js
@@ -24,7 +24,7 @@ var TextColumn = React.createClass({
);
- }
+ },
});
module.exports = TextColumn;
diff --git a/fields/types/text/TextField.js b/fields/types/text/TextField.js
index af39496233..9ea121bb19 100644
--- a/fields/types/text/TextField.js
+++ b/fields/types/text/TextField.js
@@ -1,5 +1,5 @@
import Field from '../Field';
module.exports = Field.create({
- displayName: 'TextField'
+ displayName: 'TextField',
});
diff --git a/fields/types/text/TextFilter.js b/fields/types/text/TextFilter.js
index 54eeb95df3..10c6c9b6a9 100644
--- a/fields/types/text/TextFilter.js
+++ b/fields/types/text/TextFilter.js
@@ -34,7 +34,7 @@ var TextFilter = React.createClass({
mode: React.PropTypes.oneOf(MODE_OPTIONS.map(i => i.value)),
inverted: React.PropTypes.boolean,
value: React.PropTypes.string,
- })
+ }),
},
getDefaultProps () {
@@ -77,7 +77,7 @@ var TextFilter = React.createClass({
);
- }
+ },
});
diff --git a/fields/types/text/test/server.js b/fields/types/text/test/server.js
index 847ef48a9c..c4631ef309 100644
--- a/fields/types/text/test/server.js
+++ b/fields/types/text/test/server.js
@@ -4,8 +4,8 @@ exports.initList = function(List) {
List.add({
text: String,
nested: {
- text: String
- }
+ text: String,
+ },
});
};
@@ -14,33 +14,33 @@ exports.testFieldType = function(List) {
it('should update top level fields', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'value'
+ text: 'value',
}, function() {
demand(testItem.text).be('value');
testItem.text = undefined;
done();
});
});
-
+
it('should update nested fields', function(done) {
List.fields['nested.text'].updateItem(testItem, {
nested: {
- text: 'value'
- }
+ text: 'value',
+ },
}, function() {
demand(testItem.nested.text).be('value');
testItem.nested.text = undefined;
done();
});
});
-
+
it('should update nested fields with flat paths', function(done) {
List.fields['nested.text'].updateItem(testItem, {
- 'nested.text': 'value'
+ 'nested.text': 'value',
}, function() {
demand(testItem.nested.text).be('value');
testItem.nested.text = undefined;
done();
});
- });
+ });
};
diff --git a/fields/types/textarea/TextareaField.js b/fields/types/textarea/TextareaField.js
index 9e5b3b6cfd..1ab663eb83 100644
--- a/fields/types/textarea/TextareaField.js
+++ b/fields/types/textarea/TextareaField.js
@@ -2,14 +2,11 @@ import Field from '../Field';
import React from 'react';
module.exports = Field.create({
-
displayName: 'TextareaField',
-
renderField () {
var styles = {
- height: this.props.height
+ height: this.props.height,
};
return ;
- }
-
+ },
});
diff --git a/fields/types/textarea/test/server.js b/fields/types/textarea/test/server.js
index e11678557c..fa2d84c2e9 100644
--- a/fields/types/textarea/test/server.js
+++ b/fields/types/textarea/test/server.js
@@ -5,8 +5,8 @@ exports.initList = function(List) {
List.add({
text: TextareaType,
nested: {
- text: TextareaType
- }
+ text: TextareaType,
+ },
});
};
@@ -15,73 +15,73 @@ exports.testFieldType = function(List) {
it('should update top level fields', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'value'
+ text: 'value',
}, function() {
demand(testItem.text).be('value');
testItem.text = undefined;
done();
});
});
-
+
it('should update nested fields', function(done) {
List.fields['nested.text'].updateItem(testItem, {
nested: {
- text: 'value'
- }
+ text: 'value',
+ },
}, function() {
demand(testItem.nested.text).be('value');
testItem.nested.text = undefined;
done();
});
- });
+ });
it('should update nested fields with flat paths', function(done) {
List.fields['nested.text'].updateItem(testItem, {
- 'nested.text': 'value'
+ 'nested.text': 'value',
}, function() {
demand(testItem.nested.text).be('value');
testItem.nested.text = undefined;
done();
});
- });
-
+ });
+
it('should format to HTML', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'foo\nbar'
+ text: 'foo\nbar',
}, function() {
demand(testItem._.text.format()).be('foo
bar');
testItem.text = undefined;
done();
});
- });
-
+ });
+
it('should truncate text with a length', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'foobar'
+ text: 'foobar',
}, function() {
demand(testItem._.text.crop(5)).be('fooba');
testItem.text = undefined;
done();
});
- });
-
+ });
+
it('should truncate text with a length and custom append string', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'foobar'
+ text: 'foobar',
}, function() {
demand(testItem._.text.crop(5, '...')).be('fooba...');
testItem.text = undefined;
done();
});
- });
-
+ });
+
it('should truncate text with and preserve words with a length, custom append string', function(done) {
List.fields.text.updateItem(testItem, {
- text: 'foo bar lol'
+ text: 'foo bar lol',
}, function() {
demand(testItem._.text.crop(5, '...', true)).be('foo bar...');
testItem.text = undefined;
done();
});
- });
+ });
};
diff --git a/fields/types/textarray/test/server.js b/fields/types/textarray/test/server.js
index 6e8e68487f..144454d5e0 100644
--- a/fields/types/textarray/test/server.js
+++ b/fields/types/textarray/test/server.js
@@ -5,27 +5,27 @@ exports.initList = function(List) {
List.add({
textarr: TextArrayType,
nested: {
- textarr: TextArrayType
- }
+ textarr: TextArrayType,
+ },
});
};
exports.testFieldType = function(List) {
var testItem = new List.model();
-
+
it('should default to an empty array', function() {
demand(testItem.get('textarr')).eql([]);
});
-
+
it('should validate input', function() {
demand(List.fields.textarr.inputIsValid({
- textarr: ['a']
+ textarr: ['a'],
})).be(true);
demand(List.fields.textarr.inputIsValid({
- textarr: ['a', 'b']
+ textarr: ['a', 'b'],
})).be(true);
});
-
+
it('should validate no input', function() {
demand(List.fields.textarr.inputIsValid({})).be(true);
demand(List.fields.textarr.inputIsValid({}, true)).be(false);
@@ -33,84 +33,84 @@ exports.testFieldType = function(List) {
demand(List.fields.textarr.inputIsValid({}, true, testItem)).be(true);
testItem.textarr = undefined;
});
-
+
it('should validate length when required', function() {
demand(List.fields.textarr.inputIsValid({
- textarr: []
+ textarr: [],
}, true)).be(false);
});
-
+
it('should invalidate arrays with complex values', function() {
demand(List.fields.textarr.inputIsValid({
- textarr: [[]]
+ textarr: [[]],
}, true)).be(false);
});
-
+
it('should update top level fields', function(done) {
List.fields.textarr.updateItem(testItem, {
- textarr: ['a', 'b']
+ textarr: ['a', 'b'],
}, function() {
demand(testItem.textarr).eql(['a', 'b']);
testItem.textarr = undefined;
done();
});
});
-
+
it('should update nested fields', function(done) {
List.fields['nested.textarr'].updateItem(testItem, {
nested: {
- textarr: ['a', 'b']
- }
+ textarr: ['a', 'b'],
+ },
}, function() {
demand(testItem.nested.textarr).eql(['a', 'b']);
testItem.nested.textarr = undefined;
done();
});
});
-
+
it('should update nested fields with flat paths', function(done) {
List.fields['nested.textarr'].updateItem(testItem, {
- 'nested.textarr': ['a', 'b']
+ 'nested.textarr': ['a', 'b'],
}, function() {
demand(testItem.nested.textarr).eql(['a', 'b']);
testItem.nested.textarr = undefined;
done();
});
});
-
+
it('should update empty arrays', function(done) {
List.fields.textarr.updateItem(testItem, {
- textarr: []
+ textarr: [],
}, function() {
demand(testItem.textarr).eql([]);
testItem.textarr = undefined;
done();
});
});
-
+
it('should default on null', function(done) {
List.fields.textarr.updateItem(testItem, {
- textarr: null
+ textarr: null,
}, function() {
demand(testItem.textarr).eql([]);
testItem.textarr = undefined;
done();
});
});
-
+
it('should allow a single string value', function(done) {
List.fields.textarr.updateItem(testItem, {
- textarr: 'a'
+ textarr: 'a',
}, function() {
demand(testItem.textarr).eql(['a']);
testItem.textarr = undefined;
done();
});
});
-
+
it('should convert numbers to strings', function(done) {
List.fields.textarr.updateItem(testItem, {
- textarr: 1
+ textarr: 1,
}, function() {
demand(testItem.textarr).eql(['1']);
testItem.textarr = undefined;
diff --git a/fields/types/url/UrlColumn.js b/fields/types/url/UrlColumn.js
index f3be6ecc72..8a49f9b744 100644
--- a/fields/types/url/UrlColumn.js
+++ b/fields/types/url/UrlColumn.js
@@ -34,7 +34,7 @@ var UrlColumn = React.createClass({
{this.renderValue()}
);
- }
+ },
});
module.exports = UrlColumn;
diff --git a/fields/types/url/UrlField.js b/fields/types/url/UrlField.js
index 885a9826c5..a565557da5 100644
--- a/fields/types/url/UrlField.js
+++ b/fields/types/url/UrlField.js
@@ -3,9 +3,7 @@ import Field from '../Field';
import { Button, FormInput } from 'elemental';
module.exports = Field.create({
-
displayName: 'URLField',
-
openValue () {
var href = this.props.value;
if (!href) return;
@@ -33,6 +31,5 @@ module.exports = Field.create({
},
renderValue () {
return {this.props.value};
- }
-
+ },
});
diff --git a/fields/types/url/test/server.js b/fields/types/url/test/server.js
index 3513fa29a0..a49698220d 100644
--- a/fields/types/url/test/server.js
+++ b/fields/types/url/test/server.js
@@ -5,8 +5,8 @@ exports.initList = function(List) {
List.add({
url: UrlType,
nested: {
- url: UrlType
- }
+ url: UrlType,
+ },
});
};
@@ -15,43 +15,43 @@ exports.testFieldType = function(List) {
it('should update top level fields', function(done) {
List.fields.url.updateItem(testItem, {
- url: 'value'
+ url: 'value',
}, function() {
demand(testItem.url).be('value');
testItem.url = undefined;
done();
});
});
-
+
it('should update nested fields', function(done) {
List.fields['nested.url'].updateItem(testItem, {
nested: {
- url: 'value'
- }
+ url: 'value',
+ },
}, function() {
demand(testItem.nested.url).be('value');
testItem.nested.url = undefined;
done();
});
});
-
+
it('should update nested fields with flat paths', function(done) {
List.fields['nested.url'].updateItem(testItem, {
- 'nested.url': 'value'
+ 'nested.url': 'value',
}, function() {
demand(testItem.nested.url).be('value');
testItem.nested.url = undefined;
done();
});
- });
-
+ });
+
it('should strip the protocol when formatting', function(done) {
List.fields.url.updateItem(testItem, {
- url: 'http://www.keystonejs.com'
+ url: 'http://www.keystonejs.com',
}, function() {
demand(testItem._.url.format()).be('www.keystonejs.com');
testItem.url = undefined;
done();
});
- });
+ });
};
diff --git a/index.js b/index.js
index 27be71a7aa..28347ea31a 100644
--- a/index.js
+++ b/index.js
@@ -37,7 +37,7 @@ var Keystone = function () {
'auto update': false,
'model prefix': null,
'module root': moduleRoot,
- 'frame guard': 'sameorigin'
+ 'frame guard': 'sameorigin',
};
this._redirects = {};
@@ -90,7 +90,7 @@ var Keystone = function () {
// Attach middleware packages, bound to this instance
this.middleware = {
api: require('./lib/middleware/api')(this),
- cors: require('./lib/middleware/cors')(this)
+ cors: require('./lib/middleware/cors')(this),
};
};
@@ -134,7 +134,7 @@ var keystone = module.exports = new Keystone();
// Expose modules and Classes
keystone.Admin = {
- Server: require('./admin/server')
+ Server: require('./admin/server'),
};
keystone.Email = require('./lib/email');
keystone.Field = require('./fields/types/Type');
@@ -145,7 +145,7 @@ keystone.View = require('./lib/view');
keystone.content = require('./lib/content');
keystone.security = {
- csrf: require('./lib/security/csrf')
+ csrf: require('./lib/security/csrf'),
};
keystone.utils = utils;
diff --git a/lib/content/index.js b/lib/content/index.js
index e23df50c32..d0b0c6b755 100644
--- a/lib/content/index.js
+++ b/lib/content/index.js
@@ -1,6 +1,6 @@
-var _ = require('underscore'),
- keystone = require('../../'),
- utils = keystone.utils;
+var _ = require('underscore');
+var keystone = require('../../');
+var utils = keystone.utils;
/**
* Content Class
@@ -177,7 +177,7 @@ Content.prototype.initModel = function() {
var contentSchemaDef = {
createdAt: { type: Date, default: Date.now },
- data: { type: keystone.mongoose.Schema.Types.Mixed }
+ data: { type: keystone.mongoose.Schema.Types.Mixed },
};
var ContentSchema = new keystone.mongoose.Schema(contentSchemaDef);
@@ -186,7 +186,7 @@ Content.prototype.initModel = function() {
page: { type: String, index: true },
lastChangeDate: { type: Date, index: true },
content: contentSchemaDef,
- history: [ContentSchema]
+ history: [ContentSchema],
}, { collection: 'app_content' });
this.AppContent = keystone.mongoose.model('App_Content', PageSchema);
@@ -219,7 +219,7 @@ Content.prototype.editable = function(user, options) {
type: 'list',
path: list.path,
singular: list.singular,
- plural: list.plural
+ plural: list.plural,
};
if (options.id) {
diff --git a/lib/content/page.js b/lib/content/page.js
index 37e53d40bf..1e909783ff 100644
--- a/lib/content/page.js
+++ b/lib/content/page.js
@@ -1,8 +1,8 @@
-var _ = require('underscore'),
- assign = require('object-assign'),
- keystone = require('../../'),
- utils = keystone.utils,
- Type = require('./type');
+var _ = require('underscore');
+var assign = require('object-assign');
+var keystone = require('../../');
+var utils = keystone.utils;
+var Type = require('./type');
/**
* Page Class
@@ -13,7 +13,7 @@ var _ = require('underscore'),
*/
function Page(key, options) {
-
+
if (!(this instanceof Page)) {
return new Page(key, options);
}
@@ -21,13 +21,13 @@ function Page(key, options) {
this.options = assign({}, options);
this.key = key;
this.fields = {};
-
+
}
Object.defineProperty(Page.prototype, 'name', {
get: function() {
return this.get('name') || this.set('name', utils.keyToLabel(this.key));
- }
+ },
});
/**
@@ -52,7 +52,7 @@ Page.prototype.set = function(key, value) {
value = value || null;
this.options[key] = value;
return value;
-
+
};
@@ -83,35 +83,35 @@ Page.prototype.get = function(key) {
/**
* Adds one or more fields to the page
- *
+ *
* @api public
*/
Page.prototype.add = function(fields) {
-
+
// TODO: nested paths
if (!utils.isObject(fields)) {
throw new Error('keystone.content.Page.add() Error: fields must be an object.');
}
-
+
_.each(fields, function(options, path) {
-
+
if ('function' === typeof options) {
options = { type: options };
}
-
+
if ('function' !== typeof options.type) {
throw new Error('keystone.content.page.add() Error: Page fields must be specified with a type function');
}
-
+
if (options.type.prototype.__proto__ !== Type.prototype) {
-
+
// Convert native field types to their default Keystone counterpart
-
+
if (options.type === String) {
options.type = keystone.content.Types.Text;
}
-
+
// TODO: More types
// else if (options.type == Number)
// options.type = Field.Types.Number;
@@ -119,33 +119,33 @@ Page.prototype.add = function(fields) {
// options.type = Field.Types.Boolean;
// else if (options.type == Date)
// options.type = Field.Types.Datetime;
-
+
else {
throw new Error('keystone.content.page.add() Error: Unrecognised field constructor: ' + options.type);
}
-
+
}
-
+
this.fields[path] = new options.type(path, options);
-
+
}, this);
-
+
return this;
-
+
};
/**
* Registers the page with Keystone.
- *
+ *
* ####Example:
- *
+ *
* var homePage = new keystone.content.Page('home');
* // ...
* homePage.register();
- *
+ *
* // later...
* var homePage = keystone.content.page('home');
- *
+ *
* @api public
*/
@@ -155,7 +155,7 @@ Page.prototype.register = function() {
/**
* Populates a data structure based on defined fields
- *
+ *
* @api public
*/
@@ -164,16 +164,16 @@ Page.prototype.populate = function(data) {
if (typeof data !== 'object') {
data = {};
}
-
+
// TODO: implement schema
-
+
return data;
-
+
};
/**
* Validates a data structure based on defined fields
- *
+ *
* @api public
*/
@@ -182,16 +182,16 @@ Page.prototype.validate = function(data) {
if (typeof data !== 'object') {
data = {};
}
-
+
// TODO: implement schema
-
+
return data;
-
+
};
/**
* Cleans a data structure so only the defined fields are present
- *
+ *
* @api public
*/
@@ -200,11 +200,11 @@ Page.prototype.clean = function(data) {
if (typeof data !== 'object') {
data = {};
}
-
+
// TODO: implement schema
-
+
return data;
-
+
};
diff --git a/lib/core/createItems.js b/lib/core/createItems.js
index 954fbf9798..c5b7d54ad6 100644
--- a/lib/core/createItems.js
+++ b/lib/core/createItems.js
@@ -14,7 +14,7 @@ function createItems(data, ops, callback) {
var options = {
verbose: false,
strict: true,
- refs: null
+ refs: null,
};
var dashes = '------------------------------------------------';
@@ -53,7 +53,7 @@ function createItems(data, ops, callback) {
if (options.strict) {
return doneList({
type: 'invalid list',
- message: 'List key ' + key + ' is invalid.'
+ message: 'List key ' + key + ' is invalid.',
});
}
if (options.verbose) {
@@ -70,7 +70,7 @@ function createItems(data, ops, callback) {
singular: list.singular,
plural: list.plural,
created: 0,
- warnings: 0
+ warnings: 0,
};
var itemsProcessed = 0,
@@ -239,7 +239,7 @@ function createItems(data, ops, callback) {
return doneField({
type: 'invalid ref',
srcData: srcData,
- message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid reference.'
+ message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid reference.',
});
}
@@ -251,7 +251,7 @@ function createItems(data, ops, callback) {
return doneField({
type: 'invalid data',
srcData: srcData,
- message: 'Single-value relationship ' + list.key + '.' + field.path + ' provided as an array.'
+ message: 'Single-value relationship ' + list.key + '.' + field.path + ' provided as an array.',
});
}
@@ -263,7 +263,7 @@ function createItems(data, ops, callback) {
return options.strict ? doneField({
type: 'invalid ref',
srcData: srcData,
- message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid reference: "' + fieldValue + '".'
+ message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid reference: "' + fieldValue + '".',
}) : doneField();
}
@@ -283,7 +283,7 @@ function createItems(data, ops, callback) {
return doneField({
type: 'invalid data',
srcData: srcData,
- message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid data type.'
+ message: 'Relationship ' + list.key + '.' + field.path + ' contains an invalid data type.',
});
}
@@ -305,7 +305,7 @@ function createItems(data, ops, callback) {
}, doneList);
}, next);
- }
+ },
], function(err) {
diff --git a/lib/core/initExpressSession.js b/lib/core/initExpressSession.js
index d7d26e9336..650e8844b3 100644
--- a/lib/core/initExpressSession.js
+++ b/lib/core/initExpressSession.js
@@ -55,14 +55,14 @@ module.exports = function initExpressSession () {
debug('using connect-mongo session store');
_.defaults(sessionStoreOptions, {
collection: 'app_sessions',
- url: this.get('mongo')
+ url: this.get('mongo'),
});
break;
case 'connect-mongostore':
debug('using connect-mongostore session store');
_.defaults(sessionStoreOptions, {
- collection: 'app_sessions'
+ collection: 'app_sessions',
});
if (!sessionStoreOptions.db) {
console.error(
diff --git a/lib/core/initNav.js b/lib/core/initNav.js
index 4c014b3838..4752e7d422 100644
--- a/lib/core/initNav.js
+++ b/lib/core/initNav.js
@@ -15,8 +15,8 @@ module.exports = function initNav(sections) {
sections: [],
by: {
list: {},
- section: {}
- }
+ section: {},
+ },
};
if (!sections) {
@@ -34,7 +34,7 @@ module.exports = function initNav(sections) {
}
section = {
lists: section,
- label: nav.flat ? keystone.list(section[0]).label : utils.keyToLabel(key)
+ label: nav.flat ? keystone.list(section[0]).label : utils.keyToLabel(key),
};
section.key = key;
section.lists = _.map(section.lists, function(i) {
@@ -50,7 +50,7 @@ module.exports = function initNav(sections) {
return {
key: list.key,
label: list.label,
- path: list.path
+ path: list.path,
};
} else if (_.isObject(i)) {
if (!_.has(i, 'key')) {
diff --git a/lib/core/openDatabaseConnection.js b/lib/core/openDatabaseConnection.js
index 043fea29e8..05afba5a0f 100644
--- a/lib/core/openDatabaseConnection.js
+++ b/lib/core/openDatabaseConnection.js
@@ -21,8 +21,8 @@ module.exports = function openDatabaseConnection (callback) {
auth: { authSource: replicaData.authSource },
replset: {
rs_name: replicaData.db.replicaSetOptions.rs_name,
- readPreference: replicaData.db.replicaSetOptions.readPreference
- }
+ readPreference: replicaData.db.replicaSetOptions.readPreference,
+ },
};
debug('connecting to replicate set');
diff --git a/lib/core/options.js b/lib/core/options.js
index 2de3098b47..4f77b404d7 100644
--- a/lib/core/options.js
+++ b/lib/core/options.js
@@ -49,7 +49,7 @@ module.exports = function options () {
api_key: auth[0],
api_secret: auth[1],
private_cdn: parts.pathname != null,
- secure_distribution: parts.pathname && parts.pathname.substring(1)
+ secure_distribution: parts.pathname && parts.pathname.substring(1),
};
}
if (_.isObject(value)) {
diff --git a/lib/core/render.js b/lib/core/render.js
index 24bc98d916..fd72434b6e 100644
--- a/lib/core/render.js
+++ b/lib/core/render.js
@@ -17,7 +17,7 @@ function render(req, res, view, ext) {
var templatePath = __dirname + '/../../admin/server/templates/' + view + '.jade';
var jadeOptions = {
filename: templatePath,
- pretty: keystone.get('env') !== 'production'
+ pretty: keystone.get('env') !== 'production',
};
var compileTemplate = function() {
return jade.compile(fs.readFileSync(templatePath, 'utf8'), jadeOptions);
@@ -63,7 +63,7 @@ function render(req, res, view, ext) {
csrf_query: '&' + keystone.security.csrf.TOKEN_KEY + '=' + keystone.security.csrf.getToken(req, res),
ga: {
property: keystone.get('ga property'),
- domain: keystone.get('ga domain')
+ domain: keystone.get('ga domain'),
},
wysiwygOptions: {
enableImages: keystone.get('wysiwyg images') ? true : false,
@@ -75,8 +75,8 @@ function render(req, res, view, ext) {
overrideToolbar: keystone.get('wysiwyg override toolbar'),
skin: keystone.get('wysiwyg skin') || 'keystone',
menubar: keystone.get('wysiwyg menubar'),
- importcss: keystone.get('wysiwyg importcss') || ''
- }
+ importcss: keystone.get('wysiwyg importcss') || '',
+ },
};
// view-specific extensions to the local scope
@@ -93,7 +93,7 @@ function render(req, res, view, ext) {
signature: cloudinaryUpload.hidden_fields.signature,
prefix: keystone.get('cloudinary prefix') || '',
folders: keystone.get('cloudinary folders'),
- uploader: cloudinary.uploader
+ uploader: cloudinary.uploader,
};
locals.cloudinary_js_config = cloudinary.cloudinary_js_config();
} catch(e) {
diff --git a/lib/core/start.js b/lib/core/start.js
index f0b394b2d3..d38e3ae047 100644
--- a/lib/core/start.js
+++ b/lib/core/start.js
@@ -85,7 +85,7 @@ function start(events) {
startupMessages.push(msg);
done(err);
});
- }
+ },
], function serversStarted (err, messages) {
if (keystone.get('logger')) {
console.log(dashes + startupMessages.join('\n') + dashes);
diff --git a/lib/email.js b/lib/email.js
index 9e1b4cbed5..ce24ae56fb 100644
--- a/lib/email.js
+++ b/lib/email.js
@@ -17,11 +17,11 @@ var defaultConfig = {
track_opens: true,
track_clicks: true,
preserve_recipients: false,
- inline_css: true
+ inline_css: true,
},
// Mandrill template
templateMandrillName: null,
- templateForceHtml: false // Force html render
+ templateForceHtml: false, // Force html render
};
/** Custom Errors */
@@ -117,7 +117,7 @@ var templateCSSMethods = {
var num = parseInt(color.slice(1), 16), amt = Math.round(2.55 * percent), R = (num >> 16) + amt, G = (num >> 8 & 0x00FF) + amt, B = (num & 0x0000FF) + amt;
return '#' + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (G<255?G<1?0:G:255)*0x100 + (B<255?B<1?0:B:255)).toString(16).slice(1);
/* eslint-enable */
- }
+ },
};
@@ -145,7 +145,7 @@ var Email = function(options) {
// Passing a string will use Email.defaults for everything but template name
if ('string' === typeof options) {
options = {
- templateName: options
+ templateName: options,
};
} else if (!utils.isObject(options)) {
throw new ErrorEmailOptionsRequired();
@@ -201,7 +201,7 @@ Email.prototype.render = function(locals, callback) {
subject: '(no subject)',
brand: keystone.get('brand'),
theme: {},
- css: templateCSSMethods
+ css: templateCSSMethods,
});
if (!locals.theme.buttons) {
@@ -226,7 +226,7 @@ Email.prototype.render = function(locals, callback) {
return callback({
from: 'Email.compileTemplate',
key: 'invalid rendering function',
- message: 'no template rendering function could be found.'
+ message: 'no template rendering function could be found.',
});
}
@@ -262,7 +262,7 @@ Email.prototype.render = function(locals, callback) {
callback(null, {
subject: locals.subject,
- html: html
+ html: html,
});
}.bind(this));
@@ -396,7 +396,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
return callback({
from: 'Email.send',
key: 'invalid options',
- message: 'options object is required'
+ message: 'options object is required',
});
}
@@ -412,7 +412,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
return callback({
from: 'Email.send',
key: 'invalid options',
- message: 'options.fromName and options.fromEmail are required'
+ message: 'options.fromName and options.fromEmail are required',
});
}
@@ -421,7 +421,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
return callback({
from: 'Email.send',
key: 'missing api key',
- message: 'You must either provide a Mandrill API Instance or set the mandrill api key before sending email.'
+ message: 'You must either provide a Mandrill API Instance or set the mandrill api key before sending email.',
});
}
options.mandrill = new mandrillapi.Mandrill(keystone.get('mandrill api key'));
@@ -457,7 +457,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
return callback({
from: 'Email.send',
key: 'invalid recipient',
- message: 'Recipient ' + (i + 1) + ' does not have a valid email address.'
+ message: 'Recipient ' + (i + 1) + ' does not have a valid email address.',
});
}
@@ -466,7 +466,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
return callback({
from: 'Email.send',
key: 'invalid recipient',
- message: 'Recipient ' + (i + 1) + ' is not a string or an object.'
+ message: 'Recipient ' + (i + 1) + ' is not a string or an object.',
});
}
@@ -493,7 +493,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
mergeVars.push({
rcpt: recipient.email,
- vars: vars
+ vars: vars,
});
}
@@ -505,7 +505,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
to: recipients,
global_merge_vars: options.global_merge_vars,
merge_vars: mergeVars,
- async: true
+ async: true,
};
if (options.subject) {
@@ -520,7 +520,7 @@ Email.prototype.buildOptions = function(err, options, callback) {
_.defaults(message, Email.defaults.mandrill);
var toSend = {
- message: message
+ message: message,
};
if (this.templateMandrillName) {
@@ -610,7 +610,7 @@ Email.prototype.send = function(options, callback) {
from: 'Email.send',
key: 'send error',
message: 'Mandrill encountered an error and did not send the emails.',
- info: info
+ info: info,
});
};
@@ -678,7 +678,7 @@ Email.prototype.renderMandrill = function(options, callback) {
from: 'Email.renderMandrill',
key: 'render error',
message: 'Mandrill encountered an error rendering the email.',
- info: info
+ info: info,
});
};
diff --git a/lib/fieldTypes.js b/lib/fieldTypes.js
index 551c007eb1..de4f49484e 100644
--- a/lib/fieldTypes.js
+++ b/lib/fieldTypes.js
@@ -28,7 +28,7 @@ var fields = {
get Text () { return require('../fields/types/text/TextType'); },
get TextArray () { return require('../fields/types/textarray/TextArrayType'); },
get Textarea () { return require('../fields/types/textarea/TextareaType'); },
- get Url () { return require('../fields/types/url/UrlType'); }
+ get Url () { return require('../fields/types/url/UrlType'); },
};
module.exports = fields;
diff --git a/lib/list.js b/lib/list.js
index 7ff75aec39..983985b28c 100644
--- a/lib/list.js
+++ b/lib/list.js
@@ -15,7 +15,7 @@ function List(key, options) {
var defaultOptions = {
schema: {
- collection: keystone.prefixModel(key)
+ collection: keystone.prefixModel(key),
},
noedit: false,
nocreate: false,
@@ -28,7 +28,7 @@ function List(key, options) {
perPage: 100,
searchFields: '__name__',
defaultSort: '__default__',
- defaultColumns: '__name__'
+ defaultColumns: '__name__',
};
// initialFields values are initialised on demand by the getter
@@ -61,7 +61,7 @@ function List(key, options) {
createdBy: null,
createdOn: null,
modifiedBy: null,
- modifiedOn: null
+ modifiedOn: null,
};
// init mappings
@@ -123,7 +123,7 @@ Object.defineProperty(List.prototype, 'searchFields', {
}, set: function(value) {
this.set('searchFields', value);
delete this._searchFields;
- }
+ },
});
// Default Sort Field
@@ -133,7 +133,7 @@ Object.defineProperty(List.prototype, 'defaultSort', {
return (ds === '__default__') ? (this.get('sortable') ? 'sortOrder' : this.namePath) : ds;
}, set: function(value) {
this.set('defaultSort', value);
- }
+ },
});
// Default Column Fields
@@ -146,7 +146,7 @@ Object.defineProperty(List.prototype, 'defaultColumns', {
}, set: function(value) {
this.set('defaultColumns', value);
delete this._defaultColumns;
- }
+ },
});
// Add prototype methods
diff --git a/lib/list/add.js b/lib/list/add.js
index c106233338..794e6fcb70 100644
--- a/lib/list/add.js
+++ b/lib/list/add.js
@@ -38,7 +38,7 @@ function add () {
}
this.uiElements.push({
type: 'field',
- field: this.field(path, options)
+ field: this.field(path, options),
});
}.bind(this);
@@ -47,17 +47,17 @@ function add () {
if ('string' === typeof def) {
if (def === '>>>') {
this.uiElements.push({
- type: 'indent'
+ type: 'indent',
});
} else if (def === '<<<') {
this.uiElements.push({
- type: 'outdent'
+ type: 'outdent',
});
} else {
this.uiElements.push({
type: 'heading',
heading: def,
- options: {}
+ options: {},
});
}
} else {
@@ -65,7 +65,7 @@ function add () {
this.uiElements.push({
type: 'heading',
heading: def.heading,
- options: def
+ options: def,
});
} else {
add(def);
diff --git a/lib/list/addSearchToQuery.js b/lib/list/addSearchToQuery.js
index 0d5cdacb88..ead1e905bc 100644
--- a/lib/list/addSearchToQuery.js
+++ b/lib/list/addSearchToQuery.js
@@ -12,7 +12,7 @@ function getNameFilter(field, searchString) {
var last = {};
last[field.paths.last] = nameSearchRegExp;
return {
- $or: [first, last]
+ $or: [first, last],
};
}
diff --git a/lib/list/expandColumns.js b/lib/list/expandColumns.js
index 03338f7944..5b588fc144 100644
--- a/lib/list/expandColumns.js
+++ b/lib/list/expandColumns.js
@@ -36,7 +36,7 @@ function expandColumns(cols) {
field: field,
path: field.path,
type: field.type,
- label: def.label || field.label
+ label: def.label || field.label,
};
if (col.type === 'relationship') {
col.refList = col.field.refList;
@@ -54,7 +54,7 @@ function expandColumns(cols) {
// TODO: this needs to handle sophisticated types, including arrays, nested Schemas, and mixed types
col = {
path: def.path,
- label: def.label || utils.keyToLabel(def.path)
+ label: def.label || utils.keyToLabel(def.path),
};
}
if (col) {
diff --git a/lib/list/expandPaths.js b/lib/list/expandPaths.js
index f5180527a3..23f312ec78 100644
--- a/lib/list/expandPaths.js
+++ b/lib/list/expandPaths.js
@@ -7,7 +7,7 @@ function expandPaths (paths) {
}
return {
path: path,
- field: this.fields[path]
+ field: this.fields[path],
};
}, this);
}
diff --git a/lib/list/expandSort.js b/lib/list/expandSort.js
index 191d5fd946..8899748591 100644
--- a/lib/list/expandSort.js
+++ b/lib/list/expandSort.js
@@ -6,7 +6,7 @@ function expandSort(input) {
var fields = this.fields;
var sort = {
rawInput: input || this.defaultSort,
- isDefaultSort: false
+ isDefaultSort: false,
};
sort.input = sort.rawInput;
if (sort.input === '__default__') {
@@ -26,7 +26,7 @@ function expandSort(input) {
return {
field: field,
invert: invert,
- path: field.path
+ path: field.path,
};
}).filter(truthy);
sort.string = sort.paths.map(function (i) {
diff --git a/lib/list/getCSV.js b/lib/list/getCSV.js
index 34baa7ff54..82dbfaa6ca 100644
--- a/lib/list/getCSV.js
+++ b/lib/list/getCSV.js
@@ -6,7 +6,7 @@ var listToArray = require('list-to-array');
function getData (item, fields, expandRelationshipFields) {
var data = {
- id: item.id
+ id: item.id,
};
if (this.autokey) {
data[this.autokey.path] = item.get(this.autokey.path);
diff --git a/lib/list/getData.js b/lib/list/getData.js
index 57663d81f6..684cd22c49 100644
--- a/lib/list/getData.js
+++ b/lib/list/getData.js
@@ -8,7 +8,7 @@ var listToArray = require('list-to-array');
function getData (item, fields, expandRelationshipFields) {
var data = {
id: item.id,
- name: this.getDocumentName(item)
+ name: this.getDocumentName(item),
};
if (this.autokey) {
data[this.autokey.path] = item.get(this.autokey.path);
diff --git a/lib/list/getOptions.js b/lib/list/getOptions.js
index f645dd7158..d9ed39c7a6 100644
--- a/lib/list/getOptions.js
+++ b/lib/list/getOptions.js
@@ -32,7 +32,7 @@ function getOptions () {
track: this.options.track,
tracking: this.tracking,
relationships: this.relationships,
- uiElements: []
+ uiElements: [],
};
_.each(this.uiElements, function (el) {
switch (el.type) {
@@ -52,14 +52,14 @@ function getOptions () {
// add the field to the elements array
ops.uiElements.push({
type: 'field',
- field: el.field.path
+ field: el.field.path,
});
break;
case 'heading':
ops.uiElements.push({
type: 'heading',
content: el.heading,
- options: el.options
+ options: el.options,
});
break;
}
diff --git a/lib/list/getSearchFilters.js b/lib/list/getSearchFilters.js
index 0c5b0f38b0..cfe3d40392 100644
--- a/lib/list/getSearchFilters.js
+++ b/lib/list/getSearchFilters.js
@@ -143,12 +143,12 @@ function getSearchFilters (search, add) {
if (filter.operator === 'bt') {
value = [
utils.number(value[0]),
- utils.number(value[1])
+ utils.number(value[1]),
];
if ( !isNaN(value[0]) && !isNaN(value[1]) ) {
filters[path] = {
$gte: value[0],
- $lte: value[1]
+ $lte: value[1],
};
}
else {
@@ -178,12 +178,12 @@ function getSearchFilters (search, add) {
if (filter.operator === 'bt') {
value = [
moment(value[0]),
- moment(value[1])
+ moment(value[1]),
];
if ( (value[0] && value[0].isValid()) && (value[1] && value[0].isValid()) ) {
filters[path] = {
$gte: moment(value[0]).startOf('day').toDate(),
- $lte: moment(value[1]).endOf('day').toDate()
+ $lte: moment(value[1]).endOf('day').toDate(),
};
}
} else {
diff --git a/lib/list/isReserved.js b/lib/list/isReserved.js
index 6fc0823ba7..c6326408a0 100644
--- a/lib/list/isReserved.js
+++ b/lib/list/isReserved.js
@@ -18,7 +18,7 @@ var reservedPaths = [
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
- 'valueOf'
+ 'valueOf',
];
function isReserved (path) {
diff --git a/lib/list/paginate.js b/lib/list/paginate.js
index 0d4d2c1dc2..3a49501e10 100644
--- a/lib/list/paginate.js
+++ b/lib/list/paginate.js
@@ -73,7 +73,7 @@ function paginate (options, callback) {
previous: (currentPage > 1) ? (currentPage - 1) : false,
next: (currentPage < totalPages) ? (currentPage + 1) : false,
first: skip + 1,
- last: skip + results.length
+ last: skip + results.length,
};
list.getPages(rtn, maxPages);
callback(err, rtn);
diff --git a/lib/list/relationship.js b/lib/list/relationship.js
index 12c1bcfabc..8e411e3f49 100644
--- a/lib/list/relationship.js
+++ b/lib/list/relationship.js
@@ -26,12 +26,12 @@ function relationship (def) {
Object.defineProperty(def, 'refList', {
get: function() {
return keystone.list(def.ref);
- }
+ },
});
Object.defineProperty(def, 'isValid', {
get: function() {
return keystone.list(def.ref) ? true : false;
- }
+ },
});
this.relationships[def.path] = def;
return this;
diff --git a/lib/middleware/language.js b/lib/middleware/language.js
index c5dbf67586..251f4b6a98 100644
--- a/lib/middleware/language.js
+++ b/lib/middleware/language.js
@@ -6,15 +6,15 @@ module.exports = function (keystone) {
'supported languages': ['en-US'],
'language cookie': 'language',
'language cookie options': {},
- 'language select url': '/languages/{language}'
+ 'language select url': '/languages/{language}',
}, keystone.get('language options'));
return requestLanguage({
languages: languageOptions['supported languages'],
cookie: {
name: languageOptions['language cookie'],
- url: languageOptions['language select url']
+ url: languageOptions['language select url'],
},
- queryName: languageOptions['language query name']
+ queryName: languageOptions['language query name'],
});
};
diff --git a/lib/schemaPlugins.js b/lib/schemaPlugins.js
index 6c19035692..0165c9682e 100644
--- a/lib/schemaPlugins.js
+++ b/lib/schemaPlugins.js
@@ -5,9 +5,9 @@ exports.history = require('./schemaPlugins/history');
exports.methods = {
getRelated: require('./schemaPlugins/methods/getRelated'),
- populateRelated: require('./schemaPlugins/methods/populateRelated')
+ populateRelated: require('./schemaPlugins/methods/populateRelated'),
};
exports.options = {
- transform: require('./schemaPlugins/options/transform')
+ transform: require('./schemaPlugins/options/transform'),
};
diff --git a/lib/schemaPlugins/autokey.js b/lib/schemaPlugins/autokey.js
index b6e4e3f2b4..6aa8b0ecb9 100644
--- a/lib/schemaPlugins/autokey.js
+++ b/lib/schemaPlugins/autokey.js
@@ -27,7 +27,7 @@ module.exports = function autokey() {
def[autokey.path] = {
type: String,
- index: true
+ index: true,
};
if (autokey.unique) {
diff --git a/lib/schemaPlugins/history.js b/lib/schemaPlugins/history.js
index 5ed8f08db8..03ccc27ca8 100644
--- a/lib/schemaPlugins/history.js
+++ b/lib/schemaPlugins/history.js
@@ -1,34 +1,34 @@
var keystone = require('../../');
-var historyModelSuffix = '_revisions';
+var historyModelSuffix = '_revisions';
function getHistoryModelName (list) {
return list.options.schema.collection + historyModelSuffix;
}
function getHistoryModel(list, userModel) {
-
+
var collection = getHistoryModelName(list);
-
+
var schema = new keystone.mongoose.Schema({
i: { type: keystone.mongoose.Schema.Types.ObjectId, ref: collection },
t: { type: Date, index: true, required: true },
o: { type: String, index: true, required: true },
c: { type: [String], index: true },
- d: { type: keystone.mongoose.Schema.Types.Mixed, required: true }
+ d: { type: keystone.mongoose.Schema.Types.Mixed, required: true },
}, {
id: true,
- versionKey: false
+ versionKey: false,
});
-
+
if (userModel) {
schema.add({
- u: { type: keystone.mongoose.Schema.Types.ObjectId, ref: userModel }
+ u: { type: keystone.mongoose.Schema.Types.ObjectId, ref: userModel },
});
}
-
+
return keystone.mongoose.model(collection, schema, collection);
-
+
}
/**
@@ -40,7 +40,7 @@ function getHistoryModel(list, userModel) {
module.exports = function history() {
var list = this;
-
+
//If model already exists for a '_revisions' in an inherited model, log a warning but skip creating the new model (inherited _revisions model will be used).
var collectionName = getHistoryModelName(list);
if (list.get('inherits') &&
@@ -51,62 +51,62 @@ module.exports = function history() {
}
var userModel = keystone.get('user model');
-
+
var HistoryModel = list.HistoryModel = getHistoryModel(this, userModel);
-
+
list.schema.add({
- __rev: Number
+ __rev: Number,
});
-
+
list.schema.pre('save', function(next) {
this.__rev = (typeof this.__rev === 'number') ? this.__rev + 1 : 1;
-
+
var data = this.toObject();
delete data._id;
delete data.__v;
delete data.__rev;
-
+
var doc = {
i: this.id,
t: Date.now(),
o: this.isNew ? 'c' : 'u',
c: [],
- d: data
+ d: data,
};
-
+
for (var path in list.fields) {
if (this.isModified(path)) {
doc.c.push(path);
}
}
-
+
if (list.autokey) {
if (this.isModified(list.autokey.path)) {
doc.c.push(list.autokey.path);
}
}
-
+
if (userModel && this._req_user) {
doc.u = this._req_user;
}
-
+
new HistoryModel(doc).save(next);
});
-
+
list.schema.pre('remove', function(next) {
var data = this.toObject();
data.__v = undefined;
-
+
var doc = {
t: Date.now(),
o: 'd',
- d: data
+ d: data,
};
-
+
if (userModel && this._req_user) {
doc.u = this._req_user;
}
-
+
new HistoryModel(doc).save(next);
});
diff --git a/lib/schemaPlugins/track.js b/lib/schemaPlugins/track.js
index fef905bae5..2548b17efa 100644
--- a/lib/schemaPlugins/track.js
+++ b/lib/schemaPlugins/track.js
@@ -5,38 +5,38 @@ var Types = require('../fieldTypes');
/**
* List track option
*
- * When enabled, it tracks when a document are created/updated,
+ * When enabled, it tracks when a document are created/updated,
* as well as the user who created/updated it.
*/
module.exports = function track() {
-
+
var list = this;
var options = list.get('track');
var userModel = keystone.get('user model');
- var defaultOptions = {
- createdAt: false,
+ var defaultOptions = {
+ createdAt: false,
createdBy: false,
updatedAt: false,
- updatedBy: false
+ updatedBy: false,
};
var fields = {};
-
+
// ensure track is a boolean or an object
if (!_.isBoolean(options) && !_.isObject(options) ) {
throw new Error('Invalid List "track" option for ' + list.key + '\n' +
'"track" must be a boolean or an object.\n\n' +
- 'See http://keystonejs.com/docs/database/#lists-options for more information.');
+ 'See http://keystonejs.com/docs/database/#lists-options for more information.');
}
if (_.isBoolean(options)) {
// shorthand: { track: true } sets all tracked fields to true
if (options) {
- options = {
- createdAt: true,
+ options = {
+ createdAt: true,
createdBy: true,
updatedAt: true,
- updatedBy: true
+ updatedBy: true,
};
} else {
// otherwise user doesn't want tracking
@@ -54,9 +54,9 @@ module.exports = function track() {
// validate option fields
_.each(options, function(value, key) {
-
+
var fieldName;
-
+
// make sure the key isn't already defined as a field
if (_.has(list.fields, key)) {
throw new Error('Invalid List "track" option for ' + list.key + '\n' +
@@ -65,7 +65,7 @@ module.exports = function track() {
// make sure it's a valid track option field
if (_.has(defaultOptions, key)) {
-
+
// make sure the option field value is either a boolean or a string
if (!_.isBoolean(value) && !_.isString(value)) {
throw new Error('Invalid List "track" option for ' + list.key + '\n' +
@@ -74,7 +74,7 @@ module.exports = function track() {
}
if (value) {
- // determine
+ // determine
fieldName = value === true ? key : value;
options[key] = fieldName;
list.map(key, fieldName);
@@ -94,19 +94,19 @@ module.exports = function track() {
} else {
throw new Error('Invalid List "track" option for ' + list.key + '\n' +
'valid field options are "createdAt", "createdBy", "updatedAt", an "updatedBy".\n\n' +
- 'See http://keystonejs.com/docs/database/#lists-options for more information.');
+ 'See http://keystonejs.com/docs/database/#lists-options for more information.');
}
});
// add track fields to schema
list.add(fields);
-
+
list.tracking = options;
// add the pre-save schema plugin
list.schema.pre('save', function (next) {
-
+
var now = new Date();
// set createdAt/createdBy on new docs
@@ -130,7 +130,7 @@ module.exports = function track() {
}
next();
-
+
});
};
diff --git a/lib/security/csrf.js b/lib/security/csrf.js
index b4e43a6a67..a58dff2ccd 100644
--- a/lib/security/csrf.js
+++ b/lib/security/csrf.js
@@ -57,20 +57,16 @@ exports.validate = function(req, token) {
};
exports.middleware = {
-
init: function(req, res, next) {
res.locals[exports.LOCAL_KEY] = exports.LOCAL_VALUE;
exports.getToken(req, res);
next();
},
-
validate: function(req, res, next) {
-
// Bail on safe methods
if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') {
return next();
}
-
// Validate token
if (exports.validate(req)) {
next();
@@ -78,7 +74,5 @@ exports.middleware = {
res.statusCode = 403;
next(new Error('CSRF token mismatch'));
}
-
- }
-
+ },
};
diff --git a/lib/updateHandler.js b/lib/updateHandler.js
index b45dfae993..921d8f812d 100644
--- a/lib/updateHandler.js
+++ b/lib/updateHandler.js
@@ -66,7 +66,7 @@ UpdateHandler.prototype.addValidationError = function(path, msg, type) {
name: 'ValidatorError',
path: path,
message: msg,
- type: type || 'required'
+ type: type || 'required',
};
return this;
};
@@ -154,13 +154,13 @@ UpdateHandler.prototype.process = function(data, options, callback) {
this.req.flash('error', {
type: 'ValidationError',
title: options.errorMessage,
- list: _.pluck(validationErrors, 'message')
+ list: _.pluck(validationErrors, 'message'),
});
}
callback({
message: 'Validation failed',
name: 'ValidationError',
- errors: validationErrors
+ errors: validationErrors,
}, this.item, this);
} else if (actionQueue.length) {
// TODO: parallel queue handling for cloudinary uploads?
@@ -183,7 +183,7 @@ UpdateHandler.prototype.process = function(data, options, callback) {
this.req.flash('error', {
type: 'ValidationError',
title: options.errorMessage,
- list: _.pluck(err.errors, 'message')
+ list: _.pluck(err.errors, 'message'),
});
}
} else {
diff --git a/lib/updates.js b/lib/updates.js
index ceb7e0652e..639ea176ad 100644
--- a/lib/updates.js
+++ b/lib/updates.js
@@ -12,8 +12,10 @@ var _dashes_ = '------------------------------------------------';
// Update Schema - automatically created and managed by Keystone when updates are used
var UpdateModel = new mongoose.Schema({
key: { type: String, index: true },
- appliedOn: { type: Date, default: Date.now }
-}, { collection: keystone.prefixModel('App_Update') });
+ appliedOn: { type: Date, default: Date.now },
+}, {
+ collection: keystone.prefixModel('App_Update'),
+});
mongoose.model('App_Update', UpdateModel);
// Apply method - loads the available updates and applies any that haven't been, in order
diff --git a/server/bindSassMiddleware.js b/server/bindSassMiddleware.js
index 8e481f7b28..605cf70f9b 100644
--- a/server/bindSassMiddleware.js
+++ b/server/bindSassMiddleware.js
@@ -28,11 +28,12 @@ module.exports = function bindSassMiddleware (keystone, app) {
throw e;
}
}
+ var outputStyle = keystone.get('env') === 'production' ? 'compressed' : 'nested';
sassPaths.forEach(function(path) {
app.use(sassMiddleware(_.extend({
src: keystone.expandPath(path),
dest: keystone.expandPath(path),
- outputStyle: keystone.get('env') === 'production' ? 'compressed' : 'nested'
+ outputStyle: outputStyle,
}, sassOptions)));
});
}
diff --git a/server/bindStylusMiddleware.js b/server/bindStylusMiddleware.js
index 1395c82215..216c44524c 100644
--- a/server/bindStylusMiddleware.js
+++ b/server/bindStylusMiddleware.js
@@ -31,7 +31,7 @@ module.exports = function bindStylusMiddleware (keystone, app) {
app.use(stylusMiddleware(_.extend({
src: keystone.expandPath(path),
dest: keystone.expandPath(path),
- compress: keystone.get('env') === 'production'
+ compress: keystone.get('env') === 'production',
}, stylusOptions)));
});
}
diff --git a/server/createComponentRouter.js b/server/createComponentRouter.js
index a8bb11abdf..28c5e65662 100644
--- a/server/createComponentRouter.js
+++ b/server/createComponentRouter.js
@@ -9,20 +9,15 @@ module.exports = function createComponentRouter (routes) {
return function componentRouter (req, res, next) {
match({ routes: routes, location: req.url },
function (error, redirectLocation, renderProps) {
-
if (error) return res.status(500).send(error.message);
-
if (redirectLocation) {
- return res.redirect(302,
- redirectLocation.pathname + redirectLocation.search);
+ return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
}
-
if (renderProps) {
return res.render('default', {
- content: renderToString(React.createElement(RoutingContext, renderProps))
+ content: renderToString(React.createElement(RoutingContext, renderProps)),
});
}
-
next(null);
}
);