From 99c13c02c0d6253601709477c8a1e5617e8906f9 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Sun, 12 May 2013 08:40:59 -0500 Subject: [PATCH 1/6] Initial Grunt configuration --- .jshintrc | 5 ++++ Gruntfile.js | 47 +++++++++++++++++++++++++++++++++++ core/admin/assets/js/tagui.js | 4 +-- core/ghost.js | 4 +-- package.json | 10 ++++++-- 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 .jshintrc create mode 100644 Gruntfile.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..7083b1ad46 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,5 @@ +{ + "node": true, + "browser": true, + "undef": true +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000000..c194f452e3 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,47 @@ + +var configureGrunt = function(grunt) { + + var cfg = { + // JSHint all the things! + jshint2: { + options: { + jshintrc: ".jshintrc" + }, + all: [ + // Lint files in the root, including Gruntfile.js + "*.js", + // Lint core files, but not libs + ["core/**/*.js", "!**/assets/lib/**/*.js"] + ] + }, + + // Unit test all the things! + nodeunit: { + all: ['core/test/ghost/**/test-*.js'] + }, + + // Compile all the SASS! + compass: { + options: { + config: "config.rb" + }, + // No need for config, but separated for future options + admin: {} + } + }; + + grunt.initConfig(cfg); + + grunt.loadNpmTasks("grunt-jshint2"); + grunt.loadNpmTasks("grunt-contrib-nodeunit"); + grunt.loadNpmTasks("grunt-contrib-compass"); + + // Prepare the project for development + // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? + grunt.registerTask("init", ["compass:admin"]); + + // Run tests and lint code + grunt.registerTask("validate", ["jshint2:all", "nodeunit:all"]); +}; + +module.exports = configureGrunt; \ No newline at end of file diff --git a/core/admin/assets/js/tagui.js b/core/admin/assets/js/tagui.js index 2713e8f8d3..fa3e3ca867 100644 --- a/core/admin/assets/js/tagui.js +++ b/core/admin/assets/js/tagui.js @@ -99,8 +99,8 @@ } } else if (e.keyCode === keys.ESC) { suggestions.hide(); - } else if ((e.keyCode === keys.ENTER || e.keyCode === keys.COMMA) - && searchTerm) { // Submit tag using enter or comma key + } else if ((e.keyCode === keys.ENTER || e.keyCode === keys.COMMA)&& searchTerm) { + // Submit tag using enter or comma key e.preventDefault(); if (suggestions.is(":visible") && suggestions.children(".selected").length !== 0) { diff --git a/core/ghost.js b/core/ghost.js index 30be09d74c..b1de1a4148 100644 --- a/core/ghost.js +++ b/core/ghost.js @@ -75,7 +75,7 @@ polyglot: function () { return polyglot; }, paths: function () { return { - 'activeTheme': __dirname + '/../content/' + config.themeDir + '/' + config.activeTheme + '/', + 'activeTheme': path.resolve(__dirname + '/../content/' + config.themeDir + '/' + config.activeTheme + '/'), 'adminViews': __dirname + '/admin/views/', 'lang': __dirname + '/lang/' }; @@ -158,7 +158,7 @@ )); app.set('views', self.paths().activeTheme); } else { - app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + '/partials'})); + app.engine('hbs', hbs.express3({partialsDir: self.paths().adminViews + 'partials'})); app.set('views', self.paths().adminViews); app.use('/core/admin/assets', express['static'](path.join(__dirname, '/admin/assets'))); } diff --git a/package.json b/package.json index ae33d32f32..12531f82c1 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,17 @@ "css": "*", "moment": "*", "underscore": "*", - "nodeunit": "*", "showdown": "*", "node-polyglot": "*", "sqlite3": "2.1.7", "jugglingdb": "0.2.x", "jugglingdb-sqlite3": "git+https://github.com/jugglingdb/sqlite3-adapter.git#master" + }, + "devDependencies": { + "nodeunit": "*", + "grunt": "~0.4.1", + "grunt-contrib-nodeunit": "~0.1.2", + "grunt-jshint2": "~0.1.1", + "grunt-contrib-compass": "~0.2.0" } -} \ No newline at end of file +} From 6da08eaf3c3bf9553762644bb12850497b339db3 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Mon, 13 May 2013 14:18:20 -0500 Subject: [PATCH 2/6] Make stricter jshint rules, convert tabs to spaces --- .jshintrc | 11 +++- Gruntfile.js | 72 ++++++++++----------- core/admin/assets/js/settings.js | 2 +- core/admin/assets/js/tagui.js | 2 +- core/shared/models/dataProvider.juggling.js | 14 ++-- 5 files changed, 53 insertions(+), 48 deletions(-) diff --git a/.jshintrc b/.jshintrc index 7083b1ad46..96b507fb98 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,5 +1,10 @@ { - "node": true, - "browser": true, - "undef": true + "node": true, + "browser": true, + "indent": 4, + "trailing": true, + "eqeqeq": true, + "undef": true, + "nomen": true, + "white": true } \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index c194f452e3..a1affdd06d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,47 +1,47 @@ -var configureGrunt = function(grunt) { +var configureGrunt = function (grunt) { - var cfg = { - // JSHint all the things! - jshint2: { - options: { - jshintrc: ".jshintrc" - }, - all: [ - // Lint files in the root, including Gruntfile.js - "*.js", - // Lint core files, but not libs - ["core/**/*.js", "!**/assets/lib/**/*.js"] - ] - }, + var cfg = { + // JSHint all the things! + jshint2: { + options: { + jshintrc: ".jshintrc" + }, + all: [ + // Lint files in the root, including Gruntfile.js + "*.js", + // Lint core files, but not libs + ["core/**/*.js", "!**/assets/lib/**/*.js"] + ] + }, - // Unit test all the things! - nodeunit: { - all: ['core/test/ghost/**/test-*.js'] - }, + // Unit test all the things! + nodeunit: { + all: ['core/test/ghost/**/test-*.js'] + }, - // Compile all the SASS! - compass: { - options: { - config: "config.rb" - }, - // No need for config, but separated for future options - admin: {} - } - }; + // Compile all the SASS! + compass: { + options: { + config: "config.rb" + }, + // No need for config, but separated for future options + admin: {} + } + }; - grunt.initConfig(cfg); + grunt.initConfig(cfg); - grunt.loadNpmTasks("grunt-jshint2"); - grunt.loadNpmTasks("grunt-contrib-nodeunit"); - grunt.loadNpmTasks("grunt-contrib-compass"); + grunt.loadNpmTasks("grunt-jshint2"); + grunt.loadNpmTasks("grunt-contrib-nodeunit"); + grunt.loadNpmTasks("grunt-contrib-compass"); - // Prepare the project for development - // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? - grunt.registerTask("init", ["compass:admin"]); + // Prepare the project for development + // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? + grunt.registerTask("init", ["compass:admin"]); - // Run tests and lint code - grunt.registerTask("validate", ["jshint2:all", "nodeunit:all"]); + // Run tests and lint code + grunt.registerTask("validate", ["jshint2:all", "nodeunit:all"]); }; module.exports = configureGrunt; \ No newline at end of file diff --git a/core/admin/assets/js/settings.js b/core/admin/assets/js/settings.js index 8f458d93e4..014cefb87a 100644 --- a/core/admin/assets/js/settings.js +++ b/core/admin/assets/js/settings.js @@ -14,7 +14,7 @@ }; - $(document).ready(function() { + $(document).ready(function () { $('.settings-menu li').on('click', changePage); }); diff --git a/core/admin/assets/js/tagui.js b/core/admin/assets/js/tagui.js index fa3e3ca867..51a933141d 100644 --- a/core/admin/assets/js/tagui.js +++ b/core/admin/assets/js/tagui.js @@ -99,7 +99,7 @@ } } else if (e.keyCode === keys.ESC) { suggestions.hide(); - } else if ((e.keyCode === keys.ENTER || e.keyCode === keys.COMMA)&& searchTerm) { + } else if ((e.keyCode === keys.ENTER || e.keyCode === keys.COMMA) && searchTerm) { // Submit tag using enter or comma key e.preventDefault(); if (suggestions.is(":visible") && suggestions.children(".selected").length !== 0) { diff --git a/core/shared/models/dataProvider.juggling.js b/core/shared/models/dataProvider.juggling.js index e5a147c5da..318ce90a3b 100644 --- a/core/shared/models/dataProvider.juggling.js +++ b/core/shared/models/dataProvider.juggling.js @@ -40,8 +40,8 @@ var posts = JSON.parse(data), post; - _.each(posts, function (_post) { - post = new schema.models.Post(_post); + _.each(posts, function (postData) { + post = new schema.models.Post(postData); post.preCreate(function () { post.save(function (error, data) { @@ -112,8 +112,8 @@ * @param post * @param callback */ - DataProvider.prototype.posts.add = function (_post, callback) { - var post = new schema.models.Post(_post); + DataProvider.prototype.posts.add = function (postData, callback) { + var post = new schema.models.Post(postData); post.preCreate(function () { post.save(callback); @@ -125,9 +125,9 @@ * @param post * @param callback */ - DataProvider.prototype.posts.edit = function (_post, callback) { - schema.models.Post.findOne({where: {id: _post.id}}, function (error, post) { - post = _.extend(post, _post); + DataProvider.prototype.posts.edit = function (postData, callback) { + schema.models.Post.findOne({where: {id: postData.id}}, function (error, post) { + post = _.extend(post, postData); schema.models.Post.updateOrCreate(post, callback); }); From 13e7a51bb78a1c2e73d14a2f0ef6a0ff37d6488b Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Mon, 13 May 2013 15:19:40 -0500 Subject: [PATCH 3/6] Add correct nomen setting and revert _post changes --- .jshintrc | 2 +- core/shared/models/dataProvider.juggling.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.jshintrc b/.jshintrc index 96b507fb98..c4936ccd81 100644 --- a/.jshintrc +++ b/.jshintrc @@ -5,6 +5,6 @@ "trailing": true, "eqeqeq": true, "undef": true, - "nomen": true, + "nomen": false, "white": true } \ No newline at end of file diff --git a/core/shared/models/dataProvider.juggling.js b/core/shared/models/dataProvider.juggling.js index 318ce90a3b..e5a147c5da 100644 --- a/core/shared/models/dataProvider.juggling.js +++ b/core/shared/models/dataProvider.juggling.js @@ -40,8 +40,8 @@ var posts = JSON.parse(data), post; - _.each(posts, function (postData) { - post = new schema.models.Post(postData); + _.each(posts, function (_post) { + post = new schema.models.Post(_post); post.preCreate(function () { post.save(function (error, data) { @@ -112,8 +112,8 @@ * @param post * @param callback */ - DataProvider.prototype.posts.add = function (postData, callback) { - var post = new schema.models.Post(postData); + DataProvider.prototype.posts.add = function (_post, callback) { + var post = new schema.models.Post(_post); post.preCreate(function () { post.save(callback); @@ -125,9 +125,9 @@ * @param post * @param callback */ - DataProvider.prototype.posts.edit = function (postData, callback) { - schema.models.Post.findOne({where: {id: postData.id}}, function (error, post) { - post = _.extend(post, postData); + DataProvider.prototype.posts.edit = function (_post, callback) { + schema.models.Post.findOne({where: {id: _post.id}}, function (error, post) { + post = _.extend(post, _post); schema.models.Post.updateOrCreate(post, callback); }); From b88e69a3ccb163309b6746b46f2f4df821d17824 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Tue, 14 May 2013 10:04:22 -0500 Subject: [PATCH 4/6] Switch to grunt-jslint --- Gruntfile.js | 84 +++++++++++++++++++++++++---------------------- core/ghost.js | 2 +- core/lang/i18n.js | 3 ++ package.json | 4 +-- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a1affdd06d..4da53bbd65 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,47 +1,53 @@ +(function () { + "use strict"; -var configureGrunt = function (grunt) { + var configureGrunt = function (grunt) { - var cfg = { - // JSHint all the things! - jshint2: { - options: { - jshintrc: ".jshintrc" + var cfg = { + // JSLint all the things! + jslint: { + directives: { + nomen: true, + todo: true, + predef: ["__dirname", "module", "exports", "require", "process", "document", "console"] + }, + files: [ + // Lint files in the root, including Gruntfile.js + "*.js", + // Lint core files, but not libs + ["core/**/*.js", "!**/assets/lib/**/*.js"] + ] }, - all: [ - // Lint files in the root, including Gruntfile.js - "*.js", - // Lint core files, but not libs - ["core/**/*.js", "!**/assets/lib/**/*.js"] - ] - }, - // Unit test all the things! - nodeunit: { - all: ['core/test/ghost/**/test-*.js'] - }, - - // Compile all the SASS! - compass: { - options: { - config: "config.rb" + // Unit test all the things! + nodeunit: { + all: ['core/test/ghost/**/test-*.js'] }, - // No need for config, but separated for future options - admin: {} - } + + // Compile all the SASS! + compass: { + options: { + config: "config.rb" + }, + // No need for config, but separated for future options + admin: {} + } + }; + + grunt.initConfig(cfg); + + grunt.loadNpmTasks("grunt-jslint"); + grunt.loadNpmTasks("grunt-contrib-nodeunit"); + grunt.loadNpmTasks("grunt-contrib-compass"); + + // Prepare the project for development + // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? + grunt.registerTask("init", ["compass:admin"]); + + // Run tests and lint code + grunt.registerTask("validate", ["jslint", "nodeunit:all"]); }; - grunt.initConfig(cfg); + module.exports = configureGrunt; - grunt.loadNpmTasks("grunt-jshint2"); - grunt.loadNpmTasks("grunt-contrib-nodeunit"); - grunt.loadNpmTasks("grunt-contrib-compass"); - - // Prepare the project for development - // TODO: Git submodule init/update (https://github.com/jaubourg/grunt-update-submodules)? - grunt.registerTask("init", ["compass:admin"]); - - // Run tests and lint code - grunt.registerTask("validate", ["jshint2:all", "nodeunit:all"]); -}; - -module.exports = configureGrunt; \ No newline at end of file +}()); \ No newline at end of file diff --git a/core/ghost.js b/core/ghost.js index b1de1a4148..d227f84a0d 100644 --- a/core/ghost.js +++ b/core/ghost.js @@ -75,7 +75,7 @@ polyglot: function () { return polyglot; }, paths: function () { return { - 'activeTheme': path.resolve(__dirname + '/../content/' + config.themeDir + '/' + config.activeTheme + '/'), + 'activeTheme': __dirname + '/../content/' + config.themeDir + '/' + config.activeTheme + '/', 'adminViews': __dirname + '/admin/views/', 'lang': __dirname + '/lang/' }; diff --git a/core/lang/i18n.js b/core/lang/i18n.js index 07c9bba35f..7c173875c4 100644 --- a/core/lang/i18n.js +++ b/core/lang/i18n.js @@ -19,6 +19,9 @@ if (lang === 'en') { // TODO: do stuff here to optimise for en + + // Make jslint empty block error go away + lang = 'en'; } /** TODO potentially use req.acceptedLanguages rather than the default diff --git a/package.json b/package.json index 07951e159d..dfbc2bdea3 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-nodeunit": "~0.1.2", - "grunt-jshint2": "~0.1.1", "grunt-contrib-compass": "~0.2.0", - "nodeunit": "*" + "nodeunit": "*", + "grunt-jslint": "~0.2.5a" } } From 8ecb8a7d671539419a9a28519aa8b2cb56afdfa6 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Tue, 14 May 2013 10:07:41 -0500 Subject: [PATCH 5/6] Remove predefined globals list in favor of node:true and browser:true --- Gruntfile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 4da53bbd65..0e42681150 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,9 +7,10 @@ // JSLint all the things! jslint: { directives: { + node: true, + browser: true, nomen: true, - todo: true, - predef: ["__dirname", "module", "exports", "require", "process", "document", "console"] + todo: true }, files: [ // Lint files in the root, including Gruntfile.js From d341805bd8d4c9e354e90f9d91b481876ef66060 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Tue, 14 May 2013 11:11:00 -0500 Subject: [PATCH 6/6] Remove unnecessary .jshintrc --- .jshintrc | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index c4936ccd81..0000000000 --- a/.jshintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node": true, - "browser": true, - "indent": 4, - "trailing": true, - "eqeqeq": true, - "undef": true, - "nomen": false, - "white": true -} \ No newline at end of file