Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 97 #607

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : false, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 2, // {int} Number of spaces to use for indentation
"latedef" : false, // true: Require variables/functions to be defined before being used
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` & `--`
"quotmark" : false, // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"trailing" : false, // true: Prohibit trailing whitespaces
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements"
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : true, // Web Browser (window, document, etc)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jquery" : false, // jQuery
"mootools" : false, // MooTools
"node" : false, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"rhino" : false, // Rhino
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Legacy
"nomen" : false, // true: Prohibit dangling `_` in variables
"onevar" : false, // true: Allow only one `var` statement per function
"passfail" : false, // true: Stop on first error
"white" : false, // true: Check against strict whitespace and indentation rules

// Custom Globals
"globals" : ["require", "module"] // additional predefined global variables
}
41 changes: 41 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function (grunt) {

'use strict';

var pkg = require("./package.json");

pkg.timestamp = new Date().getTime();

grunt.initConfig({
pkg: pkg,
clean: require('./tasks/clean.js'),
copy: require('./tasks/copy.js'),
cssmin: require('./tasks/cssmin.js'),
htmlmin: require('./tasks/htmlmin.js'),
jshint: require('./tasks/jshint.js'),
uglify: require('./tasks/uglify.js')
});

grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');

// called without any further parameter: 'grunt'
grunt.registerTask('default', ['jshint']);
// build: 'grunt build'
grunt.registerTask('build', [
//check jss
'jshint',
//clean old build
'clean',
//copy root and img files
'copy',
//minify html/js/css
'htmlmin',
'uglify',
'cssmin'
]);
};
8 changes: 4 additions & 4 deletions libs/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getThreshold (model, content, author, callback) {
var threshold = thresholds[model.modelName] * (author.role < 4 ? 2 : 1);

// Calculate karma and add it to the threshold
getKarma(author, maxKarma, function (karma) {
getKarma(author, maxKarma, function (karma) {
return callback(threshold + karma);
});
}
Expand All @@ -91,17 +91,17 @@ function saveContent (model, content, author, flags, callback) {
exports.saveContent = saveContent;

function flag (model, content, user, author, callback) {
var flag = new Flag({
var fl = new Flag({
'model': model.modelName,
'_contentId': content._id,
'_userId': user._id
});

flag.save(function (err, flag) {
fl.save(function (err, flag) {
if (!content.flags) { content.flags = 0; }
if (!content.flagged) { content.flagged = false; }

saveContent(model, content, author, user.role < 4 ? 2 : 1, callback)
saveContent(model, content, author, user.role < 4 ? 2 : 1, callback);
});
}

Expand Down
12 changes: 7 additions & 5 deletions libs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ exports.formatDate = function (date) {
}

if (difference > week) {
ret = date.getDate() + ' '
+ months[date.getMonth()] + ' '
+ date.getFullYear();
ret = date.getDate() +
' ' +
months[date.getMonth()] +
' ' +
date.getFullYear();
} else if (difference > day) {
days = Math.round(difference / day);
if (days <= 1) {
Expand All @@ -48,7 +50,7 @@ exports.formatDate = function (date) {
}

return ret;
}
};

// Create an object with no properties
exports.nil = function (obj) {
Expand All @@ -59,7 +61,7 @@ exports.nil = function (obj) {
exports.forIn(obj, function (val, key) {
nilObj[key] = val;
});

return nilObj;
};

Expand Down
44 changes: 22 additions & 22 deletions libs/modelsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var formatDate = require('./helpers').formatDate;
var listSize = 10;

// /scriptlist/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of scripts and build the options object
// Get a list of scripts and build the options object
// for the corresponding Mustache partial template
exports.listScripts = function (query, params, baseUrl, callback) {

Expand Down Expand Up @@ -41,7 +41,7 @@ exports.listScripts = function (query, params, baseUrl, callback) {
var name = null;
scriptsList.scripts = [];
scriptsList.headings = [];
scriptsList.hasAuthor = params[4] ?
scriptsList.hasAuthor = params[4] ?
params[4].indexOf('author') === -1 : true;

scripts.forEach(function (script) {
Expand All @@ -52,7 +52,7 @@ exports.listScripts = function (query, params, baseUrl, callback) {

editUrl.shift();

scriptsList.scripts.push({
scriptsList.scripts.push({
name: script.name,
author: script.author,
description: script.meta.description || '',
Expand All @@ -72,7 +72,7 @@ exports.listScripts = function (query, params, baseUrl, callback) {
heading = headings[name];

if (orderBy === name) {
heading.direction = '/dir/' +
heading.direction = '/dir/' +
(direction === 'asc' ? 'desc' : 'asc');
} else {
heading.direction = '';
Expand All @@ -82,22 +82,22 @@ exports.listScripts = function (query, params, baseUrl, callback) {
scriptsList.headings.push(heading);
}*/

scriptsList.baseUrl = baseUrl + (query.isLib === true ?
scriptsList.baseUrl = baseUrl + (query.isLib === true ?
'/liblist' : '/scriptlist');
callback(scriptsList);
});
};

// /userlist/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of users and build the options object
// Get a list of users and build the options object
// for the corresponding Mustache partial template
exports.listUsers = function (query, params, baseUrl, callback) {
listModels(User, query, params, ['name'],
function (users, usersList) {
usersList.users = [];

users.forEach(function (user) {
usersList.users.push({
usersList.users.push({
name: user.name,
url: '/users/' + user.name,
});
Expand All @@ -109,7 +109,7 @@ exports.listUsers = function (query, params, baseUrl, callback) {
};

// /list/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of removed content and build the options object
// Get a list of removed content and build the options object
// for the corresponding Mustache partial template
exports.listRemoved = function (query, params, baseUrl, callback) {
listModels(Remove, query, params, ['removed'],
Expand All @@ -121,14 +121,14 @@ exports.listRemoved = function (query, params, baseUrl, callback) {
var key = null;
var contentArr = [];
var val = null;

for (key in content) {
val = content[key];
val = val && typeof val === 'object' ? JSON.stringify(val) : val;
contentArr.push({ 'key': key, 'value': val });
}

removedList.removed.push({
removedList.removed.push({
remover: result.removerName,
removed: formatDate(result.removed),
reason: result.reason,
Expand All @@ -142,15 +142,15 @@ exports.listRemoved = function (query, params, baseUrl, callback) {
};

// /groups/list/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of groups and build the options object
// Get a list of groups and build the options object
// for the corresponding Mustache partial template
exports.listGroups = function (query, params, baseUrl, callback) {
listModels(Group, query, params, ['rating'],
function (groups, groupsList) {
groupsList.groups = [];

groups.forEach(function (group) {
groupsList.groups.push({
groupsList.groups.push({
name: group.name,
url: '/group/' + group.name.replace(/\s+/g, '_'),
size: group._scriptIds.length,
Expand Down Expand Up @@ -178,15 +178,15 @@ exports.listGroups = function (query, params, baseUrl, callback) {
};

// /list/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of discussions and build the options object
// Get a list of discussions and build the options object
// for the corresponding Mustache partial template
exports.listDiscussions = function (query, params, baseUrl, callback) {
listModels(Discussion, query, params, ['updated', 'rating'],
function (discussions, discussionsList) {
discussionsList.discussions = [];

discussions.forEach(function (discussion) {
discussionsList.discussions.push({
discussionsList.discussions.push({
topic: discussion.topic,
comments: discussion.comments,
author: discussion.author,
Expand All @@ -195,8 +195,8 @@ exports.listDiscussions = function (query, params, baseUrl, callback) {
discussion.lastCommentor : null,
updated: formatDate(discussion.updated),
rating: discussion.rating,
url: discussion.path
+ (discussion.duplicateId ? '_' + discussion.duplicateId : '')
url: discussion.path +
(discussion.duplicateId ? '_' + discussion.duplicateId : '')
});
});

Expand All @@ -206,15 +206,15 @@ exports.listDiscussions = function (query, params, baseUrl, callback) {
};

// /list/size/:size/sort/:orderBy/dir/:direction/page/:page
// Get a list of comments and build the options object
// Get a list of comments and build the options object
// for the corresponding Mustache partial template
exports.listComments = function (query, params, baseUrl, callback) {
listModels(Comment, query, params, ['created'],
function (comments, commentsList) {
commentsList.comments = [];

comments.forEach(function (comment) {
commentsList.comments.push({
commentsList.comments.push({
author: comment.author,
content: renderMd(comment.content),
created: formatDate(comment.created),
Expand All @@ -228,7 +228,7 @@ exports.listComments = function (query, params, baseUrl, callback) {
});
};

// options = {
// options = {
// size: (Number), orderBy: (String or Array or Object),
// direction: (String), page: (Number), omit: (Array)
// }
Expand Down Expand Up @@ -266,7 +266,7 @@ function listModels (model, query, options, defaultOrder, callback) {
params.sort[orderBy] = direction;
} else if (orderBy instanceof Array) {
orderBy.forEach(function (order) {
params.sort[order] = -1 !== fields.indexOf(order) &&
params.sort[order] = -1 !== fields.indexOf(order) &&
model.schema.paths[order].instance === 'String' ? 1 : -1;
});
} else if (typeof orderBy === 'object') {
Expand Down Expand Up @@ -297,7 +297,7 @@ function listModels (model, query, options, defaultOrder, callback) {
model.find(query, omit, params,
function (err, models) {
var list = {};
if (!models) { models = [] }
if (!models) { models = []; }
if (size < 0) { size = models.length; }
orderBy = typeof orderBy === 'string' ? orderBy : '';
direction = direction === 1 ? 'asc' : 'desc';
Expand All @@ -315,4 +315,4 @@ function listModels (model, query, options, defaultOrder, callback) {
if (list.next) { models.pop(); }
callback(models, list);
});
};
}
2 changes: 1 addition & 1 deletion libs/passportVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ exports.verify = function (id, strategy, username, loggedIn, done) {
return done(null, user);
}
});
}
};
Loading