diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..f6b9638a10 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ +coverage/ +tmp/ \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..ff93f650e8 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,45 @@ +{ + "extends": "eslint:recommended", + "root": true, + "rules": { + "curly": [2, "multi-line"], + "no-console": 0, + "no-path-concat": 2, + "handle-callback-err": 2, + "no-use-before-define": [2, "nofunc"], + "no-shadow-restricted-names": 2, + "block-scoped-var": 2, + "dot-notation": 2, + "eqeqeq": [2, "allow-null"], + "no-else-return": 1, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-implied-eval": 2, + "no-lone-blocks": 2, + "no-loop-func": 2, + "no-multi-spaces": 2, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-new-wrappers": 2, + "no-redeclare": 2, + "no-return-assign": 2, + "no-throw-literal": 2, + "no-unused-expressions": [2, { + "allowShortCircuit": true, + "allowTernary": true + }], + "no-useless-call": 2, + "no-useless-concat": 2, + "no-with": 2, + "radix": 2, + "no-self-compare": 2, + "no-unused-vars": [2, { + "vars": "all", + "args": "none" + }], + "strict": [2, "global"] + }, + "env": { + "node": true + } +} \ No newline at end of file diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000000..e9b94ed1f4 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,85 @@ +{ + "excludeFiles": ["node_modules/**", "coverage/**", "tmp/**"], + "validateIndentation": 2, + "validateLineBreaks": "LF", + "validateQuoteMarks": "'", + "requireSemicolons": true, + "disallowEmptyBlocks": true, + "disallowKeywordsOnNewLine": ["else"], + "disallowKeywords": ["with"], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleLineBreaks": true, + "disallowMultipleLineStrings": true, + "disallowMultipleVarDecl": "exceptUndefined", + "disallowNewlineBeforeBlockStatements": true, + "disallowOperatorBeforeLineBreak": ["."], + "disallowSpaceBeforeBinaryOperators": [","], + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforeComma": true, + "disallowSpaceBeforePostfixUnaryOperators": true, + "disallowSpaceBeforeSemicolon": true, + "disallowSpacesInCallExpression": true, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideParentheses": true, + "disallowSpacesInsideParenthesizedExpression": { + "allExcept": [ "{", "}" ] + }, + "disallowTrailingComma": true, + "disallowTrailingWhitespace": true, + "disallowYodaConditions": true, + "requireBlocksOnNewline": true, + "requireCapitalizedConstructors": true, + "requireCommaBeforeLineBreak": true, + "requireCurlyBraces": [ + "for", + "while", + "do", + "try", + "catch" + ], + "requireDotNotation": true, + "requireLineBreakAfterVariableAssignment": true, + "requireLineFeedAtFileEnd": true, + "requirePaddingNewLinesAfterBlocks": true, + "requirePaddingNewLinesAfterUseStrict": true, + "requireParenthesesAroundIIFE": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceAfterKeywords": [ + "do", + "for", + "if", + "else", + "switch", + "case", + "try", + "catch", + "void", + "while", + "with", + "return", + "typeof" + ], + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBetweenArguments": true, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInConditionalExpression": true, + "requireSpacesInForStatement": true, + "requireSpacesInFunctionDeclaration": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "validateNewlineAfterArrayElements": true, + "validateParameterSeparator": ", ", + "disallowMultipleSpaces": true +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 637bb4ac37..0000000000 --- a/.jshintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "eqnull": true, - "expr": true, - "indent": 2, - "node": true, - "trailing": true, - "quotmark": "single", - "undef": true, - "strict": true, - "unused": "vars", - "globals": { - "Promise": true - } -} \ No newline at end of file diff --git a/.npmignore b/.npmignore index 7c092c2113..c1cce88e47 100644 --- a/.npmignore +++ b/.npmignore @@ -2,7 +2,6 @@ test/ tmp/ coverage/ *.log -.jshintrc .travis.yml gulpfile.js .idea/ diff --git a/.travis.yml b/.travis.yml index 7203df198c..09e2c20d0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,21 @@ language: node_js +sudo: false + +cache: + apt: true + directories: + - node_modules + node_js: - "0.10" - "0.12" - - iojs + - "4" script: - - npm test + - npm run eslint + - npm run jscs + - npm run test-cov after_script: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 87f02ab265..2ec9b1d8dd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,22 +5,13 @@ init: # Test against these versions of Node.js. environment: matrix: - # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - # io.js - - nodejs_version: "1" - -# Allow failing jobs for bleeding-edge Node.js versions. -matrix: - allow_failures: - - nodejs_version: "1" + - nodejs_version: "4" # Install scripts. (runs after repo cloning) install: - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) - - cmd: npm install -g npm@2 - - set PATH=%APPDATA%\npm;%PATH% + - ps: Install-Product node $env:nodejs_version - npm install # Post-install test scripts. @@ -29,7 +20,9 @@ test_script: - node --version - npm --version # Run tests - - npm test + - npm run eslint + - npm run jscs + - npm run test-cov # Don't actually build. build: off diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index a149dbee1e..0000000000 --- a/gulpfile.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); -var $ = require('gulp-load-plugins')(); -var del = require('del'); - -var lib = 'lib/**/*.js'; -var test = 'test/scripts/**/*.js'; - -gulp.task('coverage', function(){ - return gulp.src(lib) - .pipe($.istanbul()) - .pipe($.istanbul.hookRequire()); -}); - -gulp.task('coverage:clean', function(callback){ - del(['coverage/**/*'], callback); -}); - -function mochaStream(){ - return gulp.src('test/index.js', {read: false}) - .pipe($.mocha({ - reporter: 'spec' - })); -} - -gulp.task('mocha', ['coverage'], function(){ - return mochaStream() - .pipe($.istanbul.writeReports()); -}); - -gulp.task('mocha:nocov', function(){ - return mochaStream(); -}); - -gulp.task('jshint', function(){ - return gulp.src(lib) - .pipe($.jshint()) - .pipe($.jshint.reporter('jshint-stylish')) - .pipe($.jshint.reporter('fail')); -}); - -gulp.task('watch', function(){ - gulp.watch(lib, ['mocha', 'jshint']); - gulp.watch(['test/**/*.js', test], ['mocha']); -}); - -gulp.task('test', ['mocha', 'jshint']); \ No newline at end of file diff --git a/lib/box/file.js b/lib/box/file.js index c37d36ca0e..663ddcd1ff 100644 --- a/lib/box/file.js +++ b/lib/box/file.js @@ -6,7 +6,7 @@ var Promise = require('bluebird'); var escapeBOM = fs.escapeBOM; var escapeEOL = fs.escapeEOL; -function File(data){ +function File(data) { this.source = data.source; this.path = data.path; this.type = data.type; @@ -15,7 +15,7 @@ function File(data){ this.stats = data.stats; } -function wrapReadOptions(options){ +function wrapReadOptions(options) { options = options || {}; if (typeof options === 'string') options = {encoding: options}; if (!options.hasOwnProperty('encoding')) options.encoding = 'utf8'; @@ -25,12 +25,12 @@ function wrapReadOptions(options){ return options; } -function escapeContent(str){ +function escapeContent(str) { return escapeBOM(escapeEOL(str)); } -File.prototype.read = function(options, callback){ - if (!callback && typeof options === 'function'){ +File.prototype.read = function(options, callback) { + if (!callback && typeof options === 'function') { callback = options; options = {}; } @@ -40,8 +40,8 @@ File.prototype.read = function(options, callback){ options = wrapReadOptions(options); - return new Promise(function(resolve, reject){ - if (!options.cache || !content){ + return new Promise(function(resolve, reject) { + if (!options.cache || !content) { return fs.readFile(self.source, options).then(resolve, reject); } @@ -55,12 +55,12 @@ File.prototype.read = function(options, callback){ }).nodeify(callback); }; -File.prototype.readSync = function(options){ +File.prototype.readSync = function(options) { var content = this.content; options = wrapReadOptions(options); - if (!options.cache || !content){ + if (!options.cache || !content) { return fs.readFileSync(this.source, options); } @@ -73,8 +73,8 @@ File.prototype.readSync = function(options){ return result; }; -File.prototype.stat = function(options, callback){ - if (!callback && typeof options === 'function'){ +File.prototype.stat = function(options, callback) { + if (!callback && typeof options === 'function') { callback = options; options = {}; } @@ -85,14 +85,14 @@ File.prototype.stat = function(options, callback){ var cache = options.hasOwnProperty('cache') ? options.cache : true; var self = this; - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { if (stats && cache) return resolve(stats); fs.stat(self.source).then(resolve, reject); }).nodeify(callback); }; -File.prototype.statSync = function(options){ +File.prototype.statSync = function(options) { options = options || {}; var cache = options.hasOwnProperty('cache') ? options.cache : true; @@ -103,4 +103,4 @@ File.prototype.statSync = function(options){ return fs.statSync(this.source); }; -module.exports = File; \ No newline at end of file +module.exports = File; diff --git a/lib/box/index.js b/lib/box/index.js index b9aace8c9c..03f0e7a8cb 100644 --- a/lib/box/index.js +++ b/lib/box/index.js @@ -14,17 +14,17 @@ var escapeRegExp = util.escapeRegExp; var join = pathFn.join; var sep = pathFn.sep; -var defaultPattern = new Pattern(function(){ +var defaultPattern = new Pattern(function() { return {}; }); -function Box(ctx, base, options){ +function Box(ctx, base, options) { this.options = _.extend({ persistent: true, ignored: /[\/\\]\./ }, options); - if (base.substring(base.length - 1) !== sep){ + if (base.substring(base.length - 1) !== sep) { base += sep; } @@ -35,7 +35,7 @@ function Box(ctx, base, options){ this.watcher = null; this.Cache = ctx.model('Cache'); - var _File = this.File = function(data){ + var _File = this.File = function(data) { File.call(this, data); }; @@ -43,15 +43,15 @@ function Box(ctx, base, options){ _File.prototype.box = this; - _File.prototype.render = function(options, callback){ - if (!callback && typeof options === 'function'){ + _File.prototype.render = function(options, callback) { + if (!callback && typeof options === 'function') { callback = options; options = {}; } var self = this; - return this.read().then(function(content){ + return this.read().then(function(content) { return ctx.render.render({ text: content, path: self.source @@ -59,7 +59,7 @@ function Box(ctx, base, options){ }).nodeify(callback); }; - _File.prototype.renderSync = function(options){ + _File.prototype.renderSync = function(options) { return ctx.render.renderSync({ text: this.readSync(), path: this.source @@ -67,13 +67,13 @@ function Box(ctx, base, options){ }; } -function escapeBackslash(path){ +function escapeBackslash(path) { // Replace backslashes on Windows return path.replace(/\\/g, '/'); } -Box.prototype.addProcessor = function(pattern, fn){ - if (!fn && typeof pattern === 'function'){ +Box.prototype.addProcessor = function(pattern, fn) { + if (!fn && typeof pattern === 'function') { fn = pattern; pattern = defaultPattern; } @@ -87,16 +87,16 @@ Box.prototype.addProcessor = function(pattern, fn){ }); }; -Box.prototype.process = function(callback){ +Box.prototype.process = function(callback) { var self = this; - return fs.exists(this.base).then(function(exist){ + return fs.exists(this.base).then(function(exist) { if (!exist) return; return self._loadFiles(); - }).then(function(files){ + }).then(function(files) { if (!files || !files.length) return; - return self._process(files).finally(function(){ + return self._process(files).finally(function() { files.length = 0; }); }).nodeify(callback); @@ -104,39 +104,39 @@ Box.prototype.process = function(callback){ Box.prototype.load = Box.prototype.process; -function listDir(path){ - return fs.listDir(path).catch(function(err){ +function listDir(path) { + return fs.listDir(path).catch(function(err) { // Return an empty array if path does not exist if (err.cause.code === 'ENOENT') return []; throw err; }).map(escapeBackslash); } -Box.prototype._getExistingFiles = function(){ +Box.prototype._getExistingFiles = function() { var base = this.base; var ctx = this.context; var relativeBase = escapeBackslash(base.substring(ctx.base_dir.length)); var regex = new RegExp('^' + escapeRegExp(relativeBase)); var baseLength = relativeBase.length; - return this.Cache.find({_id: regex}).map(function(item){ + return this.Cache.find({_id: regex}).map(function(item) { return item._id.substring(baseLength); }); }; -Box.prototype._loadFiles = function(){ +Box.prototype._loadFiles = function() { var base = this.base; var self = this; var existed = this._getExistingFiles(); - return listDir(base).then(function(files){ + return listDir(base).then(function(files) { var result = []; // created = files - existed var created = _.difference(files, existed); var i, len, item; - for (i = 0, len = created.length; i < len; i++){ + for (i = 0, len = created.length; i < len; i++) { item = created[i]; result.push({ @@ -145,10 +145,10 @@ Box.prototype._loadFiles = function(){ }); } - for (i = 0, len = existed.length; i < len; i++){ + for (i = 0, len = existed.length; i < len; i++) { item = existed[i]; - if (~files.indexOf(item)){ + if (~files.indexOf(item)) { result.push({ path: item, type: 'update' @@ -162,7 +162,7 @@ Box.prototype._loadFiles = function(){ } return result; - }).map(function(item){ + }).map(function(item) { existed.length = 0; switch (item.type){ @@ -176,20 +176,20 @@ Box.prototype._loadFiles = function(){ }); }; -function getShasum(path){ - return new Promise(function(resolve, reject){ +function getShasum(path) { + return new Promise(function(resolve, reject) { var src = fs.createReadStream(path); var stream = new ShasumStream(); src.pipe(stream) .on('error', reject) - .on('finish', function(){ + .on('finish', function() { resolve(stream.getShasum()); }); }); } -Box.prototype._handleUpdatedFile = function(path){ +Box.prototype._handleUpdatedFile = function(path) { var Cache = this.Cache; var ctx = this.context; var fullPath = join(this.base, path); @@ -197,11 +197,11 @@ Box.prototype._handleUpdatedFile = function(path){ return Promise.all([ getShasum(fullPath), fs.stat(fullPath) - ]).spread(function(shasum, stats){ + ]).spread(function(shasum, stats) { var id = escapeBackslash(fullPath.substring(ctx.base_dir.length)); var cache = Cache.findById(id); - if (!cache){ + if (!cache) { ctx.log.debug('Added: %s', chalk.magenta(id)); return Cache.insert({ @@ -212,33 +212,33 @@ Box.prototype._handleUpdatedFile = function(path){ type: 'create', path: path }); - } else if (cache.shasum === shasum){ + } else if (cache.shasum === shasum) { ctx.log.debug('Unchanged: %s', chalk.magenta(id)); return { type: 'skip', path: path }; - } else { - ctx.log.debug('Updated: %s', chalk.magenta(id)); + } - cache.shasum = shasum; - cache.modified = stats.mtime; + ctx.log.debug('Updated: %s', chalk.magenta(id)); - return cache.save().thenReturn({ - type: 'update', - path: path - }); - } + cache.shasum = shasum; + cache.modified = stats.mtime; + + return cache.save().thenReturn({ + type: 'update', + path: path + }); }); }; -Box.prototype._handleDeletedFile = function(path){ +Box.prototype._handleDeletedFile = function(path) { var fullPath = join(this.base, path); var ctx = this.context; var Cache = this.Cache; - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { var id = escapeBackslash(fullPath.substring(ctx.base_dir.length)); var cache = Cache.findById(id); if (!cache) return resolve(); @@ -251,24 +251,24 @@ Box.prototype._handleDeletedFile = function(path){ }); }; -Box.prototype._process = function(files){ +Box.prototype._process = function(files) { var self = this; var ctx = this.context; var base = this.base; ctx.emit('processBefore', base); - return Promise.map(files, function(item){ + return Promise.map(files, function(item) { return self._dispatch(item); }, {concurrency: 1}) // Set concurrency to 1 to solve sync problem. // This problem must be solved in database someday. - .then(function(){ + .then(function() { ctx.emit('processAfter', base); }); }; -Box.prototype._dispatch = function(item){ +Box.prototype._dispatch = function(item) { var path = item.path; var File = this.File; var self = this; @@ -282,7 +282,7 @@ Box.prototype._dispatch = function(item){ this.processingFiles[path] = true; // Use Promise.reduce to calculate the number of processors executed - return Promise.reduce(this.processors, function(count, processor){ + return Promise.reduce(this.processors, function(count, processor) { // Check whether the path match with the pattern of the processor var params = processor.pattern.match(path); if (!params) return count; @@ -295,30 +295,30 @@ Box.prototype._dispatch = function(item){ }); return Promise.method(processor.process).call(ctx, file).thenReturn(count + 1); - }, 0).then(function(count){ - if (count){ + }, 0).then(function(count) { + if (count) { ctx.log.debug('Processed: %s', chalk.magenta(path)); } - }, function(err){ + }).catch(function(err) { ctx.log.error({err: err}, 'Process failed: %s', chalk.magenta(path)); - }).finally(function(){ + }).then(function() { // Remember to unlock the file self.processingFiles[path] = false; }); }; -Box.prototype.watch = function(callback){ +Box.prototype.watch = function(callback) { var base = this.base; var baseLength = base.length; var self = this; var queue = []; var timer; - function getPath(path){ + function getPath(path) { return escapeBackslash(path.substring(baseLength)); } - function dispatch(data){ + function dispatch(data) { // Stop the timer if (timer) clearTimeout(timer); @@ -329,31 +329,31 @@ Box.prototype.watch = function(callback){ setTimeout(generate, 100); } - function generate(){ + function generate() { var tasks = queue; queue = []; - self._process(tasks).finally(function(){ + self._process(tasks).finally(function() { tasks.length = 0; }); } - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { if (self.isWatching()) return reject(new Error('Watcher has already started.')); self.process().then(resolve, reject); - }).then(function(){ + }).then(function() { return fs.watch(base, self.options); - }).then(function(watcher){ + }).then(function(watcher) { self.watcher = watcher; - watcher.on('add', function(path){ + watcher.on('add', function(path) { self._handleUpdatedFile(getPath(path)).then(dispatch); - }).on('change', function(path){ + }).on('change', function(path) { self._handleUpdatedFile(getPath(path)).then(dispatch); - }).on('unlink', function(path){ + }).on('unlink', function(path) { self._handleDeletedFile(getPath(path)).then(dispatch); - }).on('addDir', function(path){ - fs.listDir(path).map(function(item){ + }).on('addDir', function(path) { + fs.listDir(path).map(function(item) { var filePath = getPath(pathFn.join(path, item)); return self._handleUpdatedFile(filePath).then(dispatch); }); @@ -363,15 +363,15 @@ Box.prototype.watch = function(callback){ }).nodeify(callback); }; -Box.prototype.unwatch = function(){ +Box.prototype.unwatch = function() { if (!this.isWatching()) throw new Error('Watcher hasn\'t started yet.'); this.watcher.close(); this.watcher = null; }; -Box.prototype.isWatching = function(){ +Box.prototype.isWatching = function() { return Boolean(this.watcher); }; -module.exports = Box; \ No newline at end of file +module.exports = Box; diff --git a/lib/box/shasum_stream.js b/lib/box/shasum_stream.js index 976b617507..55416de71e 100644 --- a/lib/box/shasum_stream.js +++ b/lib/box/shasum_stream.js @@ -4,7 +4,7 @@ var Stream = require('stream'); var Transform = Stream.Transform; var crypto = require('crypto'); -function ShasumStream(options){ +function ShasumStream(options) { Transform.call(this, options); this._hash = crypto.createHash('sha1'); @@ -13,20 +13,20 @@ function ShasumStream(options){ require('util').inherits(ShasumStream, Transform); -ShasumStream.prototype._transform = function(chunk, enc, callback){ +ShasumStream.prototype._transform = function(chunk, enc, callback) { var buffer = chunk instanceof Buffer ? chunk : new Buffer(chunk, enc); this._hash.update(buffer); callback(); }; -ShasumStream.prototype._flush = function(callback){ +ShasumStream.prototype._flush = function(callback) { this._shasum = this._hash.digest('hex'); callback(); }; -ShasumStream.prototype.getShasum = function(){ +ShasumStream.prototype.getShasum = function() { return this._shasum; }; -module.exports = ShasumStream; \ No newline at end of file +module.exports = ShasumStream; diff --git a/lib/extend/console.js b/lib/extend/console.js index 0c40fab459..a20a868d1d 100644 --- a/lib/extend/console.js +++ b/lib/extend/console.js @@ -3,29 +3,29 @@ var Promise = require('bluebird'); var abbrev = require('abbrev'); -function Console(){ +function Console() { this.store = {}; this.alias = {}; } -Console.prototype.get = function(name){ +Console.prototype.get = function(name) { name = name.toLowerCase(); return this.store[this.alias[name]]; }; -Console.prototype.list = function(){ +Console.prototype.list = function() { return this.store; }; -Console.prototype.register = function(name, desc, options, fn){ +Console.prototype.register = function(name, desc, options, fn) { if (!name) throw new TypeError('name is required'); - if (!fn){ - if (options){ - if (typeof options === 'function'){ + if (!fn) { + if (options) { + if (typeof options === 'function') { fn = options; - if (typeof desc === 'object'){ // name, options, fn + if (typeof desc === 'object') { // name, options, fn options = desc; desc = ''; } else { // name, desc, fn @@ -36,7 +36,7 @@ Console.prototype.register = function(name, desc, options, fn){ } } else { // name, fn - if (typeof desc === 'function'){ + if (typeof desc === 'function') { fn = desc; options = {}; desc = ''; @@ -46,7 +46,7 @@ Console.prototype.register = function(name, desc, options, fn){ } } - if (fn.length > 1){ + if (fn.length > 1) { fn = Promise.promisify(fn); } else { fn = Promise.method(fn); @@ -59,4 +59,4 @@ Console.prototype.register = function(name, desc, options, fn){ this.alias = abbrev(Object.keys(this.store)); }; -module.exports = Console; \ No newline at end of file +module.exports = Console; diff --git a/lib/extend/deployer.js b/lib/extend/deployer.js index b1d45db882..8d775ada48 100644 --- a/lib/extend/deployer.js +++ b/lib/extend/deployer.js @@ -2,23 +2,23 @@ var Promise = require('bluebird'); -function Deployer(){ +function Deployer() { this.store = {}; } -Deployer.prototype.list = function(){ +Deployer.prototype.list = function() { return this.store; }; -Deployer.prototype.get = function(name){ +Deployer.prototype.get = function(name) { return this.store[name]; }; -Deployer.prototype.register = function(name, fn){ +Deployer.prototype.register = function(name, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); - if (fn.length > 1){ + if (fn.length > 1) { fn = Promise.promisify(fn); } else { fn = Promise.method(fn); @@ -27,4 +27,4 @@ Deployer.prototype.register = function(name, fn){ this.store[name] = fn; }; -module.exports = Deployer; \ No newline at end of file +module.exports = Deployer; diff --git a/lib/extend/filter.js b/lib/extend/filter.js index 3508a38912..620e79e7d0 100644 --- a/lib/extend/filter.js +++ b/lib/extend/filter.js @@ -7,18 +7,18 @@ var typeAlias = { post: 'after_post_render' }; -function Filter(){ +function Filter() { this.store = {}; } -Filter.prototype.list = function(type){ +Filter.prototype.list = function(type) { if (!type) return this.store; return this.store[type] || []; }; -Filter.prototype.register = function(type, fn, priority){ - if (!priority){ - if (typeof type === 'function'){ +Filter.prototype.register = function(type, fn, priority) { + if (!priority) { + if (typeof type === 'function') { priority = fn; fn = type; type = 'after_post_render'; @@ -35,27 +35,27 @@ Filter.prototype.register = function(type, fn, priority){ fn.priority = priority; store.push(fn); - store.sort(function(a, b){ + store.sort(function(a, b) { return a.priority - b.priority; }); }; -Filter.prototype.unregister = function(type, fn){ +Filter.prototype.unregister = function(type, fn) { if (!type) throw new TypeError('type is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); var list = this.list(type); if (!list || !list.length) return; - for (var i = 0, len = list.length; i < len; i++){ - if (list[i] === fn){ + for (var i = 0, len = list.length; i < len; i++) { + if (list[i] === fn) { list.splice(i, 1); break; } } }; -Filter.prototype.exec = function(type, data, options){ +Filter.prototype.exec = function(type, data, options) { options = options || {}; var filters = this.list(type); @@ -64,17 +64,17 @@ Filter.prototype.exec = function(type, data, options){ args.unshift(data); - return Promise.each(filters, function(filter){ - return Promise.method(filter).apply(ctx, args).then(function(result){ + return Promise.each(filters, function(filter) { + return Promise.method(filter).apply(ctx, args).then(function(result) { args[0] = result == null ? data : result; return args[0]; }); - }).then(function(){ + }).then(function() { return args[0]; }); }; -Filter.prototype.execSync = function(type, data, options){ +Filter.prototype.execSync = function(type, data, options) { options = options || {}; var filters = this.list(type); @@ -84,7 +84,7 @@ Filter.prototype.execSync = function(type, data, options){ args.unshift(data); - for (var i = 0, len = filters.length; i < len; i++){ + for (var i = 0, len = filters.length; i < len; i++) { result = filters[i].apply(ctx, args); args[0] = result == null ? data : result; } @@ -92,4 +92,4 @@ Filter.prototype.execSync = function(type, data, options){ return args[0]; }; -module.exports = Filter; \ No newline at end of file +module.exports = Filter; diff --git a/lib/extend/generator.js b/lib/extend/generator.js index fb4b294065..be1d31e352 100644 --- a/lib/extend/generator.js +++ b/lib/extend/generator.js @@ -2,22 +2,22 @@ var Promise = require('bluebird'); -function Generator(){ +function Generator() { this.id = 0; this.store = {}; } -Generator.prototype.list = function(){ +Generator.prototype.list = function() { return this.store; }; -Generator.prototype.get = function(name){ +Generator.prototype.get = function(name) { return this.store[name]; }; -Generator.prototype.register = function(name, fn){ - if (!fn){ - if (typeof name === 'function'){ +Generator.prototype.register = function(name, fn) { + if (!fn) { + if (typeof name === 'function') { fn = name; name = 'generator-' + this.id++; } else { @@ -29,4 +29,4 @@ Generator.prototype.register = function(name, fn){ this.store[name] = Promise.method(fn); }; -module.exports = Generator; \ No newline at end of file +module.exports = Generator; diff --git a/lib/extend/helper.js b/lib/extend/helper.js index 147624e523..ed678e4c0c 100644 --- a/lib/extend/helper.js +++ b/lib/extend/helper.js @@ -1,22 +1,22 @@ 'use strict'; -function Helper(){ +function Helper() { this.store = {}; } -Helper.prototype.list = function(){ +Helper.prototype.list = function() { return this.store; }; -Helper.prototype.get = function(name){ +Helper.prototype.get = function(name) { return this.store[name]; }; -Helper.prototype.register = function(name, fn){ +Helper.prototype.register = function(name, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); this.store[name] = fn; }; -module.exports = Helper; \ No newline at end of file +module.exports = Helper; diff --git a/lib/extend/index.js b/lib/extend/index.js index c8a8efc421..3ad306245c 100644 --- a/lib/extend/index.js +++ b/lib/extend/index.js @@ -8,4 +8,4 @@ exports.Helper = require('./helper'); exports.Migrator = require('./migrator'); exports.Processor = require('./processor'); exports.Renderer = require('./renderer'); -exports.Tag = require('./tag'); \ No newline at end of file +exports.Tag = require('./tag'); diff --git a/lib/extend/migrator.js b/lib/extend/migrator.js index 46d27b41a2..dcc5ab1b79 100644 --- a/lib/extend/migrator.js +++ b/lib/extend/migrator.js @@ -2,23 +2,23 @@ var Promise = require('bluebird'); -function Migrator(){ +function Migrator() { this.store = {}; } -Migrator.prototype.list = function(){ +Migrator.prototype.list = function() { return this.store; }; -Migrator.prototype.get = function(name){ +Migrator.prototype.get = function(name) { return this.store[name]; }; -Migrator.prototype.register = function(name, fn){ +Migrator.prototype.register = function(name, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); - if (fn.length > 1){ + if (fn.length > 1) { fn = Promise.promisify(fn); } else { fn = Promise.method(fn); @@ -27,4 +27,4 @@ Migrator.prototype.register = function(name, fn){ this.store[name] = fn; }; -module.exports = Migrator; \ No newline at end of file +module.exports = Migrator; diff --git a/lib/extend/processor.js b/lib/extend/processor.js index aadc38f8d2..1e4d376e46 100644 --- a/lib/extend/processor.js +++ b/lib/extend/processor.js @@ -3,17 +3,17 @@ var Promise = require('bluebird'); var Pattern = require('hexo-util').Pattern; -function Processor(){ +function Processor() { this.store = []; } -Processor.prototype.list = function(){ +Processor.prototype.list = function() { return this.store; }; -Processor.prototype.register = function(pattern, fn){ - if (!fn){ - if (typeof pattern === 'function'){ +Processor.prototype.register = function(pattern, fn) { + if (!fn) { + if (typeof pattern === 'function') { fn = pattern; pattern = /(.*)/; } else { @@ -21,7 +21,7 @@ Processor.prototype.register = function(pattern, fn){ } } - if (fn.length > 1){ + if (fn.length > 1) { fn = Promise.promisify(fn); } else { fn = Promise.method(fn); @@ -33,4 +33,4 @@ Processor.prototype.register = function(pattern, fn){ }); }; -module.exports = Processor; \ No newline at end of file +module.exports = Processor; diff --git a/lib/extend/renderer.js b/lib/extend/renderer.js index edde3b2ce6..d9c942fb86 100644 --- a/lib/extend/renderer.js +++ b/lib/extend/renderer.js @@ -3,40 +3,40 @@ var pathFn = require('path'); var Promise = require('bluebird'); -function getExtname(str){ +function getExtname(str) { var extname = pathFn.extname(str) || str; return extname[0] === '.' ? extname.slice(1) : extname; } -function Renderer(){ +function Renderer() { this.store = {}; this.storeSync = {}; } -Renderer.prototype.list = function(sync){ +Renderer.prototype.list = function(sync) { return sync ? this.storeSync : this.store; }; -Renderer.prototype.get = function(name, sync){ +Renderer.prototype.get = function(name, sync) { var store = this[sync ? 'storeSync' : 'store']; return store[getExtname(name)] || store[name]; }; -Renderer.prototype.isRenderable = function(path){ +Renderer.prototype.isRenderable = function(path) { return Boolean(this.get(path)); }; -Renderer.prototype.isRenderableSync = function(path){ +Renderer.prototype.isRenderableSync = function(path) { return Boolean(this.get(path, true)); }; -Renderer.prototype.getOutput = function(path){ +Renderer.prototype.getOutput = function(path) { var renderer = this.get(path); return renderer ? renderer.output : ''; }; -Renderer.prototype.register = function(name, output, fn, sync){ +Renderer.prototype.register = function(name, output, fn, sync) { if (!name) throw new TypeError('name is required'); if (!output) throw new TypeError('output is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); @@ -44,7 +44,7 @@ Renderer.prototype.register = function(name, output, fn, sync){ name = getExtname(name); output = getExtname(output); - if (sync){ + if (sync) { this.storeSync[name] = fn; this.storeSync[name].output = output; @@ -57,4 +57,4 @@ Renderer.prototype.register = function(name, output, fn, sync){ this.store[name].output = output; }; -module.exports = Renderer; \ No newline at end of file +module.exports = Renderer; diff --git a/lib/extend/tag.js b/lib/extend/tag.js index db8f958ce9..326a81c5bb 100644 --- a/lib/extend/tag.js +++ b/lib/extend/tag.js @@ -5,36 +5,36 @@ var nunjucks = require('nunjucks'); var inherits = require('util').inherits; var Promise = require('bluebird'); -function Tag(){ +function Tag() { this.env = new nunjucks.Environment(null, { autoescape: false }); } -Tag.prototype.register = function(name, fn, options){ +Tag.prototype.register = function(name, fn, options) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); - if (options == null || typeof options === 'boolean'){ + if (options == null || typeof options === 'boolean') { options = {ends: options}; } var tag; - if (options.async){ - if (fn.length > 2){ + if (options.async) { + if (fn.length > 2) { fn = Promise.promisify(fn); } else { fn = Promise.method(fn); } - if (options.ends){ + if (options.ends) { tag = new NunjucksAsyncBlock(name, fn); } else { tag = new NunjucksAsyncTag(name, fn); } } else { - if (options.ends){ + if (options.ends) { tag = new NunjucksBlock(name, fn); } else { tag = new NunjucksTag(name, fn); @@ -44,40 +44,40 @@ Tag.prototype.register = function(name, fn, options){ this.env.addExtension(name, tag); }; -Tag.prototype.render = function(str, options, callback){ - if (!callback && typeof options === 'function'){ +Tag.prototype.render = function(str, options, callback) { + if (!callback && typeof options === 'function') { callback = options; options = {}; } var env = this.env; - return new Promise(function(resolve, reject){ - env.renderString(str, options, function(err, result){ + return new Promise(function(resolve, reject) { + env.renderString(str, options, function(err, result) { if (err) return reject(err); resolve(result); }); }); }; -function NunjucksTag(name, fn){ +function NunjucksTag(name, fn) { this.tags = [name]; this.fn = fn; } -NunjucksTag.prototype.parse = function(parser, nodes, lexer){ +NunjucksTag.prototype.parse = function(parser, nodes, lexer) { var node = this._parseArgs(parser, nodes, lexer); return new nodes.CallExtension(this, 'run', node, []); }; -NunjucksTag.prototype._parseArgs = function(parser, nodes, lexer){ +NunjucksTag.prototype._parseArgs = function(parser, nodes, lexer) { var tag = parser.nextToken(); var node = new nodes.NodeList(tag.lineno, tag.colno); var args = []; var token; - while ((token = parser.nextToken(true)) && token.type !== lexer.TOKEN_BLOCK_END){ + while ((token = parser.nextToken(true)) && token.type !== lexer.TOKEN_BLOCK_END) { args += token.value; } @@ -86,77 +86,77 @@ NunjucksTag.prototype._parseArgs = function(parser, nodes, lexer){ return node; }; -NunjucksTag.prototype.run = function(context, args){ +NunjucksTag.prototype.run = function(context, args) { return this._run(context, args, ''); }; -NunjucksTag.prototype._run = function(context, args, body){ +NunjucksTag.prototype._run = function(context, args, body) { return this.fn.call(context.ctx, args.split(' '), body); }; -function NunjucksBlock(name, fn){ +function NunjucksBlock(name, fn) { NunjucksTag.call(this, name, fn); } inherits(NunjucksBlock, NunjucksTag); -NunjucksBlock.prototype.parse = function(parser, nodes, lexer){ +NunjucksBlock.prototype.parse = function(parser, nodes, lexer) { var node = this._parseArgs(parser, nodes, lexer); var body = this._parseBody(parser, nodes, lexer); return new nodes.CallExtension(this, 'run', node, [body]); }; -NunjucksBlock.prototype._parseBody = function(parser, nodes, lexer){ +NunjucksBlock.prototype._parseBody = function(parser, nodes, lexer) { var body = parser.parseUntilBlocks('end' + this.tags[0]); parser.advanceAfterBlockEnd(); return body; }; -NunjucksBlock.prototype.run = function(context, args, body){ +NunjucksBlock.prototype.run = function(context, args, body) { return this._run(context, args, trimBody(body)); }; -function trimBody(body){ +function trimBody(body) { return stripIndent(body()).trim(); } -function NunjucksAsyncTag(name, fn){ +function NunjucksAsyncTag(name, fn) { NunjucksTag.call(this, name, fn); } inherits(NunjucksAsyncTag, NunjucksTag); -NunjucksAsyncTag.prototype.parse = function(parser, nodes, lexer){ +NunjucksAsyncTag.prototype.parse = function(parser, nodes, lexer) { var node = this._parseArgs(parser, nodes, lexer); return new nodes.CallExtensionAsync(this, 'run', node, []); }; -NunjucksAsyncTag.prototype.run = function(context, args, callback){ - return this._run(context, args, '').then(function(result){ +NunjucksAsyncTag.prototype.run = function(context, args, callback) { + return this._run(context, args, '').then(function(result) { callback(null, result); }, callback); }; -function NunjucksAsyncBlock(name, fn){ +function NunjucksAsyncBlock(name, fn) { NunjucksBlock.call(this, name, fn); } inherits(NunjucksAsyncBlock, NunjucksBlock); -NunjucksAsyncBlock.prototype.parse = function(parser, nodes, lexer){ +NunjucksAsyncBlock.prototype.parse = function(parser, nodes, lexer) { var node = this._parseArgs(parser, nodes, lexer); var body = this._parseBody(parser, nodes, lexer); return new nodes.CallExtensionAsync(this, 'run', node, [body]); }; -NunjucksAsyncBlock.prototype.run = function(context, args, body, callback){ - return this._run(context, args, trimBody(body)).then(function(result){ +NunjucksAsyncBlock.prototype.run = function(context, args, body, callback) { + return this._run(context, args, trimBody(body)).then(function(result) { callback(null, result); }, callback); }; -module.exports = Tag; \ No newline at end of file +module.exports = Tag; diff --git a/lib/hexo/create_logger.js b/lib/hexo/create_logger.js index 7feff2eb00..2a19b34299 100644 --- a/lib/hexo/create_logger.js +++ b/lib/hexo/create_logger.js @@ -24,16 +24,16 @@ var levelColors = { 60: 'magenta' }; -function ConsoleStream(env){ +function ConsoleStream(env) { this.debug = env.debug; } -ConsoleStream.prototype.write = function(data){ +ConsoleStream.prototype.write = function(data) { var level = data.level; var msg = ''; // Time - if (this.debug){ + if (this.debug) { msg += chalk.gray(moment(data.time).format(dateFormat)) + ' '; } @@ -44,18 +44,20 @@ ConsoleStream.prototype.write = function(data){ msg += data.msg + '\n'; // Error - if (data.err){ + if (data.err) { var err = data.err.stack || data.err.message; if (err) msg += chalk.gray(err) + '\n'; - } - process.stdout.write(msg); + process.stderr.write(msg); + } else { + process.stdout.write(msg); + } }; -function createLogger(env){ +function createLogger(env) { var streams = []; - if (!env.silent){ + if (!env.silent) { streams.push({ type: 'raw', level: env.debug ? 'trace' : 'info', @@ -63,7 +65,7 @@ function createLogger(env){ }); } - if (env.debug){ + if (env.debug) { streams.push({ level: 'trace', path: 'debug.log' @@ -88,4 +90,4 @@ function createLogger(env){ return logger; } -module.exports = createLogger; \ No newline at end of file +module.exports = createLogger; diff --git a/lib/hexo/default_config.js b/lib/hexo/default_config.js index c34a20decd..0bb3a0843a 100644 --- a/lib/hexo/default_config.js +++ b/lib/hexo/default_config.js @@ -36,7 +36,7 @@ module.exports = { enable: true, auto_detect: true, // Maintain consistent with previous version. line_number: true, - tab_replace: '', + tab_replace: '' }, // Category & Tag default_category: 'uncategorized', diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 1a88e0a18b..da46eec3ff 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -28,7 +28,7 @@ var libDir = pathFn.dirname(__dirname); var sep = pathFn.sep; var dbVersion = 1; -function Hexo(base, args){ +function Hexo(base, args) { base = base || process.cwd(); args = args || {}; @@ -99,47 +99,47 @@ function Hexo(base, args){ require('util').inherits(Hexo, EventEmitter); -Hexo.prototype._bindLocals = function(){ +Hexo.prototype._bindLocals = function() { var db = this.database; var locals = this.locals; var self = this; - locals.set('posts', function(){ + locals.set('posts', function() { var query = {}; - if (!self.config.future){ + if (!self.config.future) { query.date = {$lte: Date.now()}; } - if (!self._showDrafts()){ + if (!self._showDrafts()) { query.published = true; } return db.model('Post').find(query); }); - locals.set('pages', function(){ + locals.set('pages', function() { var query = {}; - if (!self.config.future){ + if (!self.config.future) { query.date = {$lte: Date.now()}; } return db.model('Page').find(query); }); - locals.set('categories', function(){ + locals.set('categories', function() { return db.model('Category'); }); - locals.set('tags', function(){ + locals.set('tags', function() { return db.model('Tag'); }); - locals.set('data', function(){ + locals.set('data', function() { var obj = {}; - db.model('Data').forEach(function(data){ + db.model('Data').forEach(function(data) { obj[data._id] = data.data; }); @@ -147,7 +147,7 @@ Hexo.prototype._bindLocals = function(){ }); }; -Hexo.prototype.init = function(){ +Hexo.prototype.init = function() { var self = this; this.log.debug('Hexo version: %s', chalk.magenta(this.version)); @@ -167,28 +167,28 @@ Hexo.prototype.init = function(){ 'update_package', // Update package.json 'load_config', // Load config 'load_plugins' // Load external plugins & scripts - ], function(name){ + ], function(name) { return require('./' + name)(self); - }).then(function(){ + }).then(function() { return self.execFilter('after_init', null, {context: self}); - }).then(function(){ + }).then(function() { // Ready to go! self.emit('ready'); }); }; -Hexo.prototype.call = function(name, args, callback){ - if (!callback && typeof args === 'function'){ +Hexo.prototype.call = function(name, args, callback) { + if (!callback && typeof args === 'function') { callback = args; args = {}; } var self = this; - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { var c = self.extend.console.get(name); - if (c){ + if (c) { c.call(self, args).then(resolve, reject); } else { reject(new Error('Console `' + name + '` has not been registered yet!')); @@ -196,24 +196,24 @@ Hexo.prototype.call = function(name, args, callback){ }).nodeify(callback); }; -Hexo.prototype.model = function(name, schema){ +Hexo.prototype.model = function(name, schema) { return this.database.model(name, schema); }; -Hexo.prototype.loadPlugin = function(path, callback){ +Hexo.prototype.loadPlugin = function(path, callback) { var self = this; - return fs.readFile(path).then(function(script){ + return fs.readFile(path).then(function(script) { // Based on: https://github.com/joyent/node/blob/v0.10.33/src/node.js#L516 var module = new Module(path); module.filename = path; module.paths = Module._nodeModulePaths(path); - function require(path){ + function require(path) { return module.require(path); } - require.resolve = function(request){ + require.resolve = function(request) { return Module._resolveFilename(request, module); }; @@ -230,52 +230,52 @@ Hexo.prototype.loadPlugin = function(path, callback){ }).nodeify(callback); }; -Hexo.prototype._showDrafts = function(){ +Hexo.prototype._showDrafts = function() { var args = this.env.args; return args.draft || args.drafts || this.config.render_drafts; }; -Hexo.prototype.load = function(callback){ +Hexo.prototype.load = function(callback) { var self = this; - return loadDatabase(this).then(function(){ + return loadDatabase(this).then(function() { return Promise.all([ self.source.process(), self.theme.process() ]); - }).then(function(){ + }).then(function() { return self._generate({cache: true}); }).nodeify(callback); }; -Hexo.prototype.watch = function(callback){ +Hexo.prototype.watch = function(callback) { var self = this; - function generate(){ + function generate() { return self._generate({cache: false}); } - return loadDatabase(this).then(function(){ + return loadDatabase(this).then(function() { return Promise.all([ self.source.watch(), self.theme.watch() ]); - }).then(function(){ + }).then(function() { self.on('processAfter', generate); return generate(); }).nodeify(callback); }; -Hexo.prototype.unwatch = function(){ +Hexo.prototype.unwatch = function() { stopWatcher(this.source); stopWatcher(this.theme); }; -function stopWatcher(box){ +function stopWatcher(box) { if (box.isWatching()) box.unwatch(); } -Hexo.prototype._generate = function(options){ +Hexo.prototype._generate = function(options) { if (this._isGenerating) return; options = options || {}; @@ -294,7 +294,7 @@ Hexo.prototype._generate = function(options){ this.emit('generateBefore'); - function Locals(path, locals){ + function Locals(path, locals) { this.page = _.extend({ path: path }, locals); @@ -313,25 +313,25 @@ Hexo.prototype._generate = function(options){ // Run before_generate filters return this.execFilter('before_generate', null, {context: this}) - .then(function(){ + .then(function() { self.locals.invalidate(); siteLocals = self.locals.toObject(); Locals.prototype.site = siteLocals; // Run generators - return Promise.map(keys, function(key){ + return Promise.map(keys, function(key) { var generator = generators[key]; - return generator.call(self, siteLocals).then(function(data){ + return generator.call(self, siteLocals).then(function(data) { log.debug('Generator: %s', chalk.magenta(key)); return data; }); - }).reduce(function(result, data){ + }).reduce(function(result, data) { return data ? result.concat(data) : result; }, []); }) // Add routes - .each(function(item){ + .each(function(item) { if (typeof item !== 'object' || item.path == null) return; var path = route.format(item.path); @@ -340,11 +340,11 @@ Hexo.prototype._generate = function(options){ newRouteList.push(path); - if (!layout){ + if (!layout) { return route.set(path, data); } - if (Array.isArray(layout)){ + if (Array.isArray(layout)) { layout = _.uniq(layout); } else { layout = [layout]; @@ -354,23 +354,23 @@ Hexo.prototype._generate = function(options){ var layoutLength = layout.length; var cache; - function saveCache(result){ + function saveCache(result) { cache = result; return result; } return self.execFilter('template_locals', locals, {context: self}) - .then(function(locals){ - route.set(path, function(){ + .then(function(locals) { + route.set(path, function() { if (options.cache && cache != null) return cache; var view, name; - for (var i = 0; i < layoutLength; i++){ + for (var i = 0; i < layoutLength; i++) { name = layout[i]; view = theme.getView(name); - if (view){ + if (view) { log.debug('Rendering %s: %s', name, chalk.magenta(path)); return view.render(locals).then(saveCache); } @@ -379,11 +379,11 @@ Hexo.prototype._generate = function(options){ log.warn('No layout: %s', chalk.magenta(path)); }); }); - }).then(function(){ + }).then(function() { // Remove old routes var removed = _.difference(routeList, newRouteList); - for (var i = 0, len = removed.length; i < len; i++){ + for (var i = 0, len = removed.length; i < len; i++) { route.remove(removed[i]); } @@ -394,15 +394,15 @@ Hexo.prototype._generate = function(options){ // Run after_generate filters return self.execFilter('after_generate', null, {context: self}); - }).finally(function(){ + }).finally(function() { self._isGenerating = false; }); }; -Hexo.prototype.exit = function(err){ +Hexo.prototype.exit = function(err) { var self = this; - if (err){ + if (err) { this.log.fatal( {err: err}, 'Something\'s wrong. Maybe you can find the solution here: %s', @@ -410,16 +410,16 @@ Hexo.prototype.exit = function(err){ ); } - return this.execFilter('before_exit', null, {context: this}).then(function(){ + return this.execFilter('before_exit', null, {context: this}).then(function() { self.emit('exit', err); }); }; -Hexo.prototype.execFilter = function(type, data, options){ +Hexo.prototype.execFilter = function(type, data, options) { return this.extend.filter.exec(type, data, options); }; -Hexo.prototype.execFilterSync = function(type, data, options){ +Hexo.prototype.execFilterSync = function(type, data, options) { return this.extend.filter.execSync(type, data, options); }; @@ -429,4 +429,4 @@ Hexo.core_dir = Hexo.prototype.core_dir = pathFn.dirname(libDir) + sep; Hexo.version = Hexo.prototype.version = pkg.version; -module.exports = Hexo; \ No newline at end of file +module.exports = Hexo; diff --git a/lib/hexo/load_config.js b/lib/hexo/load_config.js index facfb64e36..6777afc6d9 100644 --- a/lib/hexo/load_config.js +++ b/lib/hexo/load_config.js @@ -10,20 +10,20 @@ var chalk = require('chalk'); var sep = pathFn.sep; -module.exports = function(ctx){ +module.exports = function(ctx) { if (!ctx.env.init) return; var baseDir = ctx.base_dir; var configPath = ctx.config_path; - return fs.exists(configPath).then(function(exist){ + return fs.exists(configPath).then(function(exist) { return exist ? configPath : findConfigPath(configPath); - }).then(function(path){ + }).then(function(path) { if (!path) return; configPath = path; return ctx.render.render({path: path}); - }).then(function(config){ + }).then(function(config) { if (!config || typeof config !== 'object') return; ctx.log.debug('Config loaded: %s', chalk.magenta(tildify(configPath))); @@ -47,20 +47,20 @@ module.exports = function(ctx){ }); }; -function findConfigPath(path){ +function findConfigPath(path) { var extname = pathFn.extname(path); var dirname = pathFn.dirname(path); var basename = pathFn.basename(path, extname); - return fs.readdir(dirname).then(function(files){ + return fs.readdir(dirname).then(function(files) { var item = ''; - for (var i = 0, len = files.length; i < len; i++){ + for (var i = 0, len = files.length; i < len; i++) { item = files[i]; - if (item.substring(0, basename.length) === basename){ + if (item.substring(0, basename.length) === basename) { return pathFn.join(dirname, item); } } }); -} \ No newline at end of file +} diff --git a/lib/hexo/load_database.js b/lib/hexo/load_database.js index de89168709..c5f38a2008 100644 --- a/lib/hexo/load_database.js +++ b/lib/hexo/load_database.js @@ -3,22 +3,22 @@ var fs = require('hexo-fs'); var Promise = require('bluebird'); -module.exports = function(ctx){ +module.exports = function(ctx) { if (ctx._dbLoaded) return Promise.resolve(); var db = ctx.database; var path = db.options.path; var log = ctx.log; - return fs.exists(path).then(function(exist){ + return fs.exists(path).then(function(exist) { if (!exist) return; log.debug('Loading database.'); return db.load(); - }).then(function(){ + }).then(function() { ctx._dbLoaded = true; - }, function(){ + }).catch(function() { log.error('Database load failed. Deleting database.'); return fs.unlink(path); }); -}; \ No newline at end of file +}; diff --git a/lib/hexo/load_plugins.js b/lib/hexo/load_plugins.js index 9116e3ef37..aa7db2bd3b 100644 --- a/lib/hexo/load_plugins.js +++ b/lib/hexo/load_plugins.js @@ -5,7 +5,7 @@ var fs = require('hexo-fs'); var Promise = require('bluebird'); var chalk = require('chalk'); -module.exports = function(ctx){ +module.exports = function(ctx) { if (!ctx.env.init || ctx.env.safe) return; return Promise.all([ @@ -14,62 +14,62 @@ module.exports = function(ctx){ ]); }; -function loadModules(ctx){ +function loadModules(ctx) { var packagePath = pathFn.join(ctx.base_dir, 'package.json'); var pluginDir = ctx.plugin_dir; // Make sure package.json exists - return fs.exists(packagePath).then(function(exist){ + return fs.exists(packagePath).then(function(exist) { if (!exist) return []; // Read package.json and find dependencies - return fs.readFile(packagePath).then(function(content){ + return fs.readFile(packagePath).then(function(content) { var json = JSON.parse(content); var deps = json.dependencies || {}; return Object.keys(deps); }); - }).filter(function(name){ + }).filter(function(name) { // Ignore plugins whose name is not started with "hexo-" if (name.substring(0, 5) !== 'hexo-') return false; // Make sure the plugin exists var path = pathFn.join(pluginDir, name); return fs.exists(path); - }).map(function(name){ + }).map(function(name) { var path = require.resolve(pathFn.join(pluginDir, name)); // Load plugins - return ctx.loadPlugin(path).then(function(){ + return ctx.loadPlugin(path).then(function() { ctx.log.debug('Plugin loaded: %s', chalk.magenta(name)); - }, function(err){ + }).catch(function(err) { ctx.log.error({err: err}, 'Plugin load failed: %s', chalk.magenta(name)); }); }); } -function loadScripts(ctx){ +function loadScripts(ctx) { var baseDirLength = ctx.base_dir.length; - function displayPath(path){ + function displayPath(path) { return chalk.magenta(path.substring(baseDirLength)); } return Promise.filter([ ctx.script_dir, ctx.theme_script_dir - ], function(scriptDir){ + ], function(scriptDir) { // Ignore the directory if it does not exist return scriptDir ? fs.exists(scriptDir) : false; - }).map(function(scriptDir){ - return fs.listDir(scriptDir).map(function(name){ + }).map(function(scriptDir) { + return fs.listDir(scriptDir).map(function(name) { var path = pathFn.join(scriptDir, name); - return ctx.loadPlugin(path).then(function(){ + return ctx.loadPlugin(path).then(function() { ctx.log.debug('Script loaded: %s', displayPath(path)); - }, function(err){ + }).catch(function(err) { ctx.log.error({err: err}, 'Script load failed: %s', displayPath(path)); }); }); }); -} \ No newline at end of file +} diff --git a/lib/hexo/locals.js b/lib/hexo/locals.js index f3d0406783..916c68b381 100644 --- a/lib/hexo/locals.js +++ b/lib/hexo/locals.js @@ -1,16 +1,16 @@ 'use strict'; -function Locals(){ +function Locals() { this.cache = {}; this.getters = {}; } -Locals.prototype.get = function(name){ +Locals.prototype.get = function(name) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); var cache = this.cache[name]; - if (cache == null){ + if (cache == null) { var getter = this.getters[name]; if (!getter) return; @@ -20,16 +20,16 @@ Locals.prototype.get = function(name){ return cache; }; -Locals.prototype.set = function(name, value){ +Locals.prototype.set = function(name, value) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); if (value == null) throw new TypeError('value is required!'); var getter; - if (typeof value === 'function'){ + if (typeof value === 'function') { getter = value; } else { - getter = function(){ + getter = function() { return value; }; } @@ -40,7 +40,7 @@ Locals.prototype.set = function(name, value){ return this; }; -Locals.prototype.remove = function(name){ +Locals.prototype.remove = function(name) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); this.getters[name] = null; @@ -49,19 +49,19 @@ Locals.prototype.remove = function(name){ return this; }; -Locals.prototype.invalidate = function(){ +Locals.prototype.invalidate = function() { this.cache = {}; return this; }; -Locals.prototype.toObject = function(){ +Locals.prototype.toObject = function() { var result = {}; var keys = Object.keys(this.getters); var key = ''; var item; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; item = this.get(key); @@ -71,4 +71,4 @@ Locals.prototype.toObject = function(){ return result; }; -module.exports = Locals; \ No newline at end of file +module.exports = Locals; diff --git a/lib/hexo/post.js b/lib/hexo/post.js index c3fdd394cf..dbe946f402 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.js @@ -34,12 +34,12 @@ swig.setDefaults({ autoescape: false }); -function Post(context){ +function Post(context) { this.context = context; } -Post.prototype.create = function(data, replace, callback){ - if (!callback && typeof replace === 'function'){ +Post.prototype.create = function(data, replace, callback) { + if (!callback && typeof replace === 'function') { callback = replace; replace = false; } @@ -59,7 +59,7 @@ Post.prototype.create = function(data, replace, callback){ }), // Get the scaffold this._getScaffold(data.layout) - ]).spread(function(path, scaffold){ + ]).spread(function(path, scaffold) { // Split data part from the raw scaffold var split = yfm.split(scaffold); var separator = split.separator || '---'; @@ -73,7 +73,7 @@ Post.prototype.create = function(data, replace, callback){ // Parse front-matter var compiled; - if (jsonMode){ + if (jsonMode) { compiled = JSON.parse('{' + renderedData + '}'); } else { compiled = yaml.load(renderedData); @@ -84,10 +84,10 @@ Post.prototype.create = function(data, replace, callback){ var key = ''; var obj = compiled; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; - if (!preservedKeys[key] && obj[key] == null){ + if (!preservedKeys[key] && obj[key] == null) { obj[key] = data[key]; } } @@ -102,7 +102,7 @@ Post.prototype.create = function(data, replace, callback){ // Concat content content += split.content; - if (data.content){ + if (data.content) { content += '\n' + data.content; } @@ -116,26 +116,26 @@ Post.prototype.create = function(data, replace, callback){ fs.writeFile(path, content), // Create asset folder createAssetFolder(path, config.post_asset_folder) - ]).then(function(){ + ]).then(function() { ctx.emit('new', result); }).thenReturn(result); }).nodeify(callback); }; -function prepareFrontMatter(data){ +function prepareFrontMatter(data) { var keys = Object.keys(data); var key = ''; var item; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; item = data[key]; - if (moment.isMoment(item)){ + if (moment.isMoment(item)) { data[key] = item.utc().format('YYYY-MM-DD HH:mm:ss'); - } else if (moment.isDate(item)){ + } else if (moment.isDate(item)) { data[key] = moment.utc(item).format('YYYY-MM-DD HH:mm:ss'); - } else if (typeof item === 'string'){ + } else if (typeof item === 'string') { data[key] = '"' + item + '"'; } } @@ -143,31 +143,31 @@ function prepareFrontMatter(data){ return data; } -Post.prototype._getScaffold = function(layout){ +Post.prototype._getScaffold = function(layout) { var ctx = this.context; - return ctx.scaffold.get(layout).then(function(result){ + return ctx.scaffold.get(layout).then(function(result) { if (result != null) return result; return ctx.scaffold.get('normal'); }); }; -function createAssetFolder(path, assetFolder){ +function createAssetFolder(path, assetFolder) { if (!assetFolder) return Promise.resolve(); var target = removeExtname(path); - return fs.exists(target).then(function(exist){ + return fs.exists(target).then(function(exist) { if (!exist) return fs.mkdirs(target); }); } -function removeExtname(str){ +function removeExtname(str) { return str.substring(0, str.length - pathFn.extname(str).length); } -Post.prototype.publish = function(data, replace, callback){ - if (!callback && typeof replace === 'function'){ +Post.prototype.publish = function(data, replace, callback) { + if (!callback && typeof replace === 'function') { callback = replace; replace = false; } @@ -186,50 +186,50 @@ Post.prototype.publish = function(data, replace, callback){ data.layout = (data.layout || config.default_layout).toLowerCase(); // Find the draft - return fs.listDir(draftDir).then(function(list){ + return fs.listDir(draftDir).then(function(list) { var item = ''; - for (var i = 0, len = list.length; i < len; i++){ + for (var i = 0, len = list.length; i < len; i++) { item = list[i]; if (regex.test(item)) return item; } - }).then(function(item){ + }).then(function(item) { if (!item) throw new Error('Draft "' + slug + '" does not exist.'); // Read the content src = pathFn.join(draftDir, item); return fs.readFile(src); - }).then(function(content){ + }).then(function(content) { // Create post _.extend(data, yfm(content)); data.content = data._content; delete data._content; - return self.create(data, replace).then(function(post){ + return self.create(data, replace).then(function(post) { result.path = post.path; result.content = post.content; }); - }).then(function(){ + }).then(function() { // Remove the original draft file return fs.unlink(src); - }).then(function(){ + }).then(function() { if (!config.post_asset_folder) return; // Copy assets var assetSrc = removeExtname(src); var assetDest = removeExtname(result.path); - return fs.exists(assetSrc).then(function(exist){ + return fs.exists(assetSrc).then(function(exist) { if (!exist) return; - return fs.copyDir(assetSrc, assetDest).then(function(){ + return fs.copyDir(assetSrc, assetDest).then(function() { return fs.rmdir(assetSrc); }); }); }).thenReturn(result).nodeify(callback); }; -Post.prototype.render = function(source, data, callback){ +Post.prototype.render = function(source, data, callback) { data = data || {}; var ctx = this.context; @@ -238,13 +238,13 @@ Post.prototype.render = function(source, data, callback){ var tag = ctx.extend.tag; var isSwig = data.engine === 'swig' || (source && pathFn.extname(source) === '.swig'); - function escapeContent(str){ + function escapeContent(str) { return ''; } function tagFilter(content) { // Replace cache data with real contents - content = content.replace(rPlaceholder, function(){ + content = content.replace(rPlaceholder, function() { return cache[arguments[1]]; }); @@ -253,22 +253,22 @@ Post.prototype.render = function(source, data, callback){ return tag.render(data.content, data); } - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { if (data.content != null) return resolve(data.content); if (!source) return reject(new Error('No input file or string!')); // Read content from files fs.readFile(source).then(resolve, reject); - }).then(function(content){ + }).then(function(content) { data.content = content; // Run "before_post_render" filters - return ctx.execFilter('before_post_render', data, {context: ctx}).then(function(){ - data.content = data.content.replace(rEscapeContent, function(match, content){ + return ctx.execFilter('before_post_render', data, {context: ctx}).then(function() { + data.content = data.content.replace(rEscapeContent, function(match, content) { return escapeContent(content); }); }); - }).then(function(){ + }).then(function() { // Skip rendering if this is a swig file if (isSwig) return data.content; @@ -290,7 +290,7 @@ Post.prototype.render = function(source, data, callback){ toString: true, onRenderEnd: tagFilter }, options); - }).then(function(content){ + }).then(function(content) { data.content = content; if (!isSwig) { @@ -299,7 +299,7 @@ Post.prototype.render = function(source, data, callback){ // Render with Nunjucks return tag.render(data.content, data); - }).then(function(content){ + }).then(function(content) { data.content = content; // Run "after_post_render" filters @@ -307,4 +307,4 @@ Post.prototype.render = function(source, data, callback){ }); }; -module.exports = Post; \ No newline at end of file +module.exports = Post; diff --git a/lib/hexo/register_models.js b/lib/hexo/register_models.js index 9d3f5db3d4..55c09badee 100644 --- a/lib/hexo/register_models.js +++ b/lib/hexo/register_models.js @@ -2,14 +2,14 @@ var models = require('../models'); -module.exports = function(ctx){ +module.exports = function(ctx) { var db = ctx.database; var keys = Object.keys(models); var key = ''; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; db.model(key, models[key](ctx)); } -}; \ No newline at end of file +}; diff --git a/lib/hexo/render.js b/lib/hexo/render.js index 3a405e8592..1d769abe8d 100644 --- a/lib/hexo/render.js +++ b/lib/hexo/render.js @@ -4,30 +4,30 @@ var pathFn = require('path'); var Promise = require('bluebird'); var fs = require('hexo-fs'); -function getExtname(str){ +function getExtname(str) { var extname = pathFn.extname(str); return extname[0] === '.' ? extname.slice(1) : extname; } -function Render(ctx){ +function Render(ctx) { this.context = ctx; this.renderer = ctx.extend.renderer; } -Render.prototype.isRenderable = function(path){ +Render.prototype.isRenderable = function(path) { return this.renderer.isRenderable(path); }; -Render.prototype.isRenderableSync = function(path){ +Render.prototype.isRenderableSync = function(path) { return this.renderer.isRenderableSync(path); }; -Render.prototype.getOutput = function(path){ +Render.prototype.getOutput = function(path) { return this.renderer.getOutput(path); }; -Render.prototype.render = function(data, options, callback){ - if (!callback && typeof options === 'function'){ +Render.prototype.render = function(data, options, callback) { + if (!callback && typeof options === 'function') { callback = options; options = {}; } @@ -36,26 +36,26 @@ Render.prototype.render = function(data, options, callback){ var self = this; var ext = ''; - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { if (!data) return reject(new TypeError('No input file or string!')); if (data.text != null) return resolve(data.text); if (!data.path) return reject(new TypeError('No input file or string!')); fs.readFile(data.path).then(resolve, reject); - }).then(function(text){ + }).then(function(text) { data.text = text; ext = data.engine || getExtname(data.path); if (!ext || !self.isRenderable(ext)) return text; var renderer = self.renderer.get(ext); return renderer.call(ctx, data, options); - }).then(function(result){ + }).then(function(result) { result = toString(result, data); if (data.onRenderEnd) { return data.onRenderEnd(result); - } else { - return result; } + + return result; }).then(function(result) { var output = self.getOutput(ext) || ext; return ctx.execFilter('after_render:' + output, result, { @@ -65,14 +65,14 @@ Render.prototype.render = function(data, options, callback){ }).nodeify(callback); }; -Render.prototype.renderSync = function(data, options){ +Render.prototype.renderSync = function(data, options) { if (!data) throw new TypeError('No input file or string!'); options = options || {}; var ctx = this.context; - if (data.text == null){ + if (data.text == null) { if (!data.path) throw new TypeError('No input file or string!'); data.text = fs.readFileSync(data.path); } @@ -82,7 +82,7 @@ Render.prototype.renderSync = function(data, options){ var ext = data.engine || getExtname(data.path); var result; - if (ext && this.isRenderableSync(ext)){ + if (ext && this.isRenderableSync(ext)) { var renderer = this.renderer.get(ext, true); result = renderer.call(ctx, data, options); } else { @@ -102,18 +102,18 @@ Render.prototype.renderSync = function(data, options){ }); }; -function toString(result, options){ +function toString(result, options) { if (!options.hasOwnProperty('toString') || typeof result === 'string') return result; - if (typeof options.toString === 'function'){ + if (typeof options.toString === 'function') { return options.toString(result); - } else if (typeof result === 'object'){ + } else if (typeof result === 'object') { return JSON.stringify(result); - } else if (result.toString){ + } else if (result.toString) { return result.toString(); - } else { - return result; } + + return result; } -module.exports = Render; \ No newline at end of file +module.exports = Render; diff --git a/lib/hexo/router.js b/lib/hexo/router.js index e6a185ec38..d9ce938421 100644 --- a/lib/hexo/router.js +++ b/lib/hexo/router.js @@ -7,7 +7,7 @@ var util = require('util'); var through2 = require('through2'); var Readable = Stream.Readable; -function Router(){ +function Router() { EventEmitter.call(this); this.routes = {}; @@ -15,7 +15,7 @@ function Router(){ util.inherits(Router, EventEmitter); -Router.format = Router.prototype.format = function(path){ +Router.format = Router.prototype.format = function(path) { path = path || ''; if (typeof path !== 'string') throw new TypeError('path must be a string!'); @@ -25,20 +25,20 @@ Router.format = Router.prototype.format = function(path){ .replace(/\?.*$/, ''); // Remove query string // Appends `index.html` to the path with trailing slash - if (!path || path[path.length - 1] === '/'){ + if (!path || path[path.length - 1] === '/') { path += 'index.html'; } return path; }; -Router.prototype.list = function(){ +Router.prototype.list = function() { var routes = this.routes; var keys = Object.keys(routes); var arr = []; var key; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; if (routes[key]) arr.push(key); } @@ -46,7 +46,7 @@ Router.prototype.list = function(){ return arr; }; -Router.prototype.get = function(path){ +Router.prototype.get = function(path) { if (typeof path !== 'string') throw new TypeError('path must be a string!'); var data = this.routes[this.format(path)]; @@ -55,20 +55,20 @@ Router.prototype.get = function(path){ return new RouteStream(data); }; -Router.prototype.isModified = function(path){ +Router.prototype.isModified = function(path) { if (typeof path !== 'string') throw new TypeError('path must be a string!'); var data = this.routes[this.format(path)]; return data ? data.modified : false; }; -Router.prototype.set = function(path, data){ +Router.prototype.set = function(path, data) { if (typeof path !== 'string') throw new TypeError('path must be a string!'); if (data == null) throw new TypeError('data is required!'); var obj; - if (typeof data === 'object' && data.data != null){ + if (typeof data === 'object' && data.data != null) { obj = data; } else { obj = { @@ -77,8 +77,8 @@ Router.prototype.set = function(path, data){ }; } - if (typeof obj.data === 'function'){ - if (obj.data.length){ + if (typeof obj.data === 'function') { + if (obj.data.length) { obj.data = Promise.promisify(obj.data); } else { obj.data = Promise.method(obj.data); @@ -97,7 +97,7 @@ Router.prototype.set = function(path, data){ return this; }; -Router.prototype.remove = function(path){ +Router.prototype.remove = function(path) { if (typeof path !== 'string') throw new TypeError('path must be a string!'); path = this.format(path); @@ -107,7 +107,7 @@ Router.prototype.remove = function(path){ return this; }; -function RouteStream(data){ +function RouteStream(data) { Readable.call(this, {objectMode: true}); this._data = data.data; @@ -117,10 +117,10 @@ function RouteStream(data){ util.inherits(RouteStream, Readable); -RouteStream.prototype._read = function(){ +RouteStream.prototype._read = function() { var data = this._data; - if (typeof data !== 'function'){ + if (typeof data !== 'function') { this.push(data); this.push(null); return; @@ -132,29 +132,31 @@ RouteStream.prototype._read = function(){ var self = this; - data().then(function(data){ - if (data instanceof Stream && data.readable){ - data.pipe(through2(function(chunk, enc, callback){ + data().then(function(data) { + if (data instanceof Stream && data.readable) { + data.pipe(through2(function(chunk, enc, callback) { self.push(chunk); callback(); - }, function(callback){ + }, + + function(callback) { self.push(null); callback(); - })).on('error', function(err){ + })).on('error', function(err) { self.emit('error', err); }); - } else if (data instanceof Buffer || typeof data === 'string'){ + } else if (data instanceof Buffer || typeof data === 'string') { self.push(data); self.push(null); - } else if (typeof data === 'object'){ + } else if (typeof data === 'object') { self.push(JSON.stringify(data)); self.push(null); } else { self.push(null); } - }, function(err){ + }).catch(function(err) { self.emit('error', err); }); }; -module.exports = Router; \ No newline at end of file +module.exports = Router; diff --git a/lib/hexo/scaffold.js b/lib/hexo/scaffold.js index f30fcf1d25..1cfb9225ed 100644 --- a/lib/hexo/scaffold.js +++ b/lib/hexo/scaffold.js @@ -3,7 +3,7 @@ var pathFn = require('path'); var fs = require('hexo-fs'); -function Scaffold(context){ +function Scaffold(context) { this.context = context; this.scaffoldDir = context.scaffold_dir; } @@ -18,16 +18,16 @@ Scaffold.prototype.defaults = { ].join('\n') }; -Scaffold.prototype._listDir = function(){ +Scaffold.prototype._listDir = function() { var scaffoldDir = this.scaffoldDir; - return fs.exists(scaffoldDir).then(function(exist){ + return fs.exists(scaffoldDir).then(function(exist) { if (!exist) return []; return fs.listDir(scaffoldDir, { ignoreFilesRegex: /^_|\/_/ }); - }).map(function(item){ + }).map(function(item) { return { name: item.substring(0, item.length - pathFn.extname(item).length), path: pathFn.join(scaffoldDir, item) @@ -35,33 +35,33 @@ Scaffold.prototype._listDir = function(){ }); }; -Scaffold.prototype._getScaffold = function(name){ - return this._listDir().then(function(list){ +Scaffold.prototype._getScaffold = function(name) { + return this._listDir().then(function(list) { var item; - for (var i = 0, len = list.length; i < len; i++){ + for (var i = 0, len = list.length; i < len; i++) { item = list[i]; if (item.name === name) return item; } }); }; -Scaffold.prototype.get = function(name, callback){ +Scaffold.prototype.get = function(name, callback) { var self = this; - return this._getScaffold(name).then(function(item){ - if (item){ + return this._getScaffold(name).then(function(item) { + if (item) { return fs.readFile(item.path); - } else { - return self.defaults[name]; } + + return self.defaults[name]; }).nodeify(callback); }; -Scaffold.prototype.set = function(name, content, callback){ +Scaffold.prototype.set = function(name, content, callback) { var scaffoldDir = this.scaffoldDir; - return this._getScaffold(name).then(function(item){ + return this._getScaffold(name).then(function(item) { var path = item ? item.path : pathFn.join(scaffoldDir, name); if (!pathFn.extname(path)) path += '.md'; @@ -69,12 +69,12 @@ Scaffold.prototype.set = function(name, content, callback){ }).nodeify(callback); }; -Scaffold.prototype.remove = function(name, callback){ - return this._getScaffold(name).then(function(item){ +Scaffold.prototype.remove = function(name, callback) { + return this._getScaffold(name).then(function(item) { if (!item) return; return fs.unlink(item.path); }).nodeify(callback); }; -module.exports = Scaffold; \ No newline at end of file +module.exports = Scaffold; diff --git a/lib/hexo/source.js b/lib/hexo/source.js index 5058924e9c..474c4fbf1c 100644 --- a/lib/hexo/source.js +++ b/lib/hexo/source.js @@ -3,7 +3,7 @@ var Box = require('../box'); var util = require('util'); -function Source(ctx){ +function Source(ctx) { Box.call(this, ctx, ctx.source_dir); this.processors = ctx.extend.processor.list(); @@ -11,4 +11,4 @@ function Source(ctx){ util.inherits(Source, Box); -module.exports = Source; \ No newline at end of file +module.exports = Source; diff --git a/lib/hexo/update_package.js b/lib/hexo/update_package.js index d6fb9a7a63..c7667db69c 100644 --- a/lib/hexo/update_package.js +++ b/lib/hexo/update_package.js @@ -3,10 +3,10 @@ var pathFn = require('path'); var fs = require('hexo-fs'); -module.exports = function(ctx){ +module.exports = function(ctx) { var pkgPath = pathFn.join(ctx.base_dir, 'package.json'); - return readPkg(pkgPath).then(function(pkg){ + return readPkg(pkgPath).then(function(pkg) { if (!pkg) return; ctx.env.init = true; @@ -20,15 +20,15 @@ module.exports = function(ctx){ }); }; -function readPkg(path){ - return fs.exists(path).then(function(exist){ +function readPkg(path) { + return fs.exists(path).then(function(exist) { if (!exist) return; - return fs.readFile(path).then(function(content){ + return fs.readFile(path).then(function(content) { var pkg = JSON.parse(content); if (typeof pkg.hexo !== 'object') return; return pkg; }); }); -} \ No newline at end of file +} diff --git a/lib/models/asset.js b/lib/models/asset.js index da15531316..21ec75817a 100644 --- a/lib/models/asset.js +++ b/lib/models/asset.js @@ -3,16 +3,16 @@ var Schema = require('warehouse').Schema; var pathFn = require('path'); -module.exports = function(ctx){ +module.exports = function(ctx) { var Asset = new Schema({ _id: {type: String, required: true}, path: {type: String, required: true}, modified: {type: Boolean, default: true} }); - Asset.virtual('source').get(function(){ + Asset.virtual('source').get(function() { return pathFn.join(ctx.base_dir, this._id); }); return Asset; -}; \ No newline at end of file +}; diff --git a/lib/models/cache.js b/lib/models/cache.js index 28f1a0f833..f631f94cb9 100644 --- a/lib/models/cache.js +++ b/lib/models/cache.js @@ -2,7 +2,7 @@ var Schema = require('warehouse').Schema; -module.exports = function(ctx){ +module.exports = function(ctx) { var Cache = new Schema({ _id: {type: String, required: true}, shasum: {type: String}, @@ -10,4 +10,4 @@ module.exports = function(ctx){ }); return Cache; -}; \ No newline at end of file +}; diff --git a/lib/models/category.js b/lib/models/category.js index a58cd42054..ed486ca2ca 100644 --- a/lib/models/category.js +++ b/lib/models/category.js @@ -4,20 +4,20 @@ var Schema = require('warehouse').Schema; var util = require('hexo-util'); var slugize = util.slugize; -module.exports = function(ctx){ +module.exports = function(ctx) { var Category = new Schema({ name: {type: String, required: true}, parent: {type: Schema.Types.CUID, ref: 'Category'} }); - Category.virtual('slug').get(function(){ + Category.virtual('slug').get(function() { var map = ctx.config.category_map || {}; var name = this.name; var str = ''; if (!name) return; - if (this.parent){ + if (this.parent) { var parent = ctx.model('Category').findById(this.parent); str += parent.slug + '/'; } @@ -28,21 +28,21 @@ module.exports = function(ctx){ return str; }); - Category.virtual('path').get(function(){ + Category.virtual('path').get(function() { var catDir = ctx.config.category_dir; if (catDir[catDir.length - 1] !== '/') catDir += '/'; return catDir + this.slug + '/'; }); - Category.virtual('permalink').get(function(){ + Category.virtual('permalink').get(function() { return ctx.config.url + '/' + this.path; }); - Category.virtual('posts').get(function(){ + Category.virtual('posts').get(function() { var PostCategory = ctx.model('PostCategory'); - var ids = PostCategory.find({category_id: this._id}).map(function(item){ + var ids = PostCategory.find({category_id: this._id}).map(function(item) { return item.post_id; }); @@ -51,12 +51,12 @@ module.exports = function(ctx){ }); }); - Category.virtual('length').get(function(){ + Category.virtual('length').get(function() { return this.posts.length; }); // Check whether a category exists - Category.pre('save', function(data){ + Category.pre('save', function(data) { var name = data.name; var parent = data.parent; if (!name) return; @@ -67,16 +67,16 @@ module.exports = function(ctx){ parent: parent || {$exists: false} }); - if (cat){ + if (cat) { throw new Error('Category `' + name + '` has already existed!'); } }); // Remove PostCategory references - Category.pre('remove', function(data){ + Category.pre('remove', function(data) { var PostCategory = ctx.model('PostCategory'); return PostCategory.remove({category_id: data._id}); }); return Category; -}; \ No newline at end of file +}; diff --git a/lib/models/data.js b/lib/models/data.js index ff8e3441e3..1f0353cc1b 100644 --- a/lib/models/data.js +++ b/lib/models/data.js @@ -2,11 +2,11 @@ var Schema = require('warehouse').Schema; -module.exports = function(ctx){ +module.exports = function(ctx) { var Data = new Schema({ _id: {type: String, required: true}, data: Object }); return Data; -}; \ No newline at end of file +}; diff --git a/lib/models/index.js b/lib/models/index.js index 7a6217b0c5..f52d915e1b 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -9,4 +9,4 @@ exports.Post = require('./post'); exports.PostAsset = require('./post_asset'); exports.PostCategory = require('./post_category'); exports.PostTag = require('./post_tag'); -exports.Tag = require('./tag'); \ No newline at end of file +exports.Tag = require('./tag'); diff --git a/lib/models/page.js b/lib/models/page.js index dd6c4b4919..a40a1ebf16 100644 --- a/lib/models/page.js +++ b/lib/models/page.js @@ -6,7 +6,7 @@ var Moment = require('./types/moment'); var moment = require('moment'); var CacheString = require('./types/cachestring'); -module.exports = function(ctx){ +module.exports = function(ctx) { var Page = new Schema({ title: {type: String, default: ''}, date: { @@ -32,13 +32,13 @@ module.exports = function(ctx){ more: {type: CacheString, default: ''} }); - Page.virtual('permalink').get(function(){ + Page.virtual('permalink').get(function() { return ctx.config.url + '/' + this.path; }); - Page.virtual('full_source').get(function(){ + Page.virtual('full_source').get(function() { return pathFn.join(ctx.source_dir, this.source || ''); }); return Page; -}; \ No newline at end of file +}; diff --git a/lib/models/post.js b/lib/models/post.js index 036aece61b..290e1ccc30 100644 --- a/lib/models/post.js +++ b/lib/models/post.js @@ -9,11 +9,11 @@ var _ = require('lodash'); var Moment = require('./types/moment'); var CacheString = require('./types/cachestring'); -function pickID(data){ +function pickID(data) { return data._id; } -module.exports = function(ctx){ +module.exports = function(ctx) { var Post = new Schema({ id: String, title: {type: String, default: ''}, @@ -43,49 +43,49 @@ module.exports = function(ctx){ more: {type: CacheString, default: ''} }); - Post.virtual('path').get(function(){ + Post.virtual('path').get(function() { var path = ctx.execFilterSync('post_permalink', this, {context: ctx}); return typeof path === 'string' ? path : ''; }); - Post.virtual('permalink').get(function(){ + Post.virtual('permalink').get(function() { return ctx.config.url + '/' + this.path; }); - Post.virtual('full_source').get(function(){ + Post.virtual('full_source').get(function() { return pathFn.join(ctx.source_dir, this.source || ''); }); - Post.virtual('asset_dir').get(function(){ + Post.virtual('asset_dir').get(function() { var src = this.full_source; return src.substring(0, src.length - pathFn.extname(src).length) + pathFn.sep; }); - Post.virtual('tags').get(function(){ + Post.virtual('tags').get(function() { var PostTag = ctx.model('PostTag'); var Tag = ctx.model('Tag'); - var ids = PostTag.find({post_id: this._id}).map(function(item){ + var ids = PostTag.find({post_id: this._id}).map(function(item) { return item.tag_id; }); return Tag.find({_id: {$in: ids}}).sort('name'); }); - Post.method('setTags', function(tags){ + Post.method('setTags', function(tags) { var PostTag = ctx.model('PostTag'); var Tag = ctx.model('Tag'); var id = this._id; var existed = PostTag.find({post_id: id}).map(pickID); - return Promise.map(tags, function(tag){ + return Promise.map(tags, function(tag) { // Find the tag by name var data = Tag.findOne({name: tag}); if (data) return data; // Insert the tag if not exist return Tag.insert({name: tag}); - }).map(function(tag){ + }).map(function(tag) { // Find the reference var ref = PostTag.findOne({post_id: id, tag_id: tag._id}); if (ref) return ref; @@ -95,27 +95,27 @@ module.exports = function(ctx){ post_id: id, tag_id: tag._id }); - }).then(function(tags){ + }).then(function(tags) { // Remove old tags var deleted = _.difference(existed, tags.map(pickID)); return deleted; - }).map(function(tag){ + }).map(function(tag) { return PostTag.removeById(tag); }); }); - Post.virtual('categories').get(function(){ + Post.virtual('categories').get(function() { var PostCategory = ctx.model('PostCategory'); var Category = ctx.model('Category'); - var ids = PostCategory.find({post_id: this._id}).map(function(item){ + var ids = PostCategory.find({post_id: this._id}).map(function(item) { return item.category_id; }); return Category.find({_id: {$in: ids}}); }); - Post.method('setCategories', function(cats){ + Post.method('setCategories', function(cats) { var PostCategory = ctx.model('PostCategory'); var Category = ctx.model('Category'); var id = this._id; @@ -124,14 +124,14 @@ module.exports = function(ctx){ // Don't use "Promise.map". It doesn't run in series. // MUST USE "Promise.each". - return Promise.each(cats, function(cat, i){ + return Promise.each(cats, function(cat, i) { // Find the category by name var data = Category.findOne({ name: cat, parent: i ? arr[i - 1] : {$exists: false} }); - if (data){ + if (data) { arr.push(data._id); return data; } @@ -140,11 +140,11 @@ module.exports = function(ctx){ var obj = {name: cat}; if (i) obj.parent = arr[i - 1]; - return Category.insert(obj).then(function(data){ + return Category.insert(obj).then(function(data) { arr.push(data._id); return data; }); - }).map(function(){ + }).map(function() { // Get the index from the second argument // and get the category id from arr. var cat = arr[arguments[1]]; @@ -158,32 +158,32 @@ module.exports = function(ctx){ post_id: id, category_id: cat }); - }).then(function(cats){ + }).then(function(cats) { // Remove old categories var deleted = _.difference(existed, cats.map(pickID)); return deleted; - }).map(function(cat){ + }).map(function(cat) { return PostCategory.removeById(cat); }); }); // Remove PostTag references - Post.pre('remove', function(data){ + Post.pre('remove', function(data) { var PostTag = ctx.model('PostTag'); return PostTag.remove({post_id: data._id}); }); // Remove PostCategory references - Post.pre('remove', function(data){ + Post.pre('remove', function(data) { var PostCategory = ctx.model('PostCategory'); return PostCategory.remove({post_id: data._id}); }); // Remove assets - Post.pre('remove', function(data){ + Post.pre('remove', function(data) { var PostAsset = ctx.model('PostAsset'); return PostAsset.remove({post: data._id}); }); return Post; -}; \ No newline at end of file +}; diff --git a/lib/models/post_asset.js b/lib/models/post_asset.js index c729df7524..6d78fe28da 100644 --- a/lib/models/post_asset.js +++ b/lib/models/post_asset.js @@ -4,7 +4,7 @@ var Schema = require('warehouse').Schema; var pathFn = require('path'); var url = require('url'); -module.exports = function(ctx){ +module.exports = function(ctx) { var PostAsset = new Schema({ _id: {type: String, required: true}, slug: {type: String, required: true}, @@ -12,7 +12,7 @@ module.exports = function(ctx){ post: {type: Schema.Types.CUID, ref: 'Post'} }); - PostAsset.virtual('path').get(function(){ + PostAsset.virtual('path').get(function() { var Post = ctx.model('Post'); var post = Post.findById(this.post); if (!post) return; @@ -20,9 +20,9 @@ module.exports = function(ctx){ return url.resolve(post.path, this.slug); }); - PostAsset.virtual('source').get(function(){ + PostAsset.virtual('source').get(function() { return pathFn.join(ctx.base_dir, this._id); }); return PostAsset; -}; \ No newline at end of file +}; diff --git a/lib/models/post_category.js b/lib/models/post_category.js index 6c79dcb599..83ecf5e086 100644 --- a/lib/models/post_category.js +++ b/lib/models/post_category.js @@ -2,11 +2,11 @@ var Schema = require('warehouse').Schema; -module.exports = function(ctx){ +module.exports = function(ctx) { var PostCategory = new Schema({ post_id: {type: Schema.Types.CUID, ref: 'Post'}, category_id: {type: Schema.Types.CUID, ref: 'Category'} }); return PostCategory; -}; \ No newline at end of file +}; diff --git a/lib/models/post_tag.js b/lib/models/post_tag.js index b4978efa60..d63527d73e 100644 --- a/lib/models/post_tag.js +++ b/lib/models/post_tag.js @@ -2,11 +2,11 @@ var Schema = require('warehouse').Schema; -module.exports = function(ctx){ +module.exports = function(ctx) { var PostTag = new Schema({ post_id: {type: Schema.Types.CUID, ref: 'Post'}, tag_id: {type: Schema.Types.CUID, ref: 'Tag'} }); return PostTag; -}; \ No newline at end of file +}; diff --git a/lib/models/tag.js b/lib/models/tag.js index efe5e28496..ef127aac13 100644 --- a/lib/models/tag.js +++ b/lib/models/tag.js @@ -4,12 +4,12 @@ var Schema = require('warehouse').Schema; var util = require('hexo-util'); var slugize = util.slugize; -module.exports = function(ctx){ +module.exports = function(ctx) { var Tag = new Schema({ name: {type: String, required: true} }); - Tag.virtual('slug').get(function(){ + Tag.virtual('slug').get(function() { var map = ctx.config.tag_map || {}; var name = this.name; if (!name) return; @@ -18,21 +18,21 @@ module.exports = function(ctx){ return slugize(name, {transform: ctx.config.filename_case}); }); - Tag.virtual('path').get(function(){ + Tag.virtual('path').get(function() { var tagDir = ctx.config.tag_dir; if (tagDir[tagDir.length - 1] !== '/') tagDir += '/'; return tagDir + this.slug + '/'; }); - Tag.virtual('permalink').get(function(){ + Tag.virtual('permalink').get(function() { return ctx.config.url + '/' + this.path; }); - Tag.virtual('posts').get(function(){ + Tag.virtual('posts').get(function() { var PostTag = ctx.model('PostTag'); - var ids = PostTag.find({tag_id: this._id}).map(function(item){ + var ids = PostTag.find({tag_id: this._id}).map(function(item) { return item.post_id; }); @@ -41,28 +41,28 @@ module.exports = function(ctx){ }); }); - Tag.virtual('length').get(function(){ + Tag.virtual('length').get(function() { return this.posts.length; }); // Check whether a tag exists - Tag.pre('save', function(data){ + Tag.pre('save', function(data) { var name = data.name; if (!name) return; var Tag = ctx.model('Tag'); var tag = Tag.findOne({name: name}); - if (tag){ + if (tag) { throw new Error('Tag `' + name + '` has already existed!'); } }); // Remove PostTag references - Tag.pre('remove', function(data){ + Tag.pre('remove', function(data) { var PostTag = ctx.model('PostTag'); return PostTag.remove({tag_id: data._id}); }); return Tag; -}; \ No newline at end of file +}; diff --git a/lib/models/types/cachestring.js b/lib/models/types/cachestring.js index 495b33edb9..69fc0a4f99 100644 --- a/lib/models/types/cachestring.js +++ b/lib/models/types/cachestring.js @@ -3,15 +3,15 @@ var SchemaTypeString = require('warehouse').Schema.Types.String; var util = require('util'); -function SchemaTypeCacheString(name, options){ +function SchemaTypeCacheString(name, options) { SchemaTypeString.call(this, name, options); } util.inherits(SchemaTypeCacheString, SchemaTypeString); -SchemaTypeCacheString.prototype.value = function(){ +SchemaTypeCacheString.prototype.value = function() { // Return nothing so warehouse won't save this field return; }; -module.exports = SchemaTypeCacheString; \ No newline at end of file +module.exports = SchemaTypeCacheString; diff --git a/lib/models/types/moment.js b/lib/models/types/moment.js index 5d15e21d74..dfeda95d5d 100644 --- a/lib/models/types/moment.js +++ b/lib/models/types/moment.js @@ -4,20 +4,20 @@ var moment = require('moment-timezone'); var SchemaType = require('warehouse').SchemaType; var util = require('util'); -function SchemaTypeMoment(name, options){ +function SchemaTypeMoment(name, options) { SchemaType.call(this, name, options); } util.inherits(SchemaTypeMoment, SchemaType); -function toMoment(value){ +function toMoment(value) { // FIXME: Something is wrong when using a moment instance. I try to get the // original date object and create a new moment object again. if (moment.isMoment(value)) return moment(value._d); return moment(value); } -SchemaTypeMoment.prototype.cast = function(value, data){ +SchemaTypeMoment.prototype.cast = function(value, data) { value = SchemaType.prototype.cast.call(this, value, data); if (value == null) return value; @@ -30,69 +30,63 @@ SchemaTypeMoment.prototype.cast = function(value, data){ return value; }; -SchemaTypeMoment.prototype.validate = function(value, data){ +SchemaTypeMoment.prototype.validate = function(value, data) { value = SchemaType.prototype.validate.call(this, value, data); if (value instanceof Error) return value; if (value == null) return value; value = toMoment(value); - if (!value.isValid()){ + if (!value.isValid()) { return new Error('`' + value + '` is not a valid date!'); } return value; }; -SchemaTypeMoment.prototype.match = function(value, query, data){ +SchemaTypeMoment.prototype.match = function(value, query, data) { return value ? value.valueOf() === query.valueOf() : false; }; -SchemaTypeMoment.prototype.compare = function(a, b){ - if (a){ - if (b){ // a && b - return a - b; - } else { // a && !b - return 1; - } - } else { - if (b){ // !a && b - return -1; - } else { // !a && !b - return 0; - } +SchemaTypeMoment.prototype.compare = function(a, b) { + if (a) { + if (b) return a - b; + return 1; } + + if (b) return -1; + return 0; }; -SchemaTypeMoment.prototype.parse = function(value, data){ +SchemaTypeMoment.prototype.parse = function(value, data) { if (value) return toMoment(value); }; -SchemaTypeMoment.prototype.value = function(value, data){ +SchemaTypeMoment.prototype.value = function(value, data) { // FIXME: Same as above. Also a dirty hack. return value ? value._d.toISOString() : value; }; -SchemaTypeMoment.prototype.q$day = function(value, query, data){ +SchemaTypeMoment.prototype.q$day = function(value, query, data) { return value ? value.date() === query : false; }; -SchemaTypeMoment.prototype.q$month = function(value, query, data){ +SchemaTypeMoment.prototype.q$month = function(value, query, data) { return value ? value.month() === query : false; }; -SchemaTypeMoment.prototype.q$year = function(value, query, data){ +SchemaTypeMoment.prototype.q$year = function(value, query, data) { return value ? value.year() === query : false; }; -SchemaTypeMoment.prototype.u$inc = function(value, update, data){ +SchemaTypeMoment.prototype.u$inc = function(value, update, data) { if (!value) return value; return value.add(update); }; -SchemaTypeMoment.prototype.u$dec = function(value, update, data){ +SchemaTypeMoment.prototype.u$dec = function(value, update, data) { if (!value) return value; return value.subtract(update); }; -module.exports = SchemaTypeMoment; \ No newline at end of file +module.exports = SchemaTypeMoment; diff --git a/lib/plugins/console/clean.js b/lib/plugins/console/clean.js index a12b00998d..8d975b621d 100644 --- a/lib/plugins/console/clean.js +++ b/lib/plugins/console/clean.js @@ -3,36 +3,35 @@ var Promise = require('bluebird'); var fs = require('hexo-fs'); -function cleanConsole(args){ - /* jshint validthis: true */ +function cleanConsole(args) { return Promise.all([ deleteDatabase(this), deletePublicDir(this) ]); } -function deleteDatabase(ctx){ +function deleteDatabase(ctx) { var dbPath = ctx.database.options.path; - return fs.exists(dbPath).then(function(exist){ + return fs.exists(dbPath).then(function(exist) { if (!exist) return; - return fs.unlink(dbPath).then(function(){ + return fs.unlink(dbPath).then(function() { ctx.log.info('Deleted database.'); }); }); } -function deletePublicDir(ctx){ +function deletePublicDir(ctx) { var publicDir = ctx.public_dir; - return fs.exists(publicDir).then(function(exist){ + return fs.exists(publicDir).then(function(exist) { if (!exist) return; - return fs.rmdir(publicDir).then(function(){ + return fs.rmdir(publicDir).then(function() { ctx.log.info('Deleted public folder.'); }); }); } -module.exports = cleanConsole; \ No newline at end of file +module.exports = cleanConsole; diff --git a/lib/plugins/console/config.js b/lib/plugins/console/config.js index 8c6d4f5d2d..2abd3e7338 100644 --- a/lib/plugins/console/config.js +++ b/lib/plugins/console/config.js @@ -4,18 +4,17 @@ var yaml = require('js-yaml'); var fs = require('hexo-fs'); var pathFn = require('path'); -function configConsole(args){ - /* jshint validthis: true */ +function configConsole(args) { var key = args._[0]; var value = args._[1]; var self = this; - if (!key){ + if (!key) { console.log(this.config); return; } - if (!value){ + if (!value) { value = getProperty(this.config, key); if (value) console.log(value); return; @@ -24,17 +23,17 @@ function configConsole(args){ var configPath = this.config_path; var extname = pathFn.extname(configPath); - return fs.exists(configPath).then(function(exist){ + return fs.exists(configPath).then(function(exist) { if (!exist) return {}; return self.render.render({path: configPath}); - }).then(function(config){ + }).then(function(config) { if (!config) config = {}; var result = ''; setProperty(config, key, castValue(value)); - if (extname === '.json'){ + if (extname === '.json') { result = JSON.stringify(config); } else { result = yaml.safeDump(config); @@ -44,24 +43,24 @@ function configConsole(args){ }); } -function getProperty(obj, key){ +function getProperty(obj, key) { var split = key.split('.'); var result = obj[split[0]]; - for (var i = 1, len = split.length; i < len; i++){ + for (var i = 1, len = split.length; i < len; i++) { result = result[split[i]]; } return result; } -function setProperty(obj, key, value){ +function setProperty(obj, key, value) { var split = key.split('.'); var cursor = obj; var name = ''; var lastKey = split.pop(); - for (var i = 0, len = split.length; i < len; i++){ + for (var i = 0, len = split.length; i < len; i++) { name = split[i]; cursor = cursor[name] = cursor[name] || {}; } @@ -69,7 +68,7 @@ function setProperty(obj, key, value){ cursor[lastKey] = value; } -function castValue(value){ +function castValue(value) { switch (value){ case 'true': return true; @@ -90,4 +89,4 @@ function castValue(value){ return value; } -module.exports = configConsole; \ No newline at end of file +module.exports = configConsole; diff --git a/lib/plugins/console/deploy.js b/lib/plugins/console/deploy.js index b7ebcc308e..fb4b51aba0 100644 --- a/lib/plugins/console/deploy.js +++ b/lib/plugins/console/deploy.js @@ -5,13 +5,12 @@ var fs = require('hexo-fs'); var chalk = require('chalk'); var Promise = require('bluebird'); -function deployConsole(args){ - /* jshint validthis: true */ +function deployConsole(args) { var config = this.config.deploy; var deployers = this.extend.deployer.list(); var self = this; - if (!config){ + if (!config) { var help = ''; help += 'You should configure deployment settings in _config.yml first!\n\n'; @@ -23,42 +22,42 @@ function deployConsole(args){ return; } - return new Promise(function(resolve, reject){ + return new Promise(function(resolve, reject) { var generateArgs = _.clone(args); generateArgs.d = false; generateArgs.deploy = false; - if (args.g || args.generate){ + if (args.g || args.generate) { self.call('generate', args).then(resolve, reject); } else { - fs.exists(self.public_dir, function(exist){ + fs.exists(self.public_dir, function(exist) { if (exist) return resolve(); self.call('generate', args).then(resolve, reject); }); } - }).then(function(){ + }).then(function() { self.emit('deployBefore'); if (!Array.isArray(config)) config = [config]; return config; - }).each(function(item){ + }).each(function(item) { if (!item.type) return; var type = item.type; - if (!deployers[type]){ + if (!deployers[type]) { self.log.error('Deployer not found: %s', chalk.magenta(type)); return; } self.log.info('Deploying: %s', chalk.magenta(type)); - return deployers[type].call(self, _.extend({}, item, args)).then(function(){ + return deployers[type].call(self, _.extend({}, item, args)).then(function() { self.log.info('Deploy done: %s', chalk.magenta(type)); }); - }).then(function(){ + }).then(function() { self.emit('deployAfter'); }); } -module.exports = deployConsole; \ No newline at end of file +module.exports = deployConsole; diff --git a/lib/plugins/console/generate.js b/lib/plugins/console/generate.js index aae21e46b8..7104e86190 100644 --- a/lib/plugins/console/generate.js +++ b/lib/plugins/console/generate.js @@ -10,8 +10,7 @@ var ShasumStream = require('../../box/shasum_stream'); var join = pathFn.join; -function generateConsole(args){ - /* jshint validthis: true */ +function generateConsole(args) { var force = args.f || args.force; var route = this.route; var publicDir = this.public_dir; @@ -20,41 +19,41 @@ function generateConsole(args){ var start = process.hrtime(); var Cache = this.model('Cache'); - function generateFile(path){ + function generateFile(path) { var dest = join(publicDir, path); - return fs.exists(dest).then(function(exist){ + return fs.exists(dest).then(function(exist) { if (!force && exist && !route.isModified(path)) return; - return checkShasum(path).then(function(changed){ + return checkShasum(path).then(function(changed) { if (force || changed || !exist) return writeFile(path); }); }); } - function writeFile(path){ + function writeFile(path) { var dest = join(publicDir, path); - return fs.ensureWriteStream(dest).then(function(stream){ + return fs.ensureWriteStream(dest).then(function(stream) { if (!stream) return false; - return pipeStream(route.get(path), stream).then(function(){ + return pipeStream(route.get(path), stream).then(function() { log.info('Generated: %s', chalk.magenta(path)); return true; }); }); } - function checkShasum(path){ + function checkShasum(path) { var data = route.get(path); var id = 'public/' + path; var stream = new ShasumStream(); - return pipeStream(data, stream).then(function(){ + return pipeStream(data, stream).then(function() { var shasum = stream.getShasum(); var cache = Cache.findById(id); - if (cache){ + if (cache) { if (cache.shasum === shasum) return; } else { cache = Cache.new({_id: id}); @@ -67,34 +66,34 @@ function generateConsole(args){ }); } - function deleteFile(path){ + function deleteFile(path) { var dest = join(publicDir, path); - return fs.unlink(dest).then(function(){ + return fs.unlink(dest).then(function() { log.info('Deleted: %s', chalk.magenta(path)); - }, function(err){ + }, function(err) { // Skip ENOENT errors (file was deleted) if (err.cause.code !== 'ENOENT') throw err; }); } - function generateFiles(files){ + function generateFiles(files) { var list = route.list(); - return Promise.reduce(list, function(result, path){ - return generateFile(path).then(function(success){ - return success ? result + 1 : result; + return Promise.reduce(list, function(result, path) { + return generateFile(path).then(function(success) { + return success ? result + 1 : result; }); }, 0); } - function cleanFiles(files){ + function cleanFiles(files) { var deleted = _.difference(files, route.list()); return Promise.map(deleted, deleteFile); } - function firstGenerate(){ + function firstGenerate() { // Show the loading time var interval = prettyHrtime(process.hrtime(start)); log.info('Files loaded in %s', chalk.cyan(interval)); @@ -103,55 +102,55 @@ function generateConsole(args){ start = process.hrtime(); // Check the existance of public folder - return fs.exists(publicDir).then(function(exist){ - if (!exist){ + return fs.exists(publicDir).then(function(exist) { + if (!exist) { // Create public folder if not exist return fs.mkdirs(publicDir); } // Get current file list in public folder - return fs.listDir(publicDir).map(function(path){ + return fs.listDir(publicDir).map(function(path) { return path.replace(/\\/g, '/'); }); - }).then(function(files){ + }).then(function(files) { files = files || []; return Promise.all([ generateFiles(files), cleanFiles(files) ]); - }).spread(function(count){ + }).spread(function(count) { var interval = prettyHrtime(process.hrtime(start)); log.info('%d files generated in %s', count, chalk.cyan(interval)); }); } - if (args.w || args.watch){ - return this.watch().then(firstGenerate).then(function(){ + if (args.w || args.watch) { + return this.watch().then(firstGenerate).then(function() { log.info('Hexo is watching for file changes. Press Ctrl+C to exit.'); // Watch changes of the route - route.on('update', function(path){ + route.on('update', function(path) { var modified = route.isModified(path); if (!modified) return; generateFile(path); - }).on('remove', function(path){ + }).on('remove', function(path) { deleteFile(path); }); }); } - return this.load().then(firstGenerate).then(function(){ - if (args.d || args.deploy){ + return this.load().then(firstGenerate).then(function() { + if (args.d || args.deploy) { return self.call('deploy', args); } }); } // Pipe a stream from one to another -function pipeStream(rs, ws){ - return new Promise(function(resolve, reject){ +function pipeStream(rs, ws) { + return new Promise(function(resolve, reject) { rs.pipe(ws) .on('error', reject) .on('finish', resolve); diff --git a/lib/plugins/console/help.js b/lib/plugins/console/help.js index c8a52aac8e..be1e039e22 100644 --- a/lib/plugins/console/help.js +++ b/lib/plugins/console/help.js @@ -2,18 +2,18 @@ var chalk = require('chalk'); -module.exports = function(args){ +module.exports = function(args) { var command = args._[0]; var list = this.extend.console.list(); - if (list.hasOwnProperty(command) && command !== 'help'){ + if (list.hasOwnProperty(command) && command !== 'help') { printHelpForCommand(command, list[command]); } else { printAllHelp(list); } }; -function printHelpForCommand(command, data){ +function printHelpForCommand(command, data) { var options = data.options; console.log('Usage: hexo', command, options.usage || ''); @@ -25,12 +25,12 @@ function printHelpForCommand(command, data){ if (options.options) printList('Options', options.options); } -function printAllHelp(list){ +function printAllHelp(list) { var keys = Object.keys(list); var commands = []; var key = ''; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; commands.push({ @@ -56,7 +56,7 @@ function printAllHelp(list){ console.log('or you can check the docs:', chalk.underline('http://hexo.io/docs/')); } -function printList(title, list){ +function printList(title, list) { var length = 0; var str = title + ':\n'; @@ -64,18 +64,19 @@ function printList(title, list){ length = Math.max(length, item.name.length); }); - list.sort(function(a, b){ + list.sort(function(a, b) { var nameA = a.name; var nameB = b.name; - + if (nameA < nameB) return -1; else if (nameA > nameB) return 1; - else return 0; - }).forEach(function(item){ + + return 0; + }).forEach(function(item) { var padding = length - item.name.length + 2; str += ' ' + chalk.bold(item.name); - while (padding--){ + while (padding--) { str += ' '; } @@ -83,4 +84,4 @@ function printList(title, list){ }); console.log(str); -} \ No newline at end of file +} diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index c1c88553f0..6e3e03ed1a 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var console = ctx.extend.console; console.register('clean', 'Removed generated files and cache.', require('./clean')); @@ -89,4 +89,4 @@ module.exports = function(ctx){ console.register('version', 'Display version information.', { init: true }, require('./version')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/console/init.js b/lib/plugins/console/init.js index efd6a83676..1b8ed79811 100644 --- a/lib/plugins/console/init.js +++ b/lib/plugins/console/init.js @@ -1,3 +1,3 @@ 'use strict'; -module.exports = require('hexo-cli').console.init; \ No newline at end of file +module.exports = require('hexo-cli').console.init; diff --git a/lib/plugins/console/list/common.js b/lib/plugins/console/list/common.js index 6f41c81c01..9f51bd3a2c 100644 --- a/lib/plugins/console/list/common.js +++ b/lib/plugins/console/list/common.js @@ -2,18 +2,18 @@ var strip = require('chalk').stripColor; -exports.stringLength = function(str){ +exports.stringLength = function(str) { str = strip(str); var len = str.length; var result = len; // Detect double-byte characters - for (var i = 0; i < len; i++){ - if (str.charCodeAt(i) > 255){ + for (var i = 0; i < len; i++) { + if (str.charCodeAt(i) > 255) { result++; } } return result; -}; \ No newline at end of file +}; diff --git a/lib/plugins/console/list/index.js b/lib/plugins/console/list/index.js index 681e11e31b..455a1d0906 100644 --- a/lib/plugins/console/list/index.js +++ b/lib/plugins/console/list/index.js @@ -7,19 +7,18 @@ var store = { tag: require('./tag') }; -function listConsole(args){ - /* jshint validthis: true */ +function listConsole(args) { var type = args._.shift(); var self = this; // Display help message if user didn't input any arguments - if (!type || !store.hasOwnProperty(type)){ + if (!type || !store.hasOwnProperty(type)) { return this.call('help', {_: ['list']}); } - return this.load().then(function(){ + return this.load().then(function() { return store[type].call(self, args); }); } -module.exports = listConsole; \ No newline at end of file +module.exports = listConsole; diff --git a/lib/plugins/console/list/page.js b/lib/plugins/console/list/page.js index 9c51b3ace1..69ef3efc2b 100644 --- a/lib/plugins/console/list/page.js +++ b/lib/plugins/console/list/page.js @@ -4,17 +4,16 @@ var chalk = require('chalk'); var table = require('text-table'); var common = require('./common'); -function listPage(){ - /* jshint validthis: true */ +function listPage() { var Page = this.model('Page'); - var data = Page.sort({date: 1}).map(function(page){ + var data = Page.sort({date: 1}).map(function(page) { var date = page.date.format('YYYY-MM-DD'); return [chalk.gray(date), page.title, chalk.magenta(page.source)]; }); // Table header - var header = ['Date', 'Title', 'Path'].map(function(str){ + var header = ['Date', 'Title', 'Path'].map(function(str) { return chalk.underline(str); }); @@ -28,4 +27,4 @@ function listPage(){ if (data.length === 1) console.log('No pages.'); } -module.exports = listPage; \ No newline at end of file +module.exports = listPage; diff --git a/lib/plugins/console/list/post.js b/lib/plugins/console/list/post.js index 7867fdf38a..6d43bfbd14 100644 --- a/lib/plugins/console/list/post.js +++ b/lib/plugins/console/list/post.js @@ -4,17 +4,16 @@ var chalk = require('chalk'); var table = require('text-table'); var common = require('./common'); -function listPost(){ - /* jshint validthis: true */ +function listPost() { var Post = this.model('Post'); - var data = Post.sort({published: -1, date: 1}).map(function(post){ + var data = Post.sort({published: -1, date: 1}).map(function(post) { var date = post.published ? post.date.format('YYYY-MM-DD') : 'Draft'; return [chalk.gray(date), post.title, chalk.magenta(post.source)]; }); // Table header - var header = ['Date', 'Title', 'Path'].map(function(str){ + var header = ['Date', 'Title', 'Path'].map(function(str) { return chalk.underline(str); }); @@ -28,4 +27,4 @@ function listPost(){ if (data.length === 1) console.log('No posts.'); } -module.exports = listPost; \ No newline at end of file +module.exports = listPost; diff --git a/lib/plugins/console/list/route.js b/lib/plugins/console/list/route.js index ee59105223..ef00949b48 100644 --- a/lib/plugins/console/list/route.js +++ b/lib/plugins/console/list/route.js @@ -2,8 +2,7 @@ var archy = require('archy'); -function listRoute(){ - /* jshint validthis: true */ +function listRoute() { var routes = this.route.list().sort(); var tree = buildTree(routes); var nodes = buildNodes(tree); @@ -16,15 +15,15 @@ function listRoute(){ console.log(s); } -function buildTree(routes){ +function buildTree(routes) { var obj = {}; var item, j, lenj, seg, cursor; - for (var i = 0, len = routes.length; i < len; i++){ + for (var i = 0, len = routes.length; i < len; i++) { item = routes[i].split('/'); cursor = obj; - for (j = 0, lenj = item.length; j < lenj; j++){ + for (j = 0, lenj = item.length; j < lenj; j++) { seg = item[j]; cursor = cursor[seg] = cursor[seg] || {}; } @@ -33,16 +32,16 @@ function buildTree(routes){ return obj; } -function buildNodes(tree){ +function buildNodes(tree) { var keys = Object.keys(tree); var nodes = []; var key, item; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; item = tree[key]; - if (Object.keys(item).length){ + if (Object.keys(item).length) { nodes.push({ label: key, nodes: buildNodes(item) @@ -55,4 +54,4 @@ function buildNodes(tree){ return nodes; } -module.exports = listRoute; \ No newline at end of file +module.exports = listRoute; diff --git a/lib/plugins/console/list/tag.js b/lib/plugins/console/list/tag.js index 685f9b2b8f..4477c0dc9c 100644 --- a/lib/plugins/console/list/tag.js +++ b/lib/plugins/console/list/tag.js @@ -4,16 +4,15 @@ var chalk = require('chalk'); var table = require('text-table'); var common = require('./common'); -function listTag(){ - /* jshint validthis: true */ +function listTag() { var Tag = this.model('Tag'); - var data = Tag.sort({name: 1}).map(function(tag){ + var data = Tag.sort({name: 1}).map(function(tag) { return [tag.name, String(tag.length), chalk.magenta(tag.path)]; }); // Table header - var header = ['Name', 'Posts', 'Path'].map(function(str){ + var header = ['Name', 'Posts', 'Path'].map(function(str) { return chalk.underline(str); }); @@ -28,4 +27,4 @@ function listTag(){ if (data.length === 1) console.log('No tags.'); } -module.exports = listTag; \ No newline at end of file +module.exports = listTag; diff --git a/lib/plugins/console/migrate.js b/lib/plugins/console/migrate.js index 5ffbd2c9ab..1cb64348e1 100644 --- a/lib/plugins/console/migrate.js +++ b/lib/plugins/console/migrate.js @@ -2,17 +2,16 @@ var chalk = require('chalk'); -function migrateConsole(args){ - /* jshint validthis: true */ +function migrateConsole(args) { // Display help message if user didn't input any arguments - if (!args._.length){ + if (!args._.length) { return this.call('help', {_: ['migrate']}); } var type = args._.shift(); var migrators = this.extend.migrator.list(); - if (!migrators[type]){ + if (!migrators[type]) { var help = ''; help += type.magenta + ' migrator plugin is not installed.\n\n'; @@ -27,4 +26,4 @@ function migrateConsole(args){ return migrators[type].call(this, args); } -module.exports = migrateConsole; \ No newline at end of file +module.exports = migrateConsole; diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.js index 65a63a332e..e2c847a4bf 100644 --- a/lib/plugins/console/new.js +++ b/lib/plugins/console/new.js @@ -17,10 +17,9 @@ var reservedKeys = { silent: true }; -function newConsole(args){ - /* jshint validthis: true */ +function newConsole(args) { // Display help message if user didn't input any arguments - if (!args._.length){ + if (!args._.length) { return this.call('help', {_: ['new']}); } @@ -35,14 +34,14 @@ function newConsole(args){ var key = ''; var self = this; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; if (!reservedKeys[key]) data[key] = args[key]; } - return this.post.create(data, args.r || args.replace).then(function(post){ + return this.post.create(data, args.r || args.replace).then(function(post) { self.log.info('Created: %s', chalk.magenta(tildify(post.path))); }); } -module.exports = newConsole; \ No newline at end of file +module.exports = newConsole; diff --git a/lib/plugins/console/publish.js b/lib/plugins/console/publish.js index 2f5b314a54..1ae3ae6dd1 100644 --- a/lib/plugins/console/publish.js +++ b/lib/plugins/console/publish.js @@ -3,10 +3,9 @@ var tildify = require('tildify'); var chalk = require('chalk'); -function publishConsole(args){ - /* jshint validthis: true */ +function publishConsole(args) { // Display help message if user didn't input any arguments - if (!args._.length){ + if (!args._.length) { return this.call('help', {_: ['publish']}); } @@ -15,9 +14,9 @@ function publishConsole(args){ return this.post.publish({ slug: args._.pop(), layout: args._.length ? args._[0] : this.config.default_layout - }, args.r || args.replace).then(function(post){ + }, args.r || args.replace).then(function(post) { self.log.info('Published: %s', chalk.magenta(tildify(post.path))); }); } -module.exports = publishConsole; \ No newline at end of file +module.exports = publishConsole; diff --git a/lib/plugins/console/render.js b/lib/plugins/console/render.js index c190004aaa..e10c42b935 100644 --- a/lib/plugins/console/render.js +++ b/lib/plugins/console/render.js @@ -6,10 +6,9 @@ var prettyHrtime = require('pretty-hrtime'); var fs = require('hexo-fs'); var chalk = require('chalk'); -function renderConsole(args){ - /* jshint validthis: true */ +function renderConsole(args) { // Display help message if user didn't input any arguments - if (!args._.length){ + if (!args._.length) { return this.call('help', {_: 'render'}); } @@ -22,9 +21,9 @@ function renderConsole(args){ return this.render.render({ path: src, engine: args.engine - }).then(function(result){ - if (typeof result === 'object'){ - if (args.pretty){ + }).then(function(result) { + if (typeof result === 'object') { + if (args.pretty) { result = JSON.stringify(result, null, ' '); } else { result = JSON.stringify(result); @@ -41,4 +40,4 @@ function renderConsole(args){ }); } -module.exports = renderConsole; \ No newline at end of file +module.exports = renderConsole; diff --git a/lib/plugins/console/version.js b/lib/plugins/console/version.js index 554fd16922..445e9fb5f0 100644 --- a/lib/plugins/console/version.js +++ b/lib/plugins/console/version.js @@ -2,7 +2,7 @@ var os = require('os'); -module.exports = function(args){ +module.exports = function(args) { var versions = process.versions; var keys = Object.keys(versions); var key = ''; @@ -10,8 +10,8 @@ module.exports = function(args){ console.log('hexo:', this.version); console.log('os:', os.type(), os.release(), os.platform(), os.arch()); - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; console.log('%s: %s', key, versions[key]); } -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/after_post_render/excerpt.js b/lib/plugins/filter/after_post_render/excerpt.js index 76831aefd2..16f3985684 100644 --- a/lib/plugins/filter/after_post_render/excerpt.js +++ b/lib/plugins/filter/after_post_render/excerpt.js @@ -2,11 +2,11 @@ var rExcerpt = //; -function excerptFilter(data){ +function excerptFilter(data) { var content = data.content; - if (rExcerpt.test(content)){ - data.content = content.replace(rExcerpt, function(match, index){ + if (rExcerpt.test(content)) { + data.content = content.replace(rExcerpt, function(match, index) { data.excerpt = content.substring(0, index).trim(); data.more = content.substring(index + match.length).trim(); @@ -18,4 +18,4 @@ function excerptFilter(data){ } } -module.exports = excerptFilter; \ No newline at end of file +module.exports = excerptFilter; diff --git a/lib/plugins/filter/after_post_render/external_link.js b/lib/plugins/filter/after_post_render/external_link.js index b77e7789c6..667b17cf7a 100644 --- a/lib/plugins/filter/after_post_render/external_link.js +++ b/lib/plugins/filter/after_post_render/external_link.js @@ -3,8 +3,7 @@ var url = require('url'); var cheerio; -function externalLinkFilter(data){ - /* jshint validthis: true */ +function externalLinkFilter(data) { var config = this.config; if (!config.external_link) return; @@ -13,7 +12,7 @@ function externalLinkFilter(data){ var $ = cheerio.load(data.content, {decodeEntities: false}); var siteHost = url.parse(config.url).hostname || config.url; - $('a').each(function(){ + $('a').each(function() { // Exit if the link has target attribute if ($(this).attr('target')) return; @@ -37,4 +36,4 @@ function externalLinkFilter(data){ data.content = $.html(); } -module.exports = externalLinkFilter; \ No newline at end of file +module.exports = externalLinkFilter; diff --git a/lib/plugins/filter/after_post_render/index.js b/lib/plugins/filter/after_post_render/index.js index 9fe745ff87..41d6104057 100644 --- a/lib/plugins/filter/after_post_render/index.js +++ b/lib/plugins/filter/after_post_render/index.js @@ -1,8 +1,8 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; filter.register('after_post_render', require('./excerpt')); filter.register('after_post_render', require('./external_link')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/before_exit/index.js b/lib/plugins/filter/before_exit/index.js index 3d61ce5001..3328865b2c 100644 --- a/lib/plugins/filter/before_exit/index.js +++ b/lib/plugins/filter/before_exit/index.js @@ -1,7 +1,7 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; filter.register('before_exit', require('./save_database')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/before_exit/save_database.js b/lib/plugins/filter/before_exit/save_database.js index 6ed116126b..7305077ed5 100644 --- a/lib/plugins/filter/before_exit/save_database.js +++ b/lib/plugins/filter/before_exit/save_database.js @@ -1,14 +1,13 @@ 'use strict'; -function saveDatabaseFilter(){ - /* jshint validthis: true */ +function saveDatabaseFilter() { if (!this.env.init) return; var self = this; - return this.database.save().then(function(){ + return this.database.save().then(function() { self.log.debug('Database saved'); }); } -module.exports = saveDatabaseFilter; \ No newline at end of file +module.exports = saveDatabaseFilter; diff --git a/lib/plugins/filter/before_generate/index.js b/lib/plugins/filter/before_generate/index.js index 06e55f7850..711ec0eb62 100644 --- a/lib/plugins/filter/before_generate/index.js +++ b/lib/plugins/filter/before_generate/index.js @@ -1,7 +1,7 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; filter.register('before_generate', require('./render_post')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/before_generate/render_post.js b/lib/plugins/filter/before_generate/render_post.js index 3ffc677649..ebb70ac810 100644 --- a/lib/plugins/filter/before_generate/render_post.js +++ b/lib/plugins/filter/before_generate/render_post.js @@ -2,15 +2,14 @@ var Promise = require('bluebird'); -function renderPostFilter(){ - /* jshint validthis: true */ +function renderPostFilter() { var self = this; - function renderPosts(model){ - return Promise.map(model.toArray(), function(post){ + function renderPosts(model) { + return Promise.map(model.toArray(), function(post) { post.content = post._content; - return self.post.render(post.full_source, post).then(function(){ + return self.post.render(post.full_source, post).then(function() { return post.save(); }); }); @@ -22,4 +21,4 @@ function renderPostFilter(){ ]); } -module.exports = renderPostFilter; \ No newline at end of file +module.exports = renderPostFilter; diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.js b/lib/plugins/filter/before_post_render/backtick_code_block.js index ceae602774..99f737dbca 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.js +++ b/lib/plugins/filter/before_post_render/backtick_code_block.js @@ -8,12 +8,11 @@ var rBacktick = /(\s*)(`{3,}|~{3,}) *(.*) *\n([\s\S]+?)\s*\2(\n+|$)/g; var rAllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/; var rLangCaption = /([^\s]+)\s*(.+)?/; -function backtickCodeBlock(data){ - /* jshint validthis: true */ +function backtickCodeBlock(data) { var config = this.config.highlight || {}; if (!config.enable) return; - data.content = data.content.replace(rBacktick, function(){ + data.content = data.content.replace(rBacktick, function() { var start = arguments[1]; var end = arguments[5]; var args = arguments[3]; @@ -25,22 +24,22 @@ function backtickCodeBlock(data){ tab: config.tab_replace }; - if (args){ + if (args) { var match; - if (rAllOptions.test(args)){ + if (rAllOptions.test(args)) { match = args.match(rAllOptions); - } else if (rLangCaption.test(args)){ + } else if (rLangCaption.test(args)) { match = args.match(rLangCaption); } if (match) { options.lang = match[1]; - if (match[2]){ + if (match[2]) { options.caption = '' + match[2] + ''; - if (match[3]){ + if (match[3]) { options.caption += '' + (match[4] ? match[4] : 'link') + ''; } } diff --git a/lib/plugins/filter/before_post_render/index.js b/lib/plugins/filter/before_post_render/index.js index 77b4afe9f6..0f7ef36813 100644 --- a/lib/plugins/filter/before_post_render/index.js +++ b/lib/plugins/filter/before_post_render/index.js @@ -1,8 +1,8 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; filter.register('before_post_render', require('./backtick_code_block')); filter.register('before_post_render', require('./titlecase')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/before_post_render/titlecase.js b/lib/plugins/filter/before_post_render/titlecase.js index 2d51c1b0ea..7f968602b6 100644 --- a/lib/plugins/filter/before_post_render/titlecase.js +++ b/lib/plugins/filter/before_post_render/titlecase.js @@ -2,11 +2,10 @@ var titlecase = require('titlecase'); -function titlecaseFilter(data){ - /* jshint validthis: true */ +function titlecaseFilter(data) { if (!this.config.titlecase || !data.title) return; data.title = titlecase(data.title); } -module.exports = titlecaseFilter; \ No newline at end of file +module.exports = titlecaseFilter; diff --git a/lib/plugins/filter/index.js b/lib/plugins/filter/index.js index 95b9c97061..70a93b857f 100644 --- a/lib/plugins/filter/index.js +++ b/lib/plugins/filter/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; require('./after_post_render')(ctx); @@ -11,4 +11,4 @@ module.exports = function(ctx){ filter.register('new_post_path', require('./new_post_path')); filter.register('post_permalink', require('./post_permalink')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/filter/new_post_path.js b/lib/plugins/filter/new_post_path.js index dfb892fb1b..b1a3fcbf01 100644 --- a/lib/plugins/filter/new_post_path.js +++ b/lib/plugins/filter/new_post_path.js @@ -18,8 +18,7 @@ var reservedKeys = { title: true }; -function newPostPathFilter(data, replace){ - /* jshint validthis: true */ +function newPostPathFilter(data, replace) { data = data || {}; var sourceDir = this.source_dir; @@ -33,11 +32,11 @@ function newPostPathFilter(data, replace){ var slug = data.slug; var target = ''; - if (!permalink || permalink.rule !== newPostName){ + if (!permalink || permalink.rule !== newPostName) { permalink = new Permalink(newPostName); } - if (path){ + if (path) { switch (layout){ case 'page': target = pathFn.join(sourceDir, path); @@ -50,7 +49,7 @@ function newPostPathFilter(data, replace){ default: target = pathFn.join(postDir, path); } - } else if (slug){ + } else if (slug) { switch (layout){ case 'page': target = pathFn.join(sourceDir, slug, 'index'); @@ -74,7 +73,7 @@ function newPostPathFilter(data, replace){ title: slug }; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; if (!reservedKeys[key]) filenameData[key] = data[key]; } @@ -86,15 +85,15 @@ function newPostPathFilter(data, replace){ return Promise.reject(new TypeError('Either data.path or data.slug is required!')); } - if (!pathFn.extname(target)){ + if (!pathFn.extname(target)) { target += pathFn.extname(newPostName) || '.md'; } - if (replace){ + if (replace) { return Promise.resolve(target); - } else { - return fs.ensurePath(target); } + + return fs.ensurePath(target); } -module.exports = newPostPathFilter; \ No newline at end of file +module.exports = newPostPathFilter; diff --git a/lib/plugins/filter/post_permalink.js b/lib/plugins/filter/post_permalink.js index 19b6bf2251..c660874f13 100644 --- a/lib/plugins/filter/post_permalink.js +++ b/lib/plugins/filter/post_permalink.js @@ -6,8 +6,7 @@ var pathFn = require('path'); var Permalink = util.Permalink; var permalink; -function postPermalinkFilter(data){ - /* jshint validthis: true */ +function postPermalinkFilter(data) { var config = this.config; var meta = { id: data.id || data._id, @@ -21,13 +20,13 @@ function postPermalinkFilter(data){ i_day: data.date.format('D') }; - if (!permalink || permalink.rule !== config.permalink){ + if (!permalink || permalink.rule !== config.permalink) { permalink = new Permalink(config.permalink); } var categories = data.categories; - if (categories.length){ + if (categories.length) { meta.category = categories.last().slug; } else { meta.category = config.default_category; @@ -36,7 +35,7 @@ function postPermalinkFilter(data){ var keys = Object.keys(data); var key = ''; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; if (meta.hasOwnProperty(key)) continue; @@ -48,4 +47,4 @@ function postPermalinkFilter(data){ return permalink.stringify(_.defaults(meta, config.permalink_defaults)); } -module.exports = postPermalinkFilter; \ No newline at end of file +module.exports = postPermalinkFilter; diff --git a/lib/plugins/filter/template_locals/i18n.js b/lib/plugins/filter/template_locals/i18n.js index f108016a64..e874590f92 100644 --- a/lib/plugins/filter/template_locals/i18n.js +++ b/lib/plugins/filter/template_locals/i18n.js @@ -4,8 +4,7 @@ var util = require('hexo-util'); var Pattern = util.Pattern; var _ = require('lodash'); -function i18nLocalsFilter(locals){ - /* jshint validthis: true */ +function i18nLocalsFilter(locals) { var i18n = this.theme.i18n; var config = this.config; var i18nDir = config.i18n_dir; @@ -13,11 +12,11 @@ function i18nLocalsFilter(locals){ var lang = page.lang || page.language; var i18nLanguages = i18n.list(); - if (!lang){ + if (!lang) { var pattern = new Pattern(i18nDir + '/*path'); var data = pattern.match(locals.path); - if (data && data.lang && ~i18nLanguages.indexOf(data.lang)){ + if (data && data.lang && ~i18nLanguages.indexOf(data.lang)) { lang = data.lang; page.canonical_path = data.path; } else { @@ -37,10 +36,10 @@ function i18nLocalsFilter(locals){ module.exports = i18nLocalsFilter; -function getFirstLanguage(lang){ - if (Array.isArray(lang)){ +function getFirstLanguage(lang) { + if (Array.isArray(lang)) { return lang[0]; } return lang; -} \ No newline at end of file +} diff --git a/lib/plugins/filter/template_locals/index.js b/lib/plugins/filter/template_locals/index.js index 347816827f..e36ce867ed 100644 --- a/lib/plugins/filter/template_locals/index.js +++ b/lib/plugins/filter/template_locals/index.js @@ -1,7 +1,7 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var filter = ctx.extend.filter; filter.register('template_locals', require('./i18n')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/generator/asset.js b/lib/plugins/generator/asset.js index af87caf9e6..890de6a25b 100644 --- a/lib/plugins/generator/asset.js +++ b/lib/plugins/generator/asset.js @@ -5,40 +5,39 @@ var Promise = require('bluebird'); var pathFn = require('path'); var chalk = require('chalk'); -function assetGenerator(locals){ - /* jshint validthis: true */ +function assetGenerator(locals) { var self = this; - function process(name){ - return Promise.filter(self.model(name).toArray(), function(asset){ - return fs.exists(asset.source).then(function(exist){ + function process(name) { + return Promise.filter(self.model(name).toArray(), function(asset) { + return fs.exists(asset.source).then(function(exist) { if (exist) return exist; return asset.remove().thenReturn(exist); }); - }).map(function(asset){ + }).map(function(asset) { var source = asset.source; var path = asset.path; var data = { modified: asset.modified }; - if (self.render.isRenderable(path)){ + if (self.render.isRenderable(path)) { // Replace extension name if the asset is renderable var extname = pathFn.extname(path); var filename = path.substring(0, path.length - extname.length); path = filename + '.' + self.render.getOutput(path); - data.data = function(){ + data.data = function() { return self.render.render({ path: source, toString: true - }).catch(function(err){ + }).catch(function(err) { self.log.error({err: err}, 'Asset render failed: %s', chalk.magenta(path)); }); }; } else { - data.data = function(){ + data.data = function() { return fs.createReadStream(source); }; } @@ -53,9 +52,9 @@ function assetGenerator(locals){ return Promise.all([ process('Asset'), process('PostAsset') - ]).then(function(data){ + ]).then(function(data) { return Array.prototype.concat.apply([], data); }); } -module.exports = assetGenerator; \ No newline at end of file +module.exports = assetGenerator; diff --git a/lib/plugins/generator/index.js b/lib/plugins/generator/index.js index cf6eb64ea5..fc0389f098 100644 --- a/lib/plugins/generator/index.js +++ b/lib/plugins/generator/index.js @@ -1,9 +1,9 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var generator = ctx.extend.generator; generator.register('asset', require('./asset')); generator.register('page', require('./page')); generator.register('post', require('./post')); -}; \ No newline at end of file +}; diff --git a/lib/plugins/generator/page.js b/lib/plugins/generator/page.js index 12508901fe..51398bd93b 100644 --- a/lib/plugins/generator/page.js +++ b/lib/plugins/generator/page.js @@ -3,51 +3,50 @@ var minimatch = require('minimatch'); var _ = require('lodash'); -function pageGenerator(locals){ - /* jshint validthis: true */ +function pageGenerator(locals) { var skipRender = this.config.skip_render || []; if (!Array.isArray(skipRender)) skipRender = [skipRender]; skipRender = _.compact(skipRender); var skipRenderLen = skipRender.length; - function isSkipRender(path){ + function isSkipRender(path) { if (!skipRenderLen) return false; - for (var i = 0; i < skipRenderLen; i++){ + for (var i = 0; i < skipRenderLen; i++) { if (minimatch(path, skipRender[i])) return true; } return false; } - return locals.pages.map(function(page){ + return locals.pages.map(function(page) { var layout = page.layout; var path = page.path; - if (isSkipRender(page.source)){ + if (isSkipRender(page.source)) { return { path: page.source, data: page.raw }; - } else if (!layout || layout === 'false'){ + } else if (!layout || layout === 'false') { return { path: path, data: page.content }; - } else { - var layouts = ['page', 'post', 'index']; - if (layout !== 'page') layouts.unshift(layout); - - return { - path: path, - layout: layouts, - data: _.extend({ - __page: true - }, page) - }; } + + var layouts = ['page', 'post', 'index']; + if (layout !== 'page') layouts.unshift(layout); + + return { + path: path, + layout: layouts, + data: _.extend({ + __page: true + }, page) + }; }); } -module.exports = pageGenerator; \ No newline at end of file +module.exports = pageGenerator; diff --git a/lib/plugins/generator/post.js b/lib/plugins/generator/post.js index 691254a1f6..d4529859fa 100644 --- a/lib/plugins/generator/post.js +++ b/lib/plugins/generator/post.js @@ -2,35 +2,35 @@ var _ = require('lodash'); -function postGenerator(locals){ +function postGenerator(locals) { var posts = locals.posts.sort('-date').toArray(); var length = posts.length; - return posts.map(function(post, i){ + return posts.map(function(post, i) { var layout = post.layout; var path = post.path; - if (!layout || layout === 'false'){ + if (!layout || layout === 'false') { return { path: path, data: post.content }; - } else { - if (i) post.prev = posts[i - 1]; - if (i < length - 1) post.next = posts[i + 1]; + } - var layouts = ['post', 'page', 'index']; - if (layout !== 'post') layouts.unshift(layout); + if (i) post.prev = posts[i - 1]; + if (i < length - 1) post.next = posts[i + 1]; - return { - path: path, - layout: layouts, - data: _.extend({ - __post: true - }, post) - }; - } + var layouts = ['post', 'page', 'index']; + if (layout !== 'post') layouts.unshift(layout); + + return { + path: path, + layout: layouts, + data: _.extend({ + __post: true + }, post) + }; }); } -module.exports = postGenerator; \ No newline at end of file +module.exports = postGenerator; diff --git a/lib/plugins/helper/css.js b/lib/plugins/helper/css.js index 373bcbdb28..42286ac9e9 100644 --- a/lib/plugins/helper/css.js +++ b/lib/plugins/helper/css.js @@ -1,16 +1,15 @@ 'use strict'; -function cssHelper(){ - /* jshint validthis: true */ +function cssHelper() { var result = ''; var path = ''; - for (var i = 0, len = arguments.length; i < len; i++){ + for (var i = 0, len = arguments.length; i < len; i++) { path = arguments[i]; if (i) result += '\n'; - if (Array.isArray(path)){ + if (Array.isArray(path)) { result += cssHelper.apply(this, path); } else { if (path.substring(path.length - 4, path.length) !== '.css') path += '.css'; @@ -21,4 +20,4 @@ function cssHelper(){ return result; } -module.exports = cssHelper; \ No newline at end of file +module.exports = cssHelper; diff --git a/lib/plugins/helper/date.js b/lib/plugins/helper/date.js index 038c9a735a..de3227a7c9 100644 --- a/lib/plugins/helper/date.js +++ b/lib/plugins/helper/date.js @@ -4,7 +4,7 @@ var moment = require('moment-timezone'); var isMoment = moment.isMoment; var isDate = require('util').isDate; -function output(date, format, lang, timezone){ +function output(date, format, lang, timezone) { if (date == null) date = moment(); if (!isMoment(date)) date = moment(isDate(date) ? date : new Date(date)); @@ -14,46 +14,42 @@ function output(date, format, lang, timezone){ return date.format(format); } -function toISOString(date){ - if (date == null){ +function toISOString(date) { + if (date == null) { return new Date().toISOString(); } - if (date instanceof Date || isMoment(date)){ + if (date instanceof Date || isMoment(date)) { return date.toISOString(); } return new Date(date).toISOString(); } -function dateHelper(date, format){ - /* jshint validthis: true */ +function dateHelper(date, format) { var config = this.config; return output(date, format || config.date_format, getLanguage(this), config.timezone); } -function timeHelper(date, format){ - /* jshint validthis: true */ +function timeHelper(date, format) { var config = this.config; return output(date, format || config.time_format, getLanguage(this), config.timezone); } -function fullDateHelper(date, format){ - /* jshint validthis: true */ - if (format){ +function fullDateHelper(date, format) { + if (format) { return output(date, format, getLanguage(this), this.config.timezone); - } else { - return this.date(date) + ' ' + this.time(date); } + + return this.date(date) + ' ' + this.time(date); } -function timeTagHelper(date, format){ - /* jshint validthis: true */ +function timeTagHelper(date, format) { var config = this.config; return ''; } -function getLanguage(ctx){ +function getLanguage(ctx) { return ctx.page.lang || ctx.page.language || ctx.config.language; } @@ -62,4 +58,4 @@ exports.date_xml = toISOString; exports.time = timeHelper; exports.full_date = fullDateHelper; exports.time_tag = timeTagHelper; -exports.moment = moment; \ No newline at end of file +exports.moment = moment; diff --git a/lib/plugins/helper/debug.js b/lib/plugins/helper/debug.js index 63133dc5c4..c0a6db091a 100644 --- a/lib/plugins/helper/debug.js +++ b/lib/plugins/helper/debug.js @@ -3,12 +3,12 @@ var util = require('util'); // this format object as string, resolves circular reference -function inspectObject(object, options){ +function inspectObject(object, options) { return util.inspect(object, options); } // wrapper to log to console -function log(){ +function log() { return console.log.apply(null, arguments); } diff --git a/lib/plugins/helper/favicon_tag.js b/lib/plugins/helper/favicon_tag.js index e5e850562b..a110e5020d 100644 --- a/lib/plugins/helper/favicon_tag.js +++ b/lib/plugins/helper/favicon_tag.js @@ -1,8 +1,7 @@ 'use strict'; -function faviconTagHelper(path){ - /* jshint validthis: true */ +function faviconTagHelper(path) { return ''; } -module.exports = faviconTagHelper; \ No newline at end of file +module.exports = faviconTagHelper; diff --git a/lib/plugins/helper/feed_tag.js b/lib/plugins/helper/feed_tag.js index 133b8c301a..35f18047ea 100644 --- a/lib/plugins/helper/feed_tag.js +++ b/lib/plugins/helper/feed_tag.js @@ -1,7 +1,6 @@ 'use strict'; -function feedTagHelper(path, options){ - /* jshint validthis: true */ +function feedTagHelper(path, options) { options = options || {}; var title = options.title || this.config.title; @@ -10,4 +9,4 @@ function feedTagHelper(path, options){ return ''; } -module.exports = feedTagHelper; \ No newline at end of file +module.exports = feedTagHelper; diff --git a/lib/plugins/helper/format.js b/lib/plugins/helper/format.js index 3cfab8edf7..c60998020a 100644 --- a/lib/plugins/helper/format.js +++ b/lib/plugins/helper/format.js @@ -5,7 +5,7 @@ var titlecase = require('titlecase'); exports.strip_html = exports.stripHTML = util.stripHTML; -exports.trim = function(str){ +exports.trim = function(str) { return str.trim(); }; @@ -13,4 +13,4 @@ exports.titlecase = titlecase; exports.word_wrap = exports.wordWrap = util.wordWrap; -exports.truncate = util.truncate; \ No newline at end of file +exports.truncate = util.truncate; diff --git a/lib/plugins/helper/fragment_cache.js b/lib/plugins/helper/fragment_cache.js index ceff89f96f..83a371c050 100644 --- a/lib/plugins/helper/fragment_cache.js +++ b/lib/plugins/helper/fragment_cache.js @@ -1,12 +1,12 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var cache = {}; - return function fragmentCache(id, fn){ + return function fragmentCache(id, fn) { if (this.cache && cache[id] != null) return cache[id]; var result = cache[id] = fn(); return result; }; -}; \ No newline at end of file +}; diff --git a/lib/plugins/helper/gravatar.js b/lib/plugins/helper/gravatar.js index 2361798728..e0ca261dcb 100644 --- a/lib/plugins/helper/gravatar.js +++ b/lib/plugins/helper/gravatar.js @@ -3,12 +3,12 @@ var crypto = require('crypto'); var querystring = require('querystring'); -function md5(str){ +function md5(str) { return crypto.createHash('md5').update(str).digest('hex'); } -function gravatarHelper(email, options){ - if (typeof options === 'number'){ +function gravatarHelper(email, options) { + if (typeof options === 'number') { options = {s: options}; } @@ -20,4 +20,4 @@ function gravatarHelper(email, options){ return str; } -module.exports = gravatarHelper; \ No newline at end of file +module.exports = gravatarHelper; diff --git a/lib/plugins/helper/image_tag.js b/lib/plugins/helper/image_tag.js index 49dcc72223..4991265054 100644 --- a/lib/plugins/helper/image_tag.js +++ b/lib/plugins/helper/image_tag.js @@ -2,8 +2,7 @@ var htmlTag = require('hexo-util').htmlTag; -function imageTagHelper(path, options){ - /* jshint validthis: true */ +function imageTagHelper(path, options) { options = options || {}; var attrs = { @@ -13,16 +12,16 @@ function imageTagHelper(path, options){ var keys = Object.keys(options); var key = ''; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; attrs[key] = options[key]; } - if (attrs.class && Array.isArray(attrs.class)){ + if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } return htmlTag('img', attrs); } -module.exports = imageTagHelper; \ No newline at end of file +module.exports = imageTagHelper; diff --git a/lib/plugins/helper/index.js b/lib/plugins/helper/index.js index b3134597bd..8034dae954 100644 --- a/lib/plugins/helper/index.js +++ b/lib/plugins/helper/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var helper = ctx.extend.helper; var date = require('./date'); diff --git a/lib/plugins/helper/is.js b/lib/plugins/helper/is.js index a31b01069c..7e607d2afc 100644 --- a/lib/plugins/helper/is.js +++ b/lib/plugins/helper/is.js @@ -1,75 +1,66 @@ 'use strict'; -function isCurrentHelper(path, strict){ - /* jshint validthis: true */ +function isCurrentHelper(path, strict) { path = path || ''; - if (strict){ + if (strict) { if (path[path.length - 1] === '/') path += 'index.html'; return this.path === path; - } else { - path = path.replace(/\/index\.html$/, '/'); - - return this.path.substring(0, path.length) === path; } + + path = path.replace(/\/index\.html$/, '/'); + + return this.path.substring(0, path.length) === path; } -function isHomeHelper(){ - /* jshint validthis: true */ +function isHomeHelper() { return Boolean(this.page.__index); } -function isPostHelper(){ - /* jshint validthis: true */ +function isPostHelper() { return Boolean(this.page.__post); } -function isPageHelper(){ - /* jshint validthis: true */ +function isPageHelper() { return Boolean(this.page.__page); } -function isArchiveHelper(){ - /* jshint validthis: true */ +function isArchiveHelper() { return Boolean(this.page.archive); } -function isYearHelper(year){ - /* jshint validthis: true */ +function isYearHelper(year) { var page = this.page; if (!page.archive) return false; - if (year){ + if (year) { return page.year === year; - } else { - return Boolean(page.year); } + + return Boolean(page.year); } -function isMonthHelper(year, month){ - /* jshint validthis: true */ +function isMonthHelper(year, month) { var page = this.page; if (!page.archive) return false; - if (year){ - if (month){ + if (year) { + if (month) { return page.year === year && page.month === month; - } else { - return page.month === year; } - } else { - return Boolean(page.year && page.month); + + return page.month === year; } + + return Boolean(page.year && page.month); } -function isCategoryHelper(){ - /* jshint validthis: true */ +function isCategoryHelper() { return Boolean(this.page.category); } -function isTagHelper(){ - /* jshint validthis: true */ +function isTagHelper() { return Boolean(this.page.tag); } diff --git a/lib/plugins/helper/js.js b/lib/plugins/helper/js.js index 82864ff743..7ae902d66d 100644 --- a/lib/plugins/helper/js.js +++ b/lib/plugins/helper/js.js @@ -1,16 +1,15 @@ 'use strict'; -function jsHelper(){ - /* jshint validthis: true */ +function jsHelper() { var result = ''; var path = ''; - for (var i = 0, len = arguments.length; i < len; i++){ + for (var i = 0, len = arguments.length; i < len; i++) { path = arguments[i]; if (i) result += '\n'; - if (Array.isArray(path)){ + if (Array.isArray(path)) { result += jsHelper.apply(this, path); } else { if (path.substring(path.length - 3, path.length) !== '.js') path += '.js'; @@ -21,4 +20,4 @@ function jsHelper(){ return result; } -module.exports = jsHelper; \ No newline at end of file +module.exports = jsHelper; diff --git a/lib/plugins/helper/link_to.js b/lib/plugins/helper/link_to.js index 2affac8762..0281325b7c 100644 --- a/lib/plugins/helper/link_to.js +++ b/lib/plugins/helper/link_to.js @@ -2,8 +2,7 @@ var htmlTag = require('hexo-util').htmlTag; -function linkToHelper(path, text, options){ - /* jshint validthis: true */ +function linkToHelper(path, text, options) { if (typeof options === 'boolean') options = {external: options}; options = options || {}; @@ -17,22 +16,22 @@ function linkToHelper(path, text, options){ var keys = Object.keys(options); var key = ''; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; attrs[key] = options[key]; } - if (attrs.external){ + if (attrs.external) { attrs.target = '_blank'; attrs.rel = 'external'; attrs.external = null; } - if (attrs.class && Array.isArray(attrs.class)){ + if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } return htmlTag('a', attrs, text); } -module.exports = linkToHelper; \ No newline at end of file +module.exports = linkToHelper; diff --git a/lib/plugins/helper/list_archives.js b/lib/plugins/helper/list_archives.js index d85ccdb695..37c7f2c7c5 100644 --- a/lib/plugins/helper/list_archives.js +++ b/lib/plugins/helper/list_archives.js @@ -1,7 +1,6 @@ 'use strict'; -function listArchivesHelper(options){ - /* jshint validthis: true */ +function listArchivesHelper(options) { options = options || {}; var config = this.config; @@ -19,7 +18,7 @@ function listArchivesHelper(options){ var result = ''; var self = this; - if (!format){ + if (!format) { format = type === 'monthly' ? 'MMMM YYYY' : 'YYYY'; } @@ -29,7 +28,7 @@ function listArchivesHelper(options){ var data = []; var length = 0; - posts.forEach(function(post){ + posts.forEach(function(post) { // Clone the date object to avoid pollution var date = post.date.clone(); @@ -41,7 +40,7 @@ function listArchivesHelper(options){ var name = date.format(format); var lastData = data[length - 1]; - if (!lastData || lastData.name !== name){ + if (!lastData || lastData.name !== name) { length = data.push({ name: name, year: year, @@ -53,10 +52,10 @@ function listArchivesHelper(options){ } }); - function link(item){ + function link(item) { var url = archiveDir + '/' + item.year + '/'; - if (type === 'monthly'){ + if (type === 'monthly') { if (item.month < 10) url += '0'; url += item.month + '/'; } @@ -66,10 +65,10 @@ function listArchivesHelper(options){ var item, i, len; - if (style === 'list'){ + if (style === 'list') { result += '
' + content + '
';
}
@@ -33,20 +33,20 @@ module.exports = function(ctx){
var lang = '';
var match;
- if (rLang.test(arg)){
- arg = arg.replace(rLang, function(){
+ if (rLang.test(arg)) {
+ arg = arg.replace(rLang, function() {
lang = arguments[1];
return '';
});
}
- if (rCaptionUrlTitle.test(arg)){
+ if (rCaptionUrlTitle.test(arg)) {
match = arg.match(rCaptionUrlTitle);
caption = '' + match[1] + '' + match[4] + '';
- } else if (rCaptionUrl.test(arg)){
+ } else if (rCaptionUrl.test(arg)) {
match = arg.match(rCaptionUrl);
caption = '' + match[1] + 'link';
- } else if (rCaption.test(arg)){
+ } else if (rCaption.test(arg)) {
match = arg.match(rCaption);
caption = '' + match[1] + '';
}
@@ -66,4 +66,4 @@ module.exports = function(ctx){
return content;
};
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/gist.js b/lib/plugins/tag/gist.js
index 33feb4ac98..6a4d03ea0c 100644
--- a/lib/plugins/tag/gist.js
+++ b/lib/plugins/tag/gist.js
@@ -7,11 +7,11 @@
* {% gist gist_id [filename] %}
*/
-function gistTag(args, content){
+function gistTag(args, content) {
var id = args.shift();
var file = args.length ? '?file=' + args[0] : '';
return '';
}
-module.exports = gistTag;
\ No newline at end of file
+module.exports = gistTag;
diff --git a/lib/plugins/tag/iframe.js b/lib/plugins/tag/iframe.js
index 75ba365295..67ea610a73 100644
--- a/lib/plugins/tag/iframe.js
+++ b/lib/plugins/tag/iframe.js
@@ -7,7 +7,7 @@
* {% iframe url [width] [height] %}
*/
-function iframeTag(args, content){
+function iframeTag(args, content) {
var url = args[0];
var width = args[1] && args[1] !== 'default' ? args[1] : '100%';
var height = args[2] && args[2] !== 'default' ? args[2] : '300';
@@ -15,4 +15,4 @@ function iframeTag(args, content){
return '';
}
-module.exports = iframeTag;
\ No newline at end of file
+module.exports = iframeTag;
diff --git a/lib/plugins/tag/img.js b/lib/plugins/tag/img.js
index 6360707b12..64e963be0b 100644
--- a/lib/plugins/tag/img.js
+++ b/lib/plugins/tag/img.js
@@ -13,7 +13,7 @@ var rMeta = /["']?([^"']+)?["']?\s*["']?([^"']+)?["']?/;
* {% img [class names] /path/to/image [width] [height] [title text [alt text]] %}
*/
-function imgTag(args, content){
+function imgTag(args, content) {
var classes = [];
var meta = '';
var width;
@@ -22,16 +22,18 @@ function imgTag(args, content){
var alt;
var src;
var item = '';
+ var i = 0;
+ var len = args.length;
// Find image URL and class name
- for (var i = 0, len = args.length; i < len; i++){
+ for (; i < len; i++) {
item = args[i];
- if (rUrl.test(item)){
+ if (rUrl.test(item)) {
src = item;
break;
} else {
- if (item[0] === '/'){
+ if (item[0] === '/') {
src = item;
break;
} else {
@@ -44,11 +46,11 @@ function imgTag(args, content){
args = args.slice(i + 1);
// Find image width and height
- if (args.length){
- if (!/\D+/.test(args[0])){
+ if (args.length) {
+ if (!/\D+/.test(args[0])) {
width = args.shift();
- if (args.length && !/\D+/.test(args[0])){
+ if (args.length && !/\D+/.test(args[0])) {
height = args.shift();
}
}
@@ -57,7 +59,7 @@ function imgTag(args, content){
}
// Find image title and alt
- if (meta && rMeta.test(meta)){
+ if (meta && rMeta.test(meta)) {
var match = meta.match(rMeta);
title = match[1];
alt = match[2];
@@ -75,4 +77,4 @@ function imgTag(args, content){
return htmlTag('img', attrs);
}
-module.exports = imgTag;
\ No newline at end of file
+module.exports = imgTag;
diff --git a/lib/plugins/tag/include_code.js b/lib/plugins/tag/include_code.js
index 6ba15bc14d..bc01b8feba 100644
--- a/lib/plugins/tag/include_code.js
+++ b/lib/plugins/tag/include_code.js
@@ -16,8 +16,8 @@ var rLang = /\s*lang:(\w+)/i;
* {% include_code [title] [lang:language] path/to/file %}
*/
-module.exports = function(ctx){
- return function includeCodeTag(args){
+module.exports = function(ctx) {
+ return function includeCodeTag(args) {
var config = ctx.config.highlight || {};
var codeDir = ctx.config.code_dir;
var arg = args.join(' ');
@@ -29,14 +29,14 @@ module.exports = function(ctx){
// Add trailing slash to codeDir
if (codeDir[codeDir.length - 1] !== '/') codeDir += '/';
- if (rLang.test(arg)){
- arg = arg.replace(rLang, function(){
+ if (rLang.test(arg)) {
+ arg = arg.replace(rLang, function() {
lang = arguments[1];
return '';
});
}
- if (rCaptionTitleFile.test(arg)){
+ if (rCaptionTitleFile.test(arg)) {
var match = arg.match(rCaptionTitleFile);
title = match[1];
path = match[3];
@@ -47,14 +47,14 @@ module.exports = function(ctx){
var src = pathFn.join(ctx.source_dir, codeDir, path);
- return fs.exists(src).then(function(exist){
+ return fs.exists(src).then(function(exist) {
if (exist) return fs.readFile(src);
- }).then(function(code){
+ }).then(function(code) {
if (!code) return;
code = stripIndent(code).trim();
- if (!config.enable){
+ if (!config.enable) {
return '' + code + '
';
}
@@ -74,4 +74,4 @@ module.exports = function(ctx){
});
});
};
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/index.js b/lib/plugins/tag/index.js
index f6bb9ab3f2..8385f46a95 100644
--- a/lib/plugins/tag/index.js
+++ b/lib/plugins/tag/index.js
@@ -1,6 +1,6 @@
'use strict';
-module.exports = function(ctx){
+module.exports = function(ctx) {
var tag = ctx.extend.tag;
var blockquote = require('./blockquote')(ctx);
@@ -51,4 +51,4 @@ module.exports = function(ctx){
tag.register('vimeo', require('./vimeo'));
tag.register('youtube', require('./youtube'));
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/jsfiddle.js b/lib/plugins/tag/jsfiddle.js
index cdd53d72aa..8d7b2f40cc 100644
--- a/lib/plugins/tag/jsfiddle.js
+++ b/lib/plugins/tag/jsfiddle.js
@@ -7,7 +7,7 @@
* {% jsfiddle shorttag [tabs] [skin] [height] [width] %}
*/
-function jsfiddleTag(args, content){
+function jsfiddleTag(args, content) {
var id = args[0];
var tabs = args[1] && args[1] !== 'default' ? args[1] : 'js,resources,html,css,result';
var skin = args[2] && args[2] !== 'default' ? args[2] : 'light';
@@ -17,4 +17,4 @@ function jsfiddleTag(args, content){
return '';
}
-module.exports = jsfiddleTag;
\ No newline at end of file
+module.exports = jsfiddleTag;
diff --git a/lib/plugins/tag/link.js b/lib/plugins/tag/link.js
index 387edb62de..bd3a2df022 100644
--- a/lib/plugins/tag/link.js
+++ b/lib/plugins/tag/link.js
@@ -12,18 +12,20 @@ var rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:ww
* {% link text url [external] [title] %}
*/
-function linkTag(args, content){
+function linkTag(args, content) {
var url = '';
var text = [];
var external = false;
var title = '';
var item = '';
+ var i = 0;
+ var len = args.length;
// Find link URL and text
- for (var i = 0, len = args.length; i < len; i++){
+ for (; i < len; i++) {
item = args[i];
- if (rUrl.test(item)){
+ if (rUrl.test(item)) {
url = item;
break;
} else {
@@ -36,10 +38,10 @@ function linkTag(args, content){
// Check if the link should be open in a new window
// and collect the last text as the link title
- if (args.length){
+ if (args.length) {
var shift = args[0];
- if (shift === 'true' || shift === 'false'){
+ if (shift === 'true' || shift === 'false') {
external = shift === 'true' ? true : false;
args.shift();
}
@@ -56,4 +58,4 @@ function linkTag(args, content){
return htmlTag('a', attrs, text.join(' '));
}
-module.exports = linkTag;
\ No newline at end of file
+module.exports = linkTag;
diff --git a/lib/plugins/tag/post_link.js b/lib/plugins/tag/post_link.js
index 8341ce5a3b..3b1dbd42f1 100644
--- a/lib/plugins/tag/post_link.js
+++ b/lib/plugins/tag/post_link.js
@@ -6,10 +6,10 @@
* Syntax:
* {% post_link slug [title] %}
*/
-module.exports = function(ctx){
+module.exports = function(ctx) {
var Post = ctx.model('Post');
- return function postLinkTag(args){
+ return function postLinkTag(args) {
var slug = args.shift();
if (!slug) return;
@@ -20,4 +20,4 @@ module.exports = function(ctx){
return '' + title + '';
};
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/post_path.js b/lib/plugins/tag/post_path.js
index c738b8657e..46bd575fea 100644
--- a/lib/plugins/tag/post_path.js
+++ b/lib/plugins/tag/post_path.js
@@ -6,10 +6,10 @@
* Syntax:
* {% post_path slug %}
*/
-module.exports = function(ctx){
+module.exports = function(ctx) {
var Post = ctx.model('Post');
- return function postPathTag(args){
+ return function postPathTag(args) {
var slug = args.shift();
if (!slug) return;
@@ -18,4 +18,4 @@ module.exports = function(ctx){
return ctx.config.root + post.path;
};
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/pullquote.js b/lib/plugins/tag/pullquote.js
index 3ffda7fa94..a46d7911d5 100644
--- a/lib/plugins/tag/pullquote.js
+++ b/lib/plugins/tag/pullquote.js
@@ -8,8 +8,8 @@
* Quote string
* {% endpullquote %}
*/
-module.exports = function(ctx){
- return function pullquoteTag(args, content){
+module.exports = function(ctx) {
+ return function pullquoteTag(args, content) {
var result = '';
args.unshift('pullquote');
@@ -20,4 +20,4 @@ module.exports = function(ctx){
return result;
};
-};
\ No newline at end of file
+};
diff --git a/lib/plugins/tag/vimeo.js b/lib/plugins/tag/vimeo.js
index 882bef2440..908868f217 100644
--- a/lib/plugins/tag/vimeo.js
+++ b/lib/plugins/tag/vimeo.js
@@ -7,10 +7,10 @@
* {% vimeo video_id %}
*/
-function vimeoTag(args, content){
+function vimeoTag(args, content) {
var id = args[0];
return '';
}
-module.exports = vimeoTag;
\ No newline at end of file
+module.exports = vimeoTag;
diff --git a/lib/plugins/tag/youtube.js b/lib/plugins/tag/youtube.js
index 52978ef162..d4bd48746f 100644
--- a/lib/plugins/tag/youtube.js
+++ b/lib/plugins/tag/youtube.js
@@ -7,10 +7,10 @@
* {% youtube video_id %}
*/
-function youtubeTag(args, content){
+function youtubeTag(args, content) {
var id = args[0];
return '';
}
-module.exports = youtubeTag;
\ No newline at end of file
+module.exports = youtubeTag;
diff --git a/lib/theme/index.js b/lib/theme/index.js
index 6bcf98ff72..9ae7b20cae 100644
--- a/lib/theme/index.js
+++ b/lib/theme/index.js
@@ -4,10 +4,10 @@ var pathFn = require('path');
var util = require('util');
var Box = require('../box');
var View = require('./view');
-var i18n = require('hexo-i18n');
+var I18n = require('hexo-i18n');
var _ = require('lodash');
-function Theme(ctx){
+function Theme(ctx) {
Box.call(this, ctx, ctx.theme_dir);
this.config = {};
@@ -23,17 +23,17 @@ function Theme(ctx){
var languages = ctx.config.language;
- if (!Array.isArray(languages)){
+ if (!Array.isArray(languages)) {
languages = [languages];
}
languages.push('default');
- this.i18n = new i18n({
+ this.i18n = new I18n({
languages: _(languages).compact().uniq().value()
});
- var _View = this.View = function(path, data){
+ var _View = this.View = function(path, data) {
View.call(this, path, data);
};
@@ -46,7 +46,7 @@ function Theme(ctx){
util.inherits(Theme, Box);
-Theme.prototype.getView = function(path){
+Theme.prototype.getView = function(path) {
// Replace backslashes on Windows
path = path.replace(/\\/g, '/');
@@ -56,14 +56,14 @@ Theme.prototype.getView = function(path){
if (!views) return;
- if (extname){
+ if (extname) {
return views[extname];
- } else {
- return views[Object.keys(views)[0]];
}
+
+ return views[Object.keys(views)[0]];
};
-Theme.prototype.setView = function(path, data){
+Theme.prototype.setView = function(path, data) {
var extname = pathFn.extname(path);
var name = path.substring(0, path.length - extname.length);
var views = this.views[name] = this.views[name] || {};
@@ -71,7 +71,7 @@ Theme.prototype.setView = function(path, data){
views[extname] = new this.View(path, data);
};
-Theme.prototype.removeView = function(path){
+Theme.prototype.removeView = function(path) {
var extname = pathFn.extname(path);
var name = path.substring(0, path.length - extname.length);
var views = this.views[name];
@@ -81,4 +81,4 @@ Theme.prototype.removeView = function(path){
delete views[extname];
};
-module.exports = Theme;
\ No newline at end of file
+module.exports = Theme;
diff --git a/lib/theme/processors/config.js b/lib/theme/processors/config.js
index b6a1587c70..74186524f0 100644
--- a/lib/theme/processors/config.js
+++ b/lib/theme/processors/config.js
@@ -2,21 +2,21 @@
var Pattern = require('hexo-util').Pattern;
-exports.process = function(file){
- if (file.type === 'delete'){
+exports.process = function(file) {
+ if (file.type === 'delete') {
file.box.config = {};
return;
}
var self = this;
- return file.render().then(function(result){
+ return file.render().then(function(result) {
file.box.config = result;
self.log.debug('Theme config loaded.');
- }, function(err){
+ }).catch(function(err) {
self.log.error('Theme config load failed.');
throw err;
});
};
-exports.pattern = new Pattern(/^_config\.\w+$/);
\ No newline at end of file
+exports.pattern = new Pattern(/^_config\.\w+$/);
diff --git a/lib/theme/processors/i18n.js b/lib/theme/processors/i18n.js
index 53dd20ee9b..44d847566c 100644
--- a/lib/theme/processors/i18n.js
+++ b/lib/theme/processors/i18n.js
@@ -3,21 +3,21 @@
var Pattern = require('hexo-util').Pattern;
var pathFn = require('path');
-exports.process = function(file){
+exports.process = function(file) {
var path = file.params.path;
var extname = pathFn.extname(path);
var name = path.substring(0, path.length - extname.length);
var i18n = file.box.i18n;
- if (file.type === 'delete'){
+ if (file.type === 'delete') {
i18n.remove(name);
return;
}
- return file.render().then(function(data){
+ return file.render().then(function(data) {
if (typeof data !== 'object') return;
i18n.set(name, data);
});
};
-exports.pattern = new Pattern('languages/*path');
\ No newline at end of file
+exports.pattern = new Pattern('languages/*path');
diff --git a/lib/theme/processors/source.js b/lib/theme/processors/source.js
index 3d19c2eeee..5c4dd41ee9 100644
--- a/lib/theme/processors/source.js
+++ b/lib/theme/processors/source.js
@@ -3,38 +3,38 @@
var Pattern = require('hexo-util').Pattern;
var common = require('../../plugins/processor/common');
-exports.process = function(file){
+exports.process = function(file) {
var Asset = this.model('Asset');
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
var path = file.params.path;
var doc = Asset.findById(id);
- if (file.type === 'delete'){
- if (doc){
+ if (file.type === 'delete') {
+ if (doc) {
return doc.remove();
- } else {
- return;
}
+
+ return;
}
- if (doc){
+ if (doc) {
doc.path = path;
doc.modified = file.type !== 'skip';
return doc.save();
- } else {
- return Asset.insert({
- _id: id,
- path: path
- });
}
+
+ return Asset.insert({
+ _id: id,
+ path: path
+ });
};
-exports.pattern = new Pattern(function(path){
+exports.pattern = new Pattern(function(path) {
if (path.substring(0, 7) !== 'source/') return false;
path = path.substring(7);
if (common.isHiddenFile(path) || common.isTmpFile(path)) return false;
return {path: path};
-});
\ No newline at end of file
+});
diff --git a/lib/theme/processors/view.js b/lib/theme/processors/view.js
index e04e4dffec..c9d3e97815 100644
--- a/lib/theme/processors/view.js
+++ b/lib/theme/processors/view.js
@@ -2,17 +2,17 @@
var Pattern = require('hexo-util').Pattern;
-exports.process = function(file){
+exports.process = function(file) {
var path = file.params.path;
- if (file.type === 'delete'){
+ if (file.type === 'delete') {
file.box.removeView(path);
return;
}
- return file.read().then(function(result){
+ return file.read().then(function(result) {
file.box.setView(path, result);
});
};
-exports.pattern = new Pattern('layout/*path');
\ No newline at end of file
+exports.pattern = new Pattern('layout/*path');
diff --git a/lib/theme/view.js b/lib/theme/view.js
index 61dae45f96..49a27b9809 100644
--- a/lib/theme/view.js
+++ b/lib/theme/view.js
@@ -4,14 +4,14 @@ var pathFn = require('path');
var _ = require('lodash');
var yfm = require('hexo-front-matter');
-function View(path, data){
+function View(path, data) {
this.path = path;
this.source = pathFn.join(this._theme.base, 'layout', path);
this.data = typeof data === 'string' ? yfm(data) : data;
}
-View.prototype.render = function(options, callback){
- if (!callback && typeof options === 'function'){
+View.prototype.render = function(options, callback) {
+ if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
@@ -26,7 +26,7 @@ View.prototype.render = function(options, callback){
return this._render.render({
path: this.source,
text: data._content
- }, this._bindHelpers(locals)).then(function(result){
+ }, this._bindHelpers(locals)).then(function(result) {
if (!layout) return result;
var layoutView = self._resolveLayout(layout);
@@ -40,7 +40,7 @@ View.prototype.render = function(options, callback){
}).nodeify(callback);
};
-View.prototype.renderSync = function(options){
+View.prototype.renderSync = function(options) {
options = options || {};
var data = this.data;
@@ -64,7 +64,7 @@ View.prototype.renderSync = function(options){
return layoutView.renderSync(layoutLocals);
};
-View.prototype._buildLocals = function(locals){
+View.prototype._buildLocals = function(locals) {
var data = this.data;
var result = {};
var keys = [];
@@ -72,14 +72,14 @@ View.prototype._buildLocals = function(locals){
var i, len;
// Copy locals
- for (i in locals){
+ for (i in locals) {
result[i] = locals[i];
}
// Bind view data
keys = Object.keys(data);
- for (i = 0, len = keys.length; i < len; i++){
+ for (i = 0, len = keys.length; i < len; i++) {
key = keys[i];
if (key !== 'layout' && key !== '_content') result[key] = data[key];
}
@@ -90,12 +90,12 @@ View.prototype._buildLocals = function(locals){
return result;
};
-View.prototype._bindHelpers = function(locals){
+View.prototype._bindHelpers = function(locals) {
var helpers = this._helper.list();
var keys = Object.keys(helpers);
var key = '';
- for (var i = 0, len = keys.length; i < len; i++){
+ for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
locals[key] = helpers[key].bind(locals);
}
@@ -103,7 +103,7 @@ View.prototype._bindHelpers = function(locals){
return locals;
};
-View.prototype._resolveLayout = function(name){
+View.prototype._resolveLayout = function(name) {
// Relative path
var layoutPath = pathFn.join(pathFn.dirname(this.path), name);
var layoutView = this._theme.getView(layoutPath);
@@ -115,4 +115,4 @@ View.prototype._resolveLayout = function(name){
if (layoutView && layoutView.source !== this.source) return layoutView;
};
-module.exports = View;
\ No newline at end of file
+module.exports = View;
diff --git a/package.json b/package.json
index 867ae1b191..38f94361de 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,10 @@
"hexo": "./bin/hexo"
},
"scripts": {
- "test": "gulp test"
+ "eslint": "eslint .",
+ "jscs": "jscs .",
+ "test": "mocha test/index.js",
+ "test-cov": "istanbul cover --print both _mocha -- test/index.js && istanbul check-coverage"
},
"directories": {
"lib": "./lib",
@@ -43,29 +46,25 @@
"lodash": "^3.2.0",
"minimatch": "^2.0.1",
"moment": "~2.10.3",
- "moment-timezone": "^0.3.0",
- "nunjucks": "^1.3.3",
+ "moment-timezone": "^0.4.0",
+ "nunjucks": "^2.1.0",
"pretty-hrtime": "^1.0.0",
"strip-indent": "^1.0.0",
"swig": "1.4.2",
"swig-extras": "0.0.1",
"text-table": "^0.2.0",
- "through2": "^1.1.1",
+ "through2": "^2.0.0",
"tildify": "^1.0.0",
"titlecase": "^1.0.2",
"warehouse": "^1.0.2"
},
"devDependencies": {
- "chai": "^2.2.0",
+ "chai": "^3.2.0",
"coveralls": "^2.11.2",
- "del": "^1.1.1",
- "gulp": "^3.8.9",
- "gulp-istanbul": "^0.9.0",
- "gulp-jshint": "^1.8.6",
- "gulp-load-plugins": "^0.10.0",
- "gulp-mocha": "^2.0.0",
+ "eslint": "^1.5.0",
"hexo-renderer-marked": "^0.2.3",
- "jshint-stylish": "^1.0.0",
+ "istanbul": "^0.3.20",
+ "jscs": "^2.1.1",
"mocha": "^2.0.1",
"sinon": "^1.12.2"
}
diff --git a/test/.eslintrc b/test/.eslintrc
new file mode 100644
index 0000000000..7411927efe
--- /dev/null
+++ b/test/.eslintrc
@@ -0,0 +1,9 @@
+{
+ "extend": "../.eslintrc",
+ "rules": {
+ "no-unused-expressions": 0
+ },
+ "env": {
+ "mocha": true
+ }
+}
\ No newline at end of file
diff --git a/test/.jshintrc b/test/.jshintrc
deleted file mode 100644
index beaaa4bde2..0000000000
--- a/test/.jshintrc
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "eqnull": true,
- "expr": true,
- "indent": 2,
- "node": true,
- "mocha": true,
- "trailing": true,
- "quotmark": "single",
- "undef": true,
- "strict": true,
- "unused": "vars",
- "globals": {
- "Promise": true
- }
-}
\ No newline at end of file
diff --git a/test/fixtures/post_render.js b/test/fixtures/post_render.js
index 6133db3e7e..d3ef0fe4fa 100644
--- a/test/fixtures/post_render.js
+++ b/test/fixtures/post_render.js
@@ -36,4 +36,4 @@ exports.expected = [
'\n',
'' -].join(''); \ No newline at end of file +].join(''); diff --git a/test/index.js b/test/index.js index 0e56a85e0b..64fb5ba948 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Hexo', function(){ +describe('Hexo', function() { require('./scripts/box'); require('./scripts/console'); require('./scripts/extend'); @@ -14,4 +14,4 @@ describe('Hexo', function(){ require('./scripts/tags'); require('./scripts/theme'); require('./scripts/theme_processors'); -}); \ No newline at end of file +}); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000000..fb5f82427f --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1 @@ +--reporter spec \ No newline at end of file diff --git a/test/scripts/box/box.js b/test/scripts/box/box.js index 44e8b06986..817e53fdb0 100644 --- a/test/scripts/box/box.js +++ b/test/scripts/box/box.js @@ -1,6 +1,6 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); @@ -8,42 +8,41 @@ var crypto = require('crypto'); var util = require('hexo-util'); var sinon = require('sinon'); var Pattern = util.Pattern; -var testUtil = require('../../util'); -function shasum(content){ +function shasum(content) { var hash = crypto.createHash('sha1'); hash.update(content); return hash.digest('hex'); } -describe('Box', function(){ +describe('Box', function() { var Hexo = require('../../../lib/hexo'); var baseDir = pathFn.join(__dirname, 'box_tmp'); var Box = require('../../../lib/box'); - function newBox(path){ + function newBox(path) { var hexo = new Hexo(baseDir, {silent: true}); var base = path ? pathFn.join(baseDir, path) : baseDir; return new Box(hexo, base); } - before(function(){ + before(function() { return fs.mkdir(baseDir); }); - after(function(){ + after(function() { return fs.rmdir(baseDir); }); - it('constructor - add trailing "/" to the base path', function(){ + it('constructor - add trailing "/" to the base path', function() { var box = newBox('foo'); box.base.should.eql(pathFn.join(baseDir, 'foo') + pathFn.sep); }); - it('addProcessor() - no pattern', function(){ + it('addProcessor() - no pattern', function() { var box = newBox(); - box.addProcessor(function(){ + box.addProcessor(function() { return 'test'; }); @@ -53,10 +52,10 @@ describe('Box', function(){ p.process().should.eql('test'); }); - it('addProcessor() - with regex', function(){ + it('addProcessor() - with regex', function() { var box = newBox(); - box.addProcessor(/^foo/, function(){ + box.addProcessor(/^foo/, function() { return 'test'; }); @@ -67,10 +66,10 @@ describe('Box', function(){ p.process().should.eql('test'); }); - it('addProcessor() - with pattern', function(){ + it('addProcessor() - with pattern', function() { var box = newBox(); - box.addProcessor(new Pattern(/^foo/), function(){ + box.addProcessor(new Pattern(/^foo/), function() { return 'test'; }); @@ -81,7 +80,7 @@ describe('Box', function(){ p.process().should.eql('test'); }); - it('addProcessor() - no fn', function(){ + it('addProcessor() - no fn', function() { var box = newBox(); var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'fn must be a function'); @@ -89,23 +88,23 @@ describe('Box', function(){ try { box.addProcessor('test'); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('_loadFiles() - create', function(){ + it('_loadFiles() - create', function() { var box = newBox('test'); var path = pathFn.join(box.base, 'a.txt'); - return fs.writeFile(path, 'a').then(function(){ + return fs.writeFile(path, 'a').then(function() { return Promise.all([ box._loadFiles(), fs.stat(path) ]); - }).spread(function(files, stats){ + }).spread(function(files, stats) { var cacheId = 'test/a.txt'; files.should.eql([ @@ -120,7 +119,7 @@ describe('Box', function(){ }); }); - it('_loadFiles() - update', function(){ + it('_loadFiles() - update', function() { var box = newBox('test'); var path = pathFn.join(box.base, 'a.txt'); var cacheId = 'test/a.txt'; @@ -129,12 +128,12 @@ describe('Box', function(){ return Promise.all([ fs.writeFile(path, 'a'), Cache.insert({_id: cacheId, shasum: 'a'}) - ]).then(function(){ + ]).then(function() { return Promise.all([ box._loadFiles(), fs.stat(path) ]); - }).spread(function(files, stats){ + }).spread(function(files, stats) { files.should.eql([ {path: 'a.txt', type: 'update'} ]); @@ -147,20 +146,20 @@ describe('Box', function(){ }); }); - it('_loadFiles() - skip', function(){ + it('_loadFiles() - skip', function() { var box = newBox('test'); var path = pathFn.join(box.base, 'a.txt'); var cacheId = 'test/a.txt'; var hash = shasum('a'); var Cache = box.Cache; - var mtime = Date.now() + var mtime = Date.now(); return Promise.all([ fs.writeFile(path, 'a'), Cache.insert({_id: cacheId, shasum: hash, modified: mtime}) - ]).then(function(){ + ]).then(function() { return box._loadFiles(); - }).then(function(files){ + }).then(function(files) { files.should.eql([ {type: 'skip', path: 'a.txt'} ]); @@ -173,7 +172,7 @@ describe('Box', function(){ }); }); - it('_loadFiles() - delete', function(){ + it('_loadFiles() - delete', function() { var box = newBox('test'); var cacheId = 'test/a.txt'; var Cache = box.Cache; @@ -181,9 +180,9 @@ describe('Box', function(){ return Cache.insert({ _id: cacheId, shasum: 'a' - }).then(function(){ + }).then(function() { return box._loadFiles(); - }).then(function(files){ + }).then(function(files) { files.should.eql([ {type: 'delete', path: 'a.txt'} ]); @@ -192,12 +191,12 @@ describe('Box', function(){ }); }); - it('_dispatch()', function(){ + it('_dispatch()', function() { var box = newBox(); var path = 'a.txt'; var data; - box.addProcessor(function(file){ + box.addProcessor(function(file) { box.processingFiles[path].should.be.true; data = file; }); @@ -205,7 +204,7 @@ describe('Box', function(){ return box._dispatch({ path: path, type: 'create' - }).then(function(){ + }).then(function() { box.processingFiles[path].should.be.false; data.source.should.eql(pathFn.join(box.base, path)); data.path.should.eql(path); @@ -214,45 +213,45 @@ describe('Box', function(){ }); }); - it('_dispatch() - params', function(){ + it('_dispatch() - params', function() { var box = newBox(); var data = new Array(2); - box.addProcessor(/(.*).js/, function(file){ + box.addProcessor(/(.*).js/, function(file) { data[0] = file; }); - box.addProcessor(function(file){ + box.addProcessor(function(file) { data[1] = file; }); return box._dispatch({ path: 'server.js', type: 'create' - }).then(function(){ + }).then(function() { data[0].params[1].should.eql('server'); data[1].params.should.eql({}); }); }); - it('process()', function(){ + it('process()', function() { var box = newBox('test'); var data = {}; - box.addProcessor(function(file){ + box.addProcessor(function(file) { data[file.path] = file; }); return Promise.all([ fs.writeFile(pathFn.join(box.base, 'a.txt'), 'a'), fs.writeFile(pathFn.join(box.base, 'b', 'c.js'), 'c') - ]).then(function(){ + ]).then(function() { return box.process(); - }).then(function(){ + }).then(function() { var keys = Object.keys(data); var key, item; - for (var i = 0, len = keys.length; i < len; i++){ + for (var i = 0, len = keys.length; i < len; i++) { key = keys[i]; item = data[key]; @@ -266,21 +265,21 @@ describe('Box', function(){ }); }); - it('process() - do nothing if target does not exist', function(){ + it('process() - do nothing if target does not exist', function() { var box = newBox('test'); return box.process(); }); - it('watch() - create', function(callback){ + it('watch() - create', function(callback) { var box = newBox('test'); var path = 'a.txt'; var src = pathFn.join(box.base, path); - box.watch().then(function(){ + box.watch().then(function() { box.isWatching().should.be.true; - box.addProcessor(function(file){ + box.addProcessor(function(file) { file.source.should.eql(src); file.path.should.eql(path); file.type.should.eql('create'); @@ -294,7 +293,7 @@ describe('Box', function(){ }); }); - it('watch() - update', function(callback){ + it('watch() - update', function(callback) { var box = newBox('test'); var path = 'a.txt'; var src = pathFn.join(box.base, path); @@ -304,10 +303,10 @@ describe('Box', function(){ Promise.all([ fs.writeFile(src, 'a'), Cache.insert({_id: cacheId, shasum: 'a'}) - ]).then(function(){ + ]).then(function() { return box.watch(); - }).delay(300).then(function(){ - box.addProcessor(function(file){ + }).delay(300).then(function() { + box.addProcessor(function(file) { file.source.should.eql(src); file.path.should.eql(path); file.type.should.eql('update'); @@ -321,7 +320,7 @@ describe('Box', function(){ }); }); - it('watch() - delete', function(callback){ + it('watch() - delete', function(callback) { var box = newBox('test'); var path = 'a.txt'; var src = pathFn.join(box.base, path); @@ -331,10 +330,10 @@ describe('Box', function(){ Promise.all([ fs.writeFile(src, 'a'), Cache.insert({_id: cacheId, shasum: 'a'}) - ]).then(function(){ + ]).then(function() { return box.watch(); - }).delay(300).then(function(){ - box.addProcessor(function(file){ + }).delay(300).then(function() { + box.addProcessor(function(file) { file.source.should.eql(src); file.path.should.eql(path); file.type.should.eql('delete'); @@ -348,7 +347,7 @@ describe('Box', function(){ }); }); - it('watch() - rename file', function(callback){ + it('watch() - rename file', function(callback) { var box = newBox('test'); var path = 'a.txt'; var src = pathFn.join(box.base, path); @@ -360,12 +359,12 @@ describe('Box', function(){ Promise.all([ fs.writeFile(src, 'a'), Cache.insert({_id: cacheId, shasum: 'a'}) - ]).then(function(){ + ]).then(function() { return box.watch(); - }).then(function(){ + }).then(function() { var i = 0; - box.addProcessor(function(file){ + box.addProcessor(function(file) { switch (file.type){ case 'create': file.source.should.eql(newSrc); @@ -381,7 +380,7 @@ describe('Box', function(){ throw new Error('Type must be either create or delete'); } - if (i++){ + if (i++) { box.unwatch(); fs.rmdir(box.base, callback); } @@ -391,7 +390,7 @@ describe('Box', function(){ }); }); - it('watch() - rename folder', function(callback){ + it('watch() - rename folder', function(callback) { var box = newBox('test'); var path = 'a/b.txt'; var src = pathFn.join(box.base, path); @@ -403,12 +402,12 @@ describe('Box', function(){ Promise.all([ fs.writeFile(src, 'a'), Cache.insert({_id: cacheId, shasum: 'a'}) - ]).then(function(){ + ]).then(function() { return box.watch(); - }).then(function(){ + }).then(function() { var i = 0; - box.addProcessor(function(file){ + box.addProcessor(function(file) { switch (file.type){ case 'create': file.source.should.eql(newSrc); @@ -424,7 +423,7 @@ describe('Box', function(){ throw new Error('Type must be either create or delete'); } - if (i++){ + if (i++) { box.unwatch(); fs.rmdir(box.base, callback); } @@ -434,14 +433,14 @@ describe('Box', function(){ }); }); - it.skip('watch() - watcher has started', function(callback){ + it.skip('watch() - watcher has started', function(callback) { var box = newBox(); var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Watcher has already started.'); }); - box.watch().then(function(){ - box.watch().catch(function(err){ + box.watch().then(function() { + box.watch().catch(function(err) { errorCallback(err); box.unwatch(); }).finally(function() { @@ -451,20 +450,20 @@ describe('Box', function(){ }); }); - it('watch() - run process() before start watching', function(){ + it('watch() - run process() before start watching', function() { var box = newBox('test'); var data = []; - box.addProcessor(function(file){ + box.addProcessor(function(file) { data.push(file.path); }); return Promise.all([ fs.writeFile(pathFn.join(box.base, 'a.txt'), 'a'), fs.writeFile(pathFn.join(box.base, 'b', 'c.js'), 'c') - ]).then(function(){ + ]).then(function() { return box.watch(); - }).then(function(){ + }).then(function() { data.should.have.members(['a.txt', 'b/c.js']); box.unwatch(); @@ -472,26 +471,26 @@ describe('Box', function(){ }); }); - it.skip('unwatch()', function(callback){ + it.skip('unwatch()', function(callback) { var box = newBox('test'); - box.watch().then(function(){ + box.watch().then(function() { var emitted = false; - box.addProcessor(function(file){ + box.addProcessor(function(file) { emitted = true; }); box.unwatch(); - fs.writeFile(pathFn.join(box.base, 'a.txt'), 'a').then(function(){ + fs.writeFile(pathFn.join(box.base, 'a.txt'), 'a').then(function() { emitted.should.be.false; fs.rmdir(box.base, callback); }); }); }); - it('unwatch() - watcher not started', function(){ + it('unwatch() - watcher not started', function() { var box = newBox(); var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Watcher hasn\'t started yet.'); @@ -499,23 +498,23 @@ describe('Box', function(){ try { box.unwatch(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it.skip('isWatching()', function(){ + it.skip('isWatching()', function() { var box = newBox(); - return box.watch().then(function(){ + return box.watch().then(function() { box.isWatching().should.be.true; return box.unwatch(); - }).then(function(){ + }).then(function() { box.isWatching().should.be.false; }); }); it('processBefore & processAfter events'); -}); \ No newline at end of file +}); diff --git a/test/scripts/box/file.js b/test/scripts/box/file.js index 4610283140..6b101a6461 100644 --- a/test/scripts/box/file.js +++ b/test/scripts/box/file.js @@ -1,12 +1,12 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var Promise = require('bluebird'); var fs = require('hexo-fs'); var yaml = require('js-yaml'); -describe('File', function(){ +describe('File', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Box = require('../../../lib/box'); @@ -37,44 +37,44 @@ describe('File', function(){ stats: {} }); - before(function(){ + before(function() { return Promise.all([ fs.writeFile(file.source, body), hexo.init() ]); }); - after(function(){ + after(function() { return fs.rmdir(box.base); - }) + }); - it('read()', function(){ - return file.read().then(function(content){ + it('read()', function() { + return file.read().then(function(content) { content.should.eql(body); }); }); - it('read() - callback', function(callback){ - file.read(function(err, content){ + it('read() - callback', function(callback) { + file.read(function(err, content) { should.not.exist(err); content.should.eql(body); callback(); }); }); - it('read() - raw buffer', function(){ - file.read({encoding: null}).then(function(content){ + it('read() - raw buffer', function() { + file.read({encoding: null}).then(function(content) { content.should.eql(new Buffer(body)); }); }); - it('read() - string encoding', function(){ - file.read('hex').then(function(content){ + it('read() - string encoding', function() { + file.read('hex').then(function(content) { content.should.eql(new Buffer(body).toString('hex')); }); }); - it('read() - cache off', function(){ + it('read() - cache off', function() { var path = 'nocache.txt'; var file = new File({ source: pathFn.join(box.base, path), @@ -82,62 +82,62 @@ describe('File', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, 'abc').then(function(){ + return fs.writeFile(file.source, 'abc').then(function() { return file.read({cache: false}); - }).then(function(content){ + }).then(function(content) { content.should.eql('abc'); return fs.unlink(file.source); }); }); - it('read() - no content', function(){ + it('read() - no content', function() { var path = 'nocache.txt'; var file = new File({ source: pathFn.join(box.base, path), path: path }); - return fs.writeFile(file.source, 'abc').then(function(){ + return fs.writeFile(file.source, 'abc').then(function() { return file.read(); - }).then(function(content){ + }).then(function(content) { content.should.eql('abc'); return fs.unlink(file.source); }); }); - it('read() - escape BOM', function(){ + it('read() - escape BOM', function() { var file = new File({ content: new Buffer('\ufefffoo') }); - return file.read().then(function(result){ + return file.read().then(function(result) { result.should.eql('foo'); }); }); - it('read() - escape Windows line ending', function(){ + it('read() - escape Windows line ending', function() { var file = new File({ content: new Buffer('foo\r\nbar') }); - return file.read().then(function(result){ + return file.read().then(function(result) { result.should.eql('foo\nbar'); }); }); - it('readSync()', function(){ + it('readSync()', function() { file.readSync().should.eql(body); }); - it('readSync() - raw buffer', function(){ + it('readSync() - raw buffer', function() { file.readSync({encoding: null}).should.eql(new Buffer(body)); }); - it('readSync() - string encoding', function(){ + it('readSync() - string encoding', function() { file.readSync('hex').should.eql(new Buffer(body).toString('hex')); }); - it('readSync() - cache off', function(){ + it('readSync() - cache off', function() { var path = 'nocache.txt'; var file = new File({ source: pathFn.join(box.base, path), @@ -145,7 +145,7 @@ describe('File', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, 'abc').then(function(){ + return fs.writeFile(file.source, 'abc').then(function() { var content = file.readSync({cache: false}); content.should.eql('abc'); @@ -154,14 +154,14 @@ describe('File', function(){ }); }); - it('readSync() - no content', function(){ + it('readSync() - no content', function() { var path = 'nocache.txt'; var file = new File({ source: pathFn.join(box.base, path), path: path }); - return fs.writeFile(file.source, 'abc').then(function(){ + return fs.writeFile(file.source, 'abc').then(function() { var content = file.readSync(); content.should.eql('abc'); @@ -170,7 +170,7 @@ describe('File', function(){ }); }); - it('readSync() - escape BOM', function(){ + it('readSync() - escape BOM', function() { var file = new File({ content: new Buffer('\ufefffoo') }); @@ -178,7 +178,7 @@ describe('File', function(){ file.readSync().should.eql('foo'); }); - it('readSync() - escape Windows line ending', function(){ + it('readSync() - escape Windows line ending', function() { var file = new File({ content: new Buffer('foo\r\nbar') }); @@ -186,54 +186,54 @@ describe('File', function(){ file.readSync().should.eql('foo\nbar'); }); - it('stat()', function(){ - return file.stat().then(function(stats){ + it('stat()', function() { + return file.stat().then(function(stats) { stats.should.eql({}); }); }); - it('stat() - callback', function(callback){ - file.stat(function(err, stats){ + it('stat() - callback', function(callback) { + file.stat(function(err, stats) { should.not.exist(err); stats.should.eql({}); callback(); }); }); - it('stat() - cache off', function(){ + it('stat() - cache off', function() { return Promise.all([ fs.stat(file.source), file.stat({cache: false}) - ]).then(function(stats){ + ]).then(function(stats) { stats[0].should.eql(stats[1]); }); }); - it('statSync()', function(){ + it('statSync()', function() { file.statSync().should.eql({}); }); - it('statSync() - cache off', function(){ - return fs.stat(file.source).then(function(stats){ + it('statSync() - cache off', function() { + return fs.stat(file.source).then(function(stats) { file.statSync({cache: false}).should.eql(stats); }); }); - it('render()', function(){ - return file.render().then(function(data){ + it('render()', function() { + return file.render().then(function(data) { data.should.eql(obj); }); }); - it('render() - callback', function(callback){ - file.render(function(err, data){ + it('render() - callback', function(callback) { + file.render(function(err, data) { should.not.exist(err); data.should.eql(obj); callback(); }); }); - it('renderSync()', function(){ + it('renderSync()', function() { file.renderSync().should.eql(obj); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/box/index.js b/test/scripts/box/index.js index 79ddef00ba..77aaf68c92 100644 --- a/test/scripts/box/index.js +++ b/test/scripts/box/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Box', function(){ +describe('Box', function() { require('./box'); require('./file'); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/clean.js b/test/scripts/console/clean.js index b2150aaf86..2105128d85 100644 --- a/test/scripts/console/clean.js +++ b/test/scripts/console/clean.js @@ -1,34 +1,34 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); -describe('clean', function(){ +describe('clean', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname, {silent: true}); var clean = require('../../../lib/plugins/console/clean').bind(hexo); - it('delete database', function(){ + it('delete database', function() { var dbPath = hexo.database.options.path; - return fs.writeFile(dbPath, '').then(function(){ + return fs.writeFile(dbPath, '').then(function() { return clean(); - }).then(function(){ + }).then(function() { return fs.exists(dbPath); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; }); }); - it('delete public folder', function(){ + it('delete public folder', function() { var publicDir = hexo.public_dir; - return fs.mkdirs(publicDir).then(function(){ + return fs.mkdirs(publicDir).then(function() { return clean(); - }).then(function(){ + }).then(function() { return fs.exists(publicDir); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/config.js b/test/scripts/console/config.js index 683a695192..8adb64b5f2 100644 --- a/test/scripts/console/config.js +++ b/test/scripts/console/config.js @@ -1,27 +1,27 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var pathFn = require('path'); var yaml = require('js-yaml'); var _ = require('lodash'); -describe('config', function(){ +describe('config', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); var config = require('../../../lib/plugins/console/config').bind(hexo); - before(function(){ - return fs.mkdirs(hexo.base_dir).then(function(){ + before(function() { + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); }); }); - beforeEach(function(){ + beforeEach(function() { return fs.writeFile(hexo.config_path, ''); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); @@ -29,54 +29,54 @@ describe('config', function(){ it('read config'); - function writeConfig(){ + function writeConfig() { var args = _.toArray(arguments); - return config({_: args}).then(function(){ + return config({_: args}).then(function() { return fs.readFile(hexo.config_path); - }).then(function(content){ + }).then(function(content) { return yaml.safeLoad(content); }); } - it('write config', function(){ - return writeConfig('title', 'My Blog').then(function(config){ + it('write config', function() { + return writeConfig('title', 'My Blog').then(function(config) { config.title.should.eql('My Blog'); }); }); - it('write config: number', function(){ - return writeConfig('server.port', '5000').then(function(config){ + it('write config: number', function() { + return writeConfig('server.port', '5000').then(function(config) { config.server.port.should.eql(5000); }); }); - it('write config: false', function(){ - return writeConfig('post_asset_folder', 'false').then(function(config){ + it('write config: false', function() { + return writeConfig('post_asset_folder', 'false').then(function(config) { config.post_asset_folder.should.be.false; }); }); - it('write config: true', function(){ - return writeConfig('post_asset_folder', 'true').then(function(config){ + it('write config: true', function() { + return writeConfig('post_asset_folder', 'true').then(function(config) { config.post_asset_folder.should.be.true; }); }); - it('write config: null', function(){ - return writeConfig('language', 'null').then(function(config){ + it('write config: null', function() { + return writeConfig('language', 'null').then(function(config) { should.not.exist(config.language); }); }); - it('write config: json', function(){ + it('write config: json', function() { var configPath = hexo.config_path = pathFn.join(hexo.base_dir, '_config.json'); - return fs.writeFile(configPath, '{}').then(function(){ + return fs.writeFile(configPath, '{}').then(function() { return config({_: ['title', 'My Blog']}); - }).then(function(){ + }).then(function() { return fs.readFile(configPath); - }).then(function(content){ + }).then(function(content) { var json = JSON.parse(content); json.title.should.eql('My Blog'); @@ -86,11 +86,11 @@ describe('config', function(){ }); }); - it('create config if not exist', function(){ - return fs.unlink(hexo.config_path).then(function(){ + it('create config if not exist', function() { + return fs.unlink(hexo.config_path).then(function() { return writeConfig('subtitle', 'Hello world'); - }).then(function(config){ + }).then(function(config) { config.subtitle.should.eql('Hello world'); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/deploy.js b/test/scripts/console/deploy.js index d222b82348..ace8823256 100644 --- a/test/scripts/console/deploy.js +++ b/test/scripts/console/deploy.js @@ -1,37 +1,37 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var pathFn = require('path'); var sinon = require('sinon'); -describe('deploy', function(){ +describe('deploy', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'deploy_test'), {silent: true}); var deploy = require('../../../lib/plugins/console/deploy').bind(hexo); - before(function(){ - return fs.mkdirs(hexo.public_dir).then(function(){ + before(function() { + return fs.mkdirs(hexo.public_dir).then(function() { return hexo.init(); }); }); - beforeEach(function(){ + beforeEach(function() { hexo.config.deploy = {type: 'foo'}; - hexo.extend.deployer.register('foo', function(){}); + hexo.extend.deployer.register('foo', function() {}); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('single deploy setting', function(){ + it('single deploy setting', function() { hexo.config.deploy = { type: 'foo', foo: 'bar' }; - var deployer = sinon.spy(function(args){ + var deployer = sinon.spy(function(args) { args.should.eql({ type: 'foo', foo: 'foo', @@ -46,15 +46,15 @@ describe('deploy', function(){ hexo.once('deployAfter', afterListener); hexo.extend.deployer.register('foo', deployer); - return deploy({foo: 'foo', bar: 'bar'}).then(function(){ + return deploy({foo: 'foo', bar: 'bar'}).then(function() { deployer.calledOnce.should.be.true; beforeListener.calledOnce.should.be.true; afterListener.calledOnce.should.be.true; }); }); - it('multiple deploy setting', function(){ - var deployer1 = sinon.spy(function(args){ + it('multiple deploy setting', function() { + var deployer1 = sinon.spy(function(args) { args.should.eql({ type: 'foo', foo: 'foo', @@ -62,7 +62,7 @@ describe('deploy', function(){ }); }); - var deployer2 = sinon.spy(function(args){ + var deployer2 = sinon.spy(function(args) { args.should.eql({ type: 'bar', bar: 'bar', @@ -78,7 +78,7 @@ describe('deploy', function(){ hexo.extend.deployer.register('foo', deployer1); hexo.extend.deployer.register('bar', deployer2); - return deploy({test: true}).then(function(){ + return deploy({test: true}).then(function() { deployer1.calledOnce.should.be.true; deployer2.calledOnce.should.be.true; }); @@ -86,24 +86,24 @@ describe('deploy', function(){ it('deployer not found'); - it('generate', function(){ - return fs.writeFile(pathFn.join(hexo.source_dir, 'test.txt'), 'test').then(function(){ + it('generate', function() { + return fs.writeFile(pathFn.join(hexo.source_dir, 'test.txt'), 'test').then(function() { return deploy({generate: true}); - }).then(function(){ + }).then(function() { return fs.readFile(pathFn.join(hexo.public_dir, 'test.txt')); - }).then(function(content){ + }).then(function(content) { content.should.eql('test'); return fs.rmdir(hexo.source_dir); }); }); - it('run generate if public directory not exist', function(){ - return fs.rmdir(hexo.public_dir).then(function(){ + it('run generate if public directory not exist', function() { + return fs.rmdir(hexo.public_dir).then(function() { return deploy({}); - }).then(function(){ + }).then(function() { return fs.exists(hexo.public_dir); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.true; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/generate.js b/test/scripts/console/generate.js index 766963862b..c03a035c1d 100644 --- a/test/scripts/console/generate.js +++ b/test/scripts/console/generate.js @@ -1,27 +1,27 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); var sinon = require('sinon'); -describe('generate', function(){ +describe('generate', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'generate_test'), {silent: true}); var generate = require('../../../lib/plugins/console/generate').bind(hexo); - before(function(){ - return fs.mkdirs(hexo.base_dir).then(function(){ + before(function() { + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - afterEach(function(){ + afterEach(function() { return Promise.all([ // Delete the public folder fs.rmdir(hexo.public_dir), @@ -31,7 +31,7 @@ describe('generate', function(){ ]); }); - function testGenerate(options){ + function testGenerate(options) { options = options || {}; return Promise.all([ @@ -42,16 +42,16 @@ describe('generate', function(){ fs.writeFile(pathFn.join(hexo.public_dir, 'foo.txt'), 'foo'), fs.writeFile(pathFn.join(hexo.public_dir, 'bar', 'boo.txt'), 'boo'), fs.writeFile(pathFn.join(hexo.public_dir, 'faz', 'yo.txt'), 'yo') - ]).then(function(){ + ]).then(function() { return generate(options); - }).then(function(){ + }).then(function() { return Promise.all([ fs.readFile(pathFn.join(hexo.public_dir, 'test.txt')), fs.readFile(pathFn.join(hexo.public_dir, 'faz', 'yo.txt')), fs.exists(pathFn.join(hexo.public_dir, 'foo.txt')), fs.exists(pathFn.join(hexo.public_dir, 'bar', 'boo.txt')) ]); - }).then(function(result){ + }).then(function(result) { // Check the new file result[0].should.eql('test'); @@ -64,28 +64,28 @@ describe('generate', function(){ }); } - it('default', function(){ + it('default', function() { return testGenerate(); }); - it('write file if not exist', function(){ + it('write file if not exist', function() { var src = pathFn.join(hexo.source_dir, 'test.txt'); var dest = pathFn.join(hexo.public_dir, 'test.txt'); var content = 'test'; // Add some source files - return fs.writeFile(src, content).then(function(){ + return fs.writeFile(src, content).then(function() { // First generation return generate({}); - }).then(function(){ + }).then(function() { // Delete generated files return fs.unlink(dest); - }).then(function(){ + }).then(function() { // Second generation return generate({}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { result.should.eql(content); // Remove source files and generated files @@ -96,26 +96,26 @@ describe('generate', function(){ }); }); - it('don\'t write if file unchanged', function(){ + it('don\'t write if file unchanged', function() { var src = pathFn.join(hexo.source_dir, 'test.txt'); var dest = pathFn.join(hexo.public_dir, 'test.txt'); var content = 'test'; var newContent = 'newtest'; // Add some source files - return fs.writeFile(src, content).then(function(){ + return fs.writeFile(src, content).then(function() { // First generation return generate({}); - }).then(function(){ + }).then(function() { // Change the generated file return fs.writeFile(dest, newContent); - }).then(function(){ + }).then(function() { // Second generation return generate({}); - }).then(function(){ + }).then(function() { // Read the generated file return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { // Make sure the generated file didn't changed result.should.eql(newContent); @@ -127,26 +127,26 @@ describe('generate', function(){ }); }); - it('force regenerate', function(){ + it('force regenerate', function() { var src = pathFn.join(hexo.source_dir, 'test.txt'); var dest = pathFn.join(hexo.public_dir, 'test.txt'); var content = 'test'; var mtime; - return fs.writeFile(src, content).then(function(){ + return fs.writeFile(src, content).then(function() { // First generation return generate({}); - }).then(function(){ + }).then(function() { // Read file status return fs.stat(dest); - }).then(function(stats){ + }).then(function(stats) { mtime = stats.mtime.getTime(); - }).delay(1000).then(function(){ + }).delay(1000).then(function() { // Force regenerate return generate({force: true}); - }).then(function(){ + }).then(function() { return fs.stat(dest); - }).then(function(stats){ + }).then(function(stats) { stats.mtime.getTime().should.be.above(mtime); // Remove source files and generated files @@ -157,17 +157,17 @@ describe('generate', function(){ }); }); - it('watch - update', function(){ + it('watch - update', function() { var src = pathFn.join(hexo.source_dir, 'test.txt'); var dest = pathFn.join(hexo.public_dir, 'test.txt'); var content = 'test'; - return testGenerate({watch: true}).then(function(){ + return testGenerate({watch: true}).then(function() { // Update the file return fs.writeFile(src, content); - }).delay(300).then(function(){ + }).delay(300).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { // Check the updated file result.should.eql(content); @@ -176,12 +176,12 @@ describe('generate', function(){ }); }); - it('watch - delete', function(){ - return testGenerate({watch: true}).then(function(){ + it('watch - delete', function() { + return testGenerate({watch: true}).then(function() { return fs.unlink(pathFn.join(hexo.source_dir, 'test.txt')); - }).delay(300).then(function(){ + }).delay(300).then(function() { return fs.exists(pathFn.join(hexo.public_dir, 'test.txt')); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; // Stop watching @@ -189,7 +189,7 @@ describe('generate', function(){ }); }); - it('deploy', function(){ + it('deploy', function() { var deployer = sinon.spy(); hexo.extend.deployer.register('test', deployer); @@ -198,37 +198,37 @@ describe('generate', function(){ type: 'test' }; - return generate({deploy: true}).then(function(){ + return generate({deploy: true}).then(function() { deployer.calledOnce.should.be.true; }); }); - it('update theme source files', function(){ + it('update theme source files', function() { return Promise.all([ // Add some source files fs.writeFile(pathFn.join(hexo.theme_dir, 'source', 'a.txt'), 'a'), fs.writeFile(pathFn.join(hexo.theme_dir, 'source', 'b.txt'), 'b'), fs.writeFile(pathFn.join(hexo.theme_dir, 'source', 'c.swig'), 'c') - ]).then(function(){ + ]).then(function() { return generate({}); - }).then(function(){ + }).then(function() { // Update source file return Promise.all([ fs.writeFile(pathFn.join(hexo.theme_dir, 'source', 'b.txt'), 'bb'), fs.writeFile(pathFn.join(hexo.theme_dir, 'source', 'c.swig'), 'cc') ]); - }).then(function(){ + }).then(function() { // Generate again return generate({}); - }).then(function(){ + }).then(function() { // Read the updated source file return Promise.all([ fs.readFile(pathFn.join(hexo.public_dir, 'b.txt')), fs.readFile(pathFn.join(hexo.public_dir, 'c.html')) ]); - }).then(function(result){ + }).then(function(result) { result[0].should.eql('bb'); result[1].should.eql('cc'); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/help.js b/test/scripts/console/help.js index e5fce7db8e..b71d508817 100644 --- a/test/scripts/console/help.js +++ b/test/scripts/console/help.js @@ -1,35 +1,35 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var pathFn = require('path'); var sinon = require('sinon'); -describe('help', function(){ +describe('help', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'help_test'), {silent: true}); var help = require('../../../lib/plugins/console/help').bind(hexo); - before(function(){ - return fs.mkdirs(hexo.base_dir).then(function(){ + before(function() { + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); }); }); beforeEach(function() { - sinon.stub(console, "log").returns(void 0); + sinon.stub(console, 'log').returns(void 0); }); afterEach(function() { console.log.restore(); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); // Only check that the error does not occur - it('help list', function(){ + it('help list', function() { return help({_: ['list']}); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/index.js b/test/scripts/console/index.js index 66bbaf2b38..dc9aa9f289 100644 --- a/test/scripts/console/index.js +++ b/test/scripts/console/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Console', function(){ +describe('Console', function() { require('./clean'); require('./config'); require('./deploy'); @@ -10,4 +10,4 @@ describe('Console', function(){ require('./new'); require('./publish'); require('./render'); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/migrate.js b/test/scripts/console/migrate.js index 29b2a1160f..78d5f852f1 100644 --- a/test/scripts/console/migrate.js +++ b/test/scripts/console/migrate.js @@ -1,23 +1,23 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); -describe('migrate', function(){ +describe('migrate', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname, {silent: true}); var migrate = require('../../../lib/plugins/console/migrate').bind(hexo); - it('default', function(){ - var migrator = sinon.spy(function(args){ + it('default', function() { + var migrator = sinon.spy(function(args) { args.foo.should.eql(1); args.bar.should.eql(2); }); hexo.extend.migrator.register('test', migrator); - return migrate({_: ['test'], foo: 1, bar: 2}).then(function(){ + return migrate({_: ['test'], foo: 1, bar: 2}).then(function() { migrator.calledOnce.should.be.true; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/new.js b/test/scripts/console/new.js index e00e8176ef..e88e70adbb 100644 --- a/test/scripts/console/new.js +++ b/test/scripts/console/new.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var moment = require('moment'); var pathFn = require('path'); var Promise = require('bluebird'); var sinon = require('sinon'); -describe('new', function(){ +describe('new', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'new_test'), {silent: true}); var n = require('../../../lib/plugins/console/new').bind(hexo); @@ -15,19 +15,19 @@ describe('new', function(){ var now = Date.now(); var clock; - before(function(){ + before(function() { clock = sinon.useFakeTimers(now); - return fs.mkdirs(hexo.base_dir).then(function(){ + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); - }).then(function(){ + }).then(function() { return hexo.scaffold.set('post', [ 'title: {{ title }}', 'date: {{ date }}', 'tags:', '---' ].join('\n')); - }).then(function(){ + }).then(function() { return hexo.scaffold.set('draft', [ 'title: {{ title }}', 'tags:', @@ -36,12 +36,12 @@ describe('new', function(){ }); }); - after(function(){ + after(function() { clock.restore(); return fs.rmdir(hexo.base_dir); }); - it('title', function(){ + it('title', function() { var date = moment(now); var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var body = [ @@ -53,33 +53,33 @@ describe('new', function(){ return n({ _: ['Hello World'] - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(content){ + }).then(function(content) { content.should.eql(body); return fs.unlink(path); }); }); - it('layout', function(){ + it('layout', function() { var path = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); var body = [ 'title: Hello World', 'tags:', - '---', + '---' ].join('\n') + '\n'; return n({ _: ['draft', 'Hello World'] - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(content){ + }).then(function(content) { content.should.eql(body); return fs.unlink(path); }); }); - it('slug', function(){ + it('slug', function() { var date = moment(now); var path = pathFn.join(hexo.source_dir, '_posts', 'foo.md'); var body = [ @@ -92,15 +92,15 @@ describe('new', function(){ return n({ _: ['Hello World'], slug: 'foo' - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(content){ + }).then(function(content) { content.should.eql(body); return fs.unlink(path); }); }); - it('path', function(){ + it('path', function() { var date = moment(now); var path = pathFn.join(hexo.source_dir, '_posts', 'bar.md'); var body = [ @@ -114,26 +114,26 @@ describe('new', function(){ _: ['Hello World'], slug: 'foo', path: 'bar' - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(content){ + }).then(function(content) { content.should.eql(body); return fs.unlink(path); }); }); - it('rename if target existed', function(){ + it('rename if target existed', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); return post.create({ title: 'Hello World' - }).then(function(){ + }).then(function() { return n({ _: ['Hello World'] }); - }).then(function(){ + }).then(function() { return fs.exists(path); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.true; return Promise.all([ @@ -143,25 +143,25 @@ describe('new', function(){ }); }); - it('replace existing files', function(){ + it('replace existing files', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); return post.create({ title: 'Hello World' - }).then(function(){ + }).then(function() { return n({ _: ['Hello World'], replace: true }); - }).then(function(){ + }).then(function() { return fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md')); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; return fs.unlink(path); }); }); - it('extra data', function(){ + it('extra data', function() { var date = moment(now); var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var body = [ @@ -175,11 +175,11 @@ describe('new', function(){ return n({ _: ['Hello World'], foo: 'bar' - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(content){ + }).then(function(content) { content.should.eql(body); return fs.unlink(path); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/publish.js b/test/scripts/console/publish.js index 972273d01e..223d560f9f 100644 --- a/test/scripts/console/publish.js +++ b/test/scripts/console/publish.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var moment = require('moment'); var pathFn = require('path'); var Promise = require('bluebird'); var sinon = require('sinon'); -describe('publish', function(){ +describe('publish', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'publish_test'), {silent: true}); var publish = require('../../../lib/plugins/console/publish').bind(hexo); @@ -15,19 +15,19 @@ describe('publish', function(){ var now = Date.now(); var clock; - before(function(){ + before(function() { clock = sinon.useFakeTimers(now); - return fs.mkdirs(hexo.base_dir).then(function(){ + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); - }).then(function(){ + }).then(function() { return hexo.scaffold.set('post', [ 'title: {{ title }}', 'date: {{ date }}', 'tags:', '---' ].join('\n')); - }).then(function(){ + }).then(function() { return hexo.scaffold.set('draft', [ 'title: {{ title }}', 'tags:', @@ -36,19 +36,19 @@ describe('publish', function(){ }); }); - after(function(){ + after(function() { clock.restore(); return fs.rmdir(hexo.base_dir); }); - beforeEach(function(){ + beforeEach(function() { return post.create({ title: 'Hello World', layout: 'draft' }); }); - it('slug', function(){ + it('slug', function() { var draftPath = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -62,12 +62,12 @@ describe('publish', function(){ return publish({ _: ['Hello-World'] - }).then(function(){ + }).then(function() { return Promise.all([ fs.exists(draftPath), fs.readFile(path) ]); - }).spread(function(exist, data){ + }).spread(function(exist, data) { exist.should.be.false; data.should.eql(content); @@ -75,7 +75,7 @@ describe('publish', function(){ }); }); - it('layout', function(){ + it('layout', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -89,26 +89,26 @@ describe('publish', function(){ return publish({ _: ['photo', 'Hello-World'] - }).then(function(){ + }).then(function() { return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); - }) + }); }); - it('rename if target existed', function(){ + it('rename if target existed', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); return post.create({ title: 'Hello World' - }).then(function(){ + }).then(function() { return publish({ _: ['Hello-World'] }); - }).then(function(){ + }).then(function() { return fs.exists(path); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.true; return Promise.all([ @@ -118,22 +118,22 @@ describe('publish', function(){ }); }); - it('replace existing target', function(){ + it('replace existing target', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); return post.create({ title: 'Hello World' - }).then(function(){ + }).then(function() { return publish({ _: ['Hello-World'], replace: true }); - }).then(function(){ + }).then(function() { return fs.exists(pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md')); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; return fs.unlink(path); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/console/render.js b/test/scripts/console/render.js index 25d269791b..43980f9950 100644 --- a/test/scripts/console/render.js +++ b/test/scripts/console/render.js @@ -1,22 +1,22 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var pathFn = require('path'); var Promise = require('bluebird'); -describe('render', function(){ +describe('render', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'render_test'), {silent: true}); var render = require('../../../lib/plugins/console/render').bind(hexo); - before(function(){ - return fs.mkdirs(hexo.base_dir).then(function(){ + before(function() { + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); @@ -26,15 +26,15 @@ describe('render', function(){ ' boo: 2' ].join('\n'); - it('relative path', function(){ + it('relative path', function() { var src = pathFn.join(hexo.base_dir, 'test.yml'); var dest = pathFn.join(hexo.base_dir, 'result.json'); - return fs.writeFile(src, body).then(function(){ + return fs.writeFile(src, body).then(function() { return render({_: ['test.yml'], output: 'result.json'}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { JSON.parse(result).should.eql({ foo: 1, bar: { @@ -49,15 +49,15 @@ describe('render', function(){ }); }); - it('absolute path', function(){ + it('absolute path', function() { var src = pathFn.join(hexo.base_dir, 'test.yml'); var dest = pathFn.join(hexo.base_dir, 'result.json'); - return fs.writeFile(src, body).then(function(){ + return fs.writeFile(src, body).then(function() { return render({_: [src], output: 'result.json'}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { JSON.parse(result).should.eql({ foo: 1, bar: { @@ -72,15 +72,15 @@ describe('render', function(){ }); }); - it('absolute output', function(){ + it('absolute output', function() { var src = pathFn.join(hexo.base_dir, 'test.yml'); var dest = pathFn.join(hexo.base_dir, 'result.json'); - return fs.writeFile(src, body).then(function(){ + return fs.writeFile(src, body).then(function() { return render({_: ['test.yml'], output: dest}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { JSON.parse(result).should.eql({ foo: 1, bar: { @@ -97,15 +97,15 @@ describe('render', function(){ it('output'); - it('engine', function(){ + it('engine', function() { var src = pathFn.join(hexo.base_dir, 'test'); var dest = pathFn.join(hexo.base_dir, 'result.json'); - return fs.writeFile(src, body).then(function(){ + return fs.writeFile(src, body).then(function() { return render({_: ['test'], output: 'result.json', engine: 'yaml'}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { JSON.parse(result).should.eql({ foo: 1, bar: { @@ -120,15 +120,15 @@ describe('render', function(){ }); }); - it('pretty', function(){ + it('pretty', function() { var src = pathFn.join(hexo.base_dir, 'test.yml'); var dest = pathFn.join(hexo.base_dir, 'result.json'); - return fs.writeFile(src, body).then(function(){ + return fs.writeFile(src, body).then(function() { return render({_: ['test.yml'], output: 'result.json', pretty: true}); - }).then(function(){ + }).then(function() { return fs.readFile(dest); - }).then(function(result){ + }).then(function(result) { result.should.eql(JSON.stringify({ foo: 1, bar: { @@ -142,4 +142,4 @@ describe('render', function(){ ]); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/console.js b/test/scripts/extend/console.js index 7c018e5cfc..b15bbfe108 100644 --- a/test/scripts/extend/console.js +++ b/test/scripts/extend/console.js @@ -1,51 +1,54 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Console', function(){ +describe('Console', function() { var Console = require('../../../lib/extend/console'); - it('register()', function(){ + it('register()', function() { var c = new Console(); // no name try { c.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'name is required'); } // name, fn - c.register('test', function(){}); + c.register('test', function() {}); + c.get('test').should.exist; // name, not fn try { c.register('test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } // name, desc, fn - c.register('test', 'this is a test', function(){}); + c.register('test', 'this is a test', function() {}); + c.get('test').should.exist; c.get('test').desc.should.eql('this is a test'); // name, desc, not fn try { c.register('test', 'this is a test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } // name, desc, options, fn - c.register('test', 'this is a test', {init: true}, function(){}); + c.register('test', 'this is a test', {init: true}, function() {}); + c.get('test').should.exist; c.get('test').desc.should.eql('this is a test'); c.get('test').options.init.should.be.true; @@ -53,17 +56,18 @@ describe('Console', function(){ // name, desc, options, not fn try { c.register('test', 'this is a test', {init: true}); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('register() - alias', function(){ + it('register() - alias', function() { var c = new Console(); - c.register('test', function(){}); + c.register('test', function() {}); + c.alias.should.eql({ t: 'test', te: 'test', @@ -72,35 +76,37 @@ describe('Console', function(){ }); }); - it('register() - promisify', function(){ + it('register() - promisify', function() { var c = new Console(); - c.register('test', function(args, callback){ + c.register('test', function(args, callback) { args.should.eql({foo: 'bar'}); callback(null, 'foo'); }); c.get('test')({ foo: 'bar' - }).then(function(result){ + }).then(function(result) { result.should.eql('foo'); }); }); - it('list()', function(){ + it('list()', function() { var c = new Console(); - c.register('test', function(){}); + c.register('test', function() {}); + c.list().should.have.keys(['test']); }); - it('get()', function(){ + it('get()', function() { var c = new Console(); - c.register('test', function(){}); + c.register('test', function() {}); + c.get('test').should.exist; c.get('t').should.exist; c.get('te').should.exist; c.get('tes').should.exist; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/deployer.js b/test/scripts/extend/deployer.js index 2fb3bf8127..5dc7f30737 100644 --- a/test/scripts/extend/deployer.js +++ b/test/scripts/extend/deployer.js @@ -1,21 +1,22 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Deployer', function(){ +describe('Deployer', function() { var Deployer = require('../../../lib/extend/deployer'); - it('register()', function(){ + it('register()', function() { var d = new Deployer(); // name, fn - d.register('test', function(){}); + d.register('test', function() {}); + d.get('test').should.exist; // no name try { d.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'name is required'); @@ -24,54 +25,56 @@ describe('Deployer', function(){ // no fn try { d.register('test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('register() - promisify', function(){ + it('register() - promisify', function() { var d = new Deployer(); - d.register('test', function(args, callback){ + d.register('test', function(args, callback) { args.should.eql({foo: 'bar'}); callback(null, 'foo'); }); d.get('test')({ foo: 'bar' - }).then(function(result){ + }).then(function(result) { result.should.eql('foo'); }); }); - it('register() - Promise.method', function(){ + it('register() - Promise.method', function() { var d = new Deployer(); - d.register('test', function(args){ + d.register('test', function(args) { args.should.eql({foo: 'bar'}); return 'foo'; }); d.get('test')({ foo: 'bar' - }).then(function(result){ + }).then(function(result) { result.should.eql('foo'); }); }); - it('list()', function(){ + it('list()', function() { var d = new Deployer(); - d.register('test', function(){}); + d.register('test', function() {}); + d.list().should.have.keys(['test']); }); - it('get()', function(){ + it('get()', function() { var d = new Deployer(); - d.register('test', function(){}); + d.register('test', function() {}); + d.get('test').should.exist; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 9c601c5c0e..09a690dd52 100644 --- a/test/scripts/extend/filter.js +++ b/test/scripts/extend/filter.js @@ -1,79 +1,87 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); -describe('Filter', function(){ +describe('Filter', function() { var Filter = require('../../../lib/extend/filter'); - it('register()', function(){ + it('register()', function() { var f = new Filter(); // type, fn - f.register('test', function(){}); + f.register('test', function() {}); + f.list('test')[0].should.exist; f.list('test')[0].priority.should.eql(10); // type, fn, priority - f.register('test2', function(){}, 50); + f.register('test2', function() {}, 50); + f.list('test2')[0].priority.should.eql(50); // fn - f.register(function(){}); + f.register(function() {}); + f.list('after_post_render')[0].should.exist; f.list('after_post_render')[0].priority.should.eql(10); // fn, priority - f.register(function(){}, 50); + f.register(function() {}, 50); + f.list('after_post_render')[1].priority.should.eql(50); // no fn try { f.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('register() - type alias', function(){ + it('register() - type alias', function() { var f = new Filter(); // pre - f.register('pre', function(){}); + f.register('pre', function() {}); + f.list('before_post_render')[0].should.exist; // post - f.register('post', function(){}); + f.register('post', function() {}); + f.list('after_post_render')[0].should.exist; }); - it('register() - priority', function(){ + it('register() - priority', function() { var f = new Filter(); - f.register('test', function(){}); - f.register('test', function(){}, 5); - f.register('test', function(){}, 15); + f.register('test', function() {}); + + f.register('test', function() {}, 5); - f.list('test').map(function(item){ + f.register('test', function() {}, 15); + + f.list('test').map(function(item) { return item.priority; }).should.eql([5, 10, 15]); }); - it('unregister()', function(){ + it('unregister()', function() { var f = new Filter(); var filter = sinon.spy(); f.register('test', filter); f.unregister('test', filter); - return f.exec('test').then(function(){ + return f.exec('test').then(function() { filter.called.should.be.false; }); }); - it('unregister() - type is required', function(){ + it('unregister() - type is required', function() { var f = new Filter(); var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'type is required'); @@ -81,14 +89,14 @@ describe('Filter', function(){ try { f.unregister(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('unregister() - fn must be a function', function(){ + it('unregister() - fn must be a function', function() { var f = new Filter(); var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'fn must be a function'); @@ -96,30 +104,31 @@ describe('Filter', function(){ try { f.unregister('test'); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('list()', function(){ + it('list()', function() { var f = new Filter(); - f.register('test', function(){}); + f.register('test', function() {}); + f.list('test')[0].should.exist; f.list('foo').length.should.eql(0); }); - it('exec()', function(){ + it('exec()', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { data.should.eql(''); return data + 'foo'; }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -128,22 +137,22 @@ describe('Filter', function(){ f.register('test', filter1); f.register('test', filter2); - return f.exec('test', '').then(function(data){ + return f.exec('test', '').then(function(data) { filter1.calledOnce.should.be.true; filter2.calledOnce.should.be.true; data.should.eql('foobar'); }); }); - it('exec() - pointer', function(){ + it('exec() - pointer', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { data.should.eql({}); data.foo = 1; }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -152,22 +161,22 @@ describe('Filter', function(){ f.register('test', filter1); f.register('test', filter2); - return f.exec('test', {}).then(function(data){ + return f.exec('test', {}).then(function(data) { filter1.calledOnce.should.be.true; filter2.calledOnce.should.be.true; data.should.eql({foo: 1, bar: 2}); }); }); - it('exec() - args', function(){ + it('exec() - args', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data, arg1, arg2){ + var filter1 = sinon.spy(function(data, arg1, arg2) { arg1.should.eql(1); arg2.should.eql(2); }); - var filter2 = sinon.spy(function(data, arg1, arg2){ + var filter2 = sinon.spy(function(data, arg1, arg2) { arg1.should.eql(1); arg2.should.eql(2); }); @@ -177,42 +186,42 @@ describe('Filter', function(){ return f.exec('test', {}, { args: [1, 2] - }).then(function(){ + }).then(function() { filter1.calledOnce.should.be.true; filter2.calledOnce.should.be.true; }); }); - it('exec() - context', function(){ + it('exec() - context', function() { var f = new Filter(); var ctx = {foo: 1, bar: 2}; - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { this.should.eql(ctx); }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { this.should.eql(ctx); }); f.register('test', filter1); f.register('test', filter2); - return f.exec('test', {}, {context: ctx}).then(function(){ + return f.exec('test', {}, {context: ctx}).then(function() { filter1.calledOnce.should.be.true; filter2.calledOnce.should.be.true; }); }); - it('execSync()', function(){ + it('execSync()', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { data.should.eql(''); return data + 'foo'; }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -226,15 +235,15 @@ describe('Filter', function(){ filter2.calledOnce.should.be.true; }); - it('execSync() - pointer', function(){ + it('execSync() - pointer', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { data.should.eql({}); data.foo = 1; }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -248,15 +257,15 @@ describe('Filter', function(){ filter2.calledOnce.should.be.true; }); - it('execSync() - args', function(){ + it('execSync() - args', function() { var f = new Filter(); - var filter1 = sinon.spy(function(data, arg1, arg2){ + var filter1 = sinon.spy(function(data, arg1, arg2) { arg1.should.eql(1); arg2.should.eql(2); }); - var filter2 = sinon.spy(function(data, arg1, arg2){ + var filter2 = sinon.spy(function(data, arg1, arg2) { arg1.should.eql(1); arg2.should.eql(2); }); @@ -272,15 +281,15 @@ describe('Filter', function(){ filter2.calledOnce.should.be.true; }); - it('execSync() - context', function(){ + it('execSync() - context', function() { var f = new Filter(); var ctx = {foo: 1, bar: 2}; - var filter1 = sinon.spy(function(data){ + var filter1 = sinon.spy(function(data) { this.should.eql(ctx); }); - var filter2 = sinon.spy(function(data){ + var filter2 = sinon.spy(function(data) { this.should.eql(ctx); }); @@ -291,4 +300,4 @@ describe('Filter', function(){ filter1.calledOnce.should.be.true; filter2.calledOnce.should.be.true; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/generator.js b/test/scripts/extend/generator.js index 4a831362c4..4835e57e6e 100644 --- a/test/scripts/extend/generator.js +++ b/test/scripts/extend/generator.js @@ -1,54 +1,58 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Generator', function(){ +describe('Generator', function() { var Generator = require('../../../lib/extend/generator'); - it('register()', function(){ + it('register()', function() { var g = new Generator(); // name, fn - g.register('test', function(){}); + g.register('test', function() {}); + g.get('test').should.exist; // fn - g.register(function(){}); + g.register(function() {}); + g.get('generator-0').should.exist; // no fn try { g.register('test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('register() - promisify', function(){ + it('register() - promisify', function() { var g = new Generator(); - g.register('test', function(locals, render, callback){ + g.register('test', function(locals, render, callback) { callback(null, 'foo'); }); - g.get('test')({}, {}).then(function(result){ + g.get('test')({}, {}).then(function(result) { result.should.eql('foo'); }); }); - it('get()', function(){ + it('get()', function() { var g = new Generator(); - g.register('test', function(){}); + g.register('test', function() {}); + g.get('test').should.exist; }); - it('list()', function(){ + it('list()', function() { var g = new Generator(); - g.register('test', function(){}); + g.register('test', function() {}); + g.list().should.have.keys(['test']); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/helper.js b/test/scripts/extend/helper.js index 68ba4c934e..b73e781788 100644 --- a/test/scripts/extend/helper.js +++ b/test/scripts/extend/helper.js @@ -1,21 +1,22 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Helper', function(){ +describe('Helper', function() { var Helper = require('../../../lib/extend/helper'); - it('register()', function(){ + it('register()', function() { var h = new Helper(); // name, fn - h.register('test', function(){}); + h.register('test', function() {}); + h.get('test').should.exist; // no fn try { h.register('test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); @@ -24,24 +25,26 @@ describe('Helper', function(){ // no name try { h.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'name is required'); } }); - it('list()', function(){ + it('list()', function() { var h = new Helper(); - h.register('test', function(){}); + h.register('test', function() {}); + h.list().should.have.keys(['test']); }); - it('get()', function(){ + it('get()', function() { var h = new Helper(); - h.register('test', function(){}); + h.register('test', function() {}); + h.get('test').should.exist; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/index.js b/test/scripts/extend/index.js index 076c36479a..717b90fd4f 100644 --- a/test/scripts/extend/index.js +++ b/test/scripts/extend/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Extend', function(){ +describe('Extend', function() { require('./console'); require('./deployer'); require('./filter'); @@ -10,4 +10,4 @@ describe('Extend', function(){ require('./processor'); require('./renderer'); require('./tag'); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/migrator.js b/test/scripts/extend/migrator.js index 6b36e18d48..ffdaf623d3 100644 --- a/test/scripts/extend/migrator.js +++ b/test/scripts/extend/migrator.js @@ -1,21 +1,22 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Migrator', function(){ +describe('Migrator', function() { var Migrator = require('../../../lib/extend/migrator'); - it('register()', function(){ + it('register()', function() { var d = new Migrator(); // name, fn - d.register('test', function(){}); + d.register('test', function() {}); + d.get('test').should.exist; // no name try { d.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'name is required'); @@ -24,54 +25,56 @@ describe('Migrator', function(){ // no fn try { d.register('test'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('register() - promisify', function(){ + it('register() - promisify', function() { var d = new Migrator(); - d.register('test', function(args, callback){ + d.register('test', function(args, callback) { args.should.eql({foo: 'bar'}); callback(null, 'foo'); }); d.get('test')({ foo: 'bar' - }).then(function(result){ + }).then(function(result) { result.should.eql('foo'); }); }); - it('register() - Promise.method', function(){ + it('register() - Promise.method', function() { var d = new Migrator(); - d.register('test', function(args){ + d.register('test', function(args) { args.should.eql({foo: 'bar'}); return 'foo'; }); d.get('test')({ foo: 'bar' - }).then(function(result){ + }).then(function(result) { result.should.eql('foo'); }); }); - it('list()', function(){ + it('list()', function() { var d = new Migrator(); - d.register('test', function(){}); + d.register('test', function() {}); + d.list().should.have.keys(['test']); }); - it('get()', function(){ + it('get()', function() { var d = new Migrator(); - d.register('test', function(){}); + d.register('test', function() {}); + d.get('test').should.exist; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/processor.js b/test/scripts/extend/processor.js index 16e1058a5d..b36f06d23f 100644 --- a/test/scripts/extend/processor.js +++ b/test/scripts/extend/processor.js @@ -1,36 +1,38 @@ 'use strict'; -var should = require('chai').should(); -var Pattern = require('hexo-util').Pattern; +var should = require('chai').should(); // eslint-disable-line -describe('Processor', function(){ +describe('Processor', function() { var Processor = require('../../../lib/extend/processor'); - it('register()', function(){ + it('register()', function() { var p = new Processor(); // pattern, fn - p.register('test', function(){}); + p.register('test', function() {}); + p.list()[0].should.exist; // fn - p.register(function(){}); + p.register(function() {}); + p.list()[1].should.exist; // no fn try { p.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); } }); - it('list()', function(){ + it('list()', function() { var p = new Processor(); - p.register('test', function(){}); + p.register('test', function() {}); + p.list().length.should.eql(1); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/renderer.js b/test/scripts/extend/renderer.js index 4d26b1613e..092e32f1ab 100644 --- a/test/scripts/extend/renderer.js +++ b/test/scripts/extend/renderer.js @@ -1,20 +1,22 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Renderer', function(){ +describe('Renderer', function() { var Renderer = require('../../../lib/extend/renderer'); - it('register()', function(){ + it('register()', function() { var r = new Renderer(); // name, output, fn - r.register('yaml', 'json', function(){}); + r.register('yaml', 'json', function() {}); + r.get('yaml').should.exist; r.get('yaml').output.should.eql('json'); // name, output, fn, sync - r.register('yaml', 'json', function(){}, true); + r.register('yaml', 'json', function() {}, true); + r.get('yaml').should.exist; r.get('yaml').output.should.eql('json'); r.get('yaml', true).should.exist; @@ -23,7 +25,7 @@ describe('Renderer', function(){ // no fn try { r.register('yaml', 'json'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'fn must be a function'); @@ -32,7 +34,7 @@ describe('Renderer', function(){ // no output try { r.register('yaml'); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'output is required'); @@ -41,90 +43,97 @@ describe('Renderer', function(){ // no name try { r.register(); - } catch (err){ + } catch (err) { err.should.be .instanceOf(TypeError) .property('message', 'name is required'); } }); - it('register() - promisify', function(){ + it('register() - promisify', function() { var r = new Renderer(); // async - r.register('yaml', 'json', function(data, options, callback){ + r.register('yaml', 'json', function(data, options, callback) { callback(null, 'foo'); }); - r.get('yaml')({}, {}).then(function(result){ + r.get('yaml')({}, {}).then(function(result) { result.should.eql('foo'); }); // sync - r.register('swig', 'html', function(data, options){ + r.register('swig', 'html', function(data, options) { return 'foo'; }, true); - r.get('swig')({}, {}).then(function(result){ + r.get('swig')({}, {}).then(function(result) { result.should.eql('foo'); }); }); - it('getOutput()', function(){ + it('getOutput()', function() { var r = new Renderer(); - r.register('yaml', 'json', function(){}); + r.register('yaml', 'json', function() {}); + r.getOutput('yaml').should.eql('json'); r.getOutput('.yaml').should.eql('json'); r.getOutput('config.yaml').should.eql('json'); r.getOutput('foo.xml').should.not.ok; }); - it('isRenderable()', function(){ + it('isRenderable()', function() { var r = new Renderer(); - r.register('yaml', 'json', function(){}); + r.register('yaml', 'json', function() {}); + r.isRenderable('yaml').should.be.true; r.isRenderable('.yaml').should.be.true; r.isRenderable('config.yaml').should.be.true; r.isRenderable('foo.xml').should.be.false; }); - it('isRenderableSync()', function(){ + it('isRenderableSync()', function() { var r = new Renderer(); - r.register('yaml', 'json', function(){}); + r.register('yaml', 'json', function() {}); + r.isRenderableSync('yaml').should.be.false; - r.register('swig', 'html', function(){}, true); + r.register('swig', 'html', function() {}, true); + r.isRenderableSync('swig').should.be.true; r.isRenderableSync('.swig').should.be.true; r.isRenderableSync('layout.swig').should.be.true; r.isRenderableSync('foo.html').should.be.false; }); - it('get()', function(){ + it('get()', function() { var r = new Renderer(); - r.register('yaml', 'json', function(){}); + r.register('yaml', 'json', function() {}); + r.get('yaml').should.exist; r.get('.yaml').should.exist; r.get('config.yaml').should.exist; should.not.exist(r.get('foo.xml')); should.not.exist(r.get('yaml', true)); - r.register('swig', 'html', function(){}, true); + r.register('swig', 'html', function() {}, true); + r.get('swig').should.exist; r.get('swig', true).should.exist; }); - it('list()', function(){ + it('list()', function() { var r = new Renderer(); - r.register('yaml', 'json', function(){}); - r.register('swig', 'html', function(){}, true); + r.register('yaml', 'json', function() {}); + + r.register('swig', 'html', function() {}, true); r.list().should.have.keys(['yaml', 'swig']); r.list(true).should.have.keys(['swig']); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/extend/tag.js b/test/scripts/extend/tag.js index 34a660b168..ea8033ea51 100644 --- a/test/scripts/extend/tag.js +++ b/test/scripts/extend/tag.js @@ -1,41 +1,41 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var Promise = require('bluebird'); -describe('Tag', function(){ +describe('Tag', function() { var Tag = require('../../../lib/extend/tag'); var tag = new Tag(); - it('register()', function(){ + it('register()', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return args.join(' '); }); - return tag.render('{% test foo.bar | abcdef > fn(a, b, c) < fn() %}').then(function(result){ + return tag.render('{% test foo.bar | abcdef > fn(a, b, c) < fn() %}').then(function(result) { result.should.eql('foo.bar | abcdef > fn(a, b, c) < fn()'); }); }); - it('register() - async', function(){ + it('register() - async', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return Promise.resolve(args.join(' ')); }, {async: true}); - return tag.render('{% test foo bar %}').then(function(result){ + return tag.render('{% test foo bar %}').then(function(result) { result.should.eql('foo bar'); }); }); - it('register() - block', function(){ + it('register() - block', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return args.join(' ') + ' ' + content; }, true); @@ -45,15 +45,15 @@ describe('Tag', function(){ '{% endtest %}' ].join('\n'); - return tag.render(str).then(function(result){ + return tag.render(str).then(function(result) { result.should.eql('foo bar test content'); }); }); - it('register() - async block', function(){ + it('register() - async block', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return Promise.resolve(args.join(' ') + ' ' + content); }, {ends: true, async: true}); @@ -63,15 +63,15 @@ describe('Tag', function(){ '{% endtest %}' ].join('\n'); - return tag.render(str).then(function(result){ + return tag.render(str).then(function(result) { result.should.eql('foo bar test content'); }); }); - it('register() - nested test', function(){ + it('register() - nested test', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return content; }, true); @@ -88,15 +88,15 @@ describe('Tag', function(){ '{% endtest %}' ].join('\n'); - return tag.render(str).then(function(result){ + return tag.render(str).then(function(result) { result.replace(/\s/g, '').should.eql('123456rawtest789012'); }); }); - it('register() - strip indention', function(){ + it('register() - strip indention', function() { var tag = new Tag(); - tag.register('test', function(args, content){ + tag.register('test', function(args, content) { return content; }, true); @@ -106,60 +106,60 @@ describe('Tag', function(){ '{% endtest %}' ].join('\n'); - return tag.render(str).then(function(result){ + return tag.render(str).then(function(result) { result.should.eql('test content'); }); }); - it('register() - async callback', function(){ + it('register() - async callback', function() { var tag = new Tag(); - tag.register('test', function(args, content, callback){ + tag.register('test', function(args, content, callback) { callback(null, args.join(' ')); }, {async: true}); - return tag.render('{% test foo bar %}').then(function(result){ + return tag.render('{% test foo bar %}').then(function(result) { result.should.eql('foo bar'); }); }); - it('register() - name is required', function(){ + it('register() - name is required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'name is required'); }); try { tag.register(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('register() - fn must be a function', function(){ + it('register() - fn must be a function', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'fn must be a function'); }); try { tag.register('test'); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('render() - context', function(){ + it('render() - context', function() { var tag = new Tag(); - tag.register('test', function(){ + tag.register('test', function() { return this.foo; }); - return tag.render('{% test %}', {foo: 'bar'}).then(function(result){ + return tag.render('{% test %}', {foo: 'bar'}).then(function(result) { result.should.eql('bar'); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/backtick_code_block.js b/test/scripts/filters/backtick_code_block.js index 28921bdf64..b2f74dd547 100644 --- a/test/scripts/filters/backtick_code_block.js +++ b/test/scripts/filters/backtick_code_block.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var util = require('hexo-util'); var _ = require('lodash'); var defaultConfig = require('../../../lib/hexo/default_config'); -describe('Backtick code block', function(){ +describe('Backtick code block', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var codeBlock = require('../../../lib/plugins/filter/before_post_render/backtick_code_block').bind(hexo); @@ -16,18 +16,18 @@ describe('Backtick code block', function(){ '}' ].join('\n'); - function highlight(code, options){ + function highlight(code, options) { return util.highlight(code, options || {}) .replace(/{/g, '{') .replace(/}/g, '}'); } - beforeEach(function(){ + beforeEach(function() { // Reset config hexo.config.highlight = _.clone(defaultConfig.highlight); }); - it('disabled', function(){ + it('disabled', function() { var content = [ '``` js', code, @@ -41,7 +41,7 @@ describe('Backtick code block', function(){ data.content.should.eql(content); }); - it('with no config (disabled)', function(){ + it('with no config (disabled)', function() { var content = [ '``` js', code, @@ -59,7 +59,7 @@ describe('Backtick code block', function(){ hexo.config.highlight = oldConfig; }); - it('default', function(){ + it('default', function() { var data = { content: [ '``` js', @@ -72,7 +72,7 @@ describe('Backtick code block', function(){ data.content.should.eql('quote content
\n', '
123456 bold and italic
\n'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/number_format.js b/test/scripts/helpers/number_format.js index 164a0e22b4..06c1502e31 100644 --- a/test/scripts/helpers/number_format.js +++ b/test/scripts/helpers/number_format.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('number_format', function(){ +describe('number_format', function() { var numberFormat = require('../../../lib/plugins/helper/number_format'); - it('default', function(){ + it('default', function() { numberFormat(1234.567).should.eql('1,234.567'); }); - it('precision', function(){ + it('precision', function() { numberFormat(1234.567, {precision: false}).should.eql('1,234.567'); numberFormat(1234.567, {precision: 0}).should.eql('1,234'); numberFormat(1234.567, {precision: 1}).should.eql('1,234.6'); @@ -18,11 +18,11 @@ describe('number_format', function(){ numberFormat(1234.567, {precision: 4}).should.eql('1,234.5670'); }); - it('delimiter', function(){ + it('delimiter', function() { numberFormat(1234.567, {delimiter: ' '}).should.eql('1 234.567'); }); - it('separator', function(){ + it('separator', function() { numberFormat(1234.567, {separator: '*'}).should.eql('1,234*567'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js index 1ac96eb19e..b62d5d073c 100644 --- a/test/scripts/helpers/open_graph.js +++ b/test/scripts/helpers/open_graph.js @@ -1,19 +1,19 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('open_graph', function(){ +describe('open_graph', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var openGraph = require('../../../lib/plugins/helper/open_graph'); var isPost = require('../../../lib/plugins/helper/is').post; var tag = require('hexo-util').htmlTag; - function meta(options){ + function meta(options) { return tag('meta', options); } - it('default', function(){ + it('default', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -33,7 +33,7 @@ describe('open_graph', function(){ ].join('\n')); }); - it('title - page', function(){ + it('title - page', function() { var ctx = { page: {title: 'Hello world'}, config: hexo.config, @@ -45,7 +45,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:title', content: ctx.page.title})); }); - it('title - options', function(){ + it('title - options', function() { var result = openGraph.call({ page: {title: 'Hello world'}, config: hexo.config, @@ -55,7 +55,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:title', content: 'test'})); }); - it('type - options', function(){ + it('type - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -65,17 +65,19 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:type', content: 'photo'})); }); - it('type - is_post', function(){ + it('type - is_post', function() { var result = openGraph.call({ page: {}, config: hexo.config, - is_post: function(){ return true; } + is_post: function() { + return true; + } }); result.should.contain(meta({property: 'og:type', content: 'article'})); }); - it('url - context', function(){ + it('url - context', function() { var ctx = { page: {}, config: hexo.config, @@ -88,7 +90,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:url', content: ctx.url})); }); - it('url - options', function(){ + it('url - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -99,7 +101,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:url', content: 'http://hexo.io/bar'})); }); - it('images - content', function(){ + it('images - content', function() { var result = openGraph.call({ page: { content: [ @@ -114,7 +116,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: 'http://hexo.io/test.jpg'})); }); - it('images - string', function(){ + it('images - string', function() { var result = openGraph.call({ page: { photos: 'http://hexo.io/test.jpg' @@ -126,7 +128,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: 'http://hexo.io/test.jpg'})); }); - it('images - array', function(){ + it('images - array', function() { var result = openGraph.call({ page: { photos: [ @@ -144,7 +146,7 @@ describe('open_graph', function(){ ].join('\n')); }); - it('images - don\'t pollute context', function(){ + it('images - don\'t pollute context', function() { var ctx = { page: { content: [ @@ -161,7 +163,7 @@ describe('open_graph', function(){ ctx.page.photos.should.eql([]); }); - it('images - options.image', function(){ + it('images - options.image', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -171,7 +173,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: 'http://hexo.io/test.jpg'})); }); - it('images - options.images', function(){ + it('images - options.images', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -181,7 +183,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: 'http://hexo.io/test.jpg'})); }); - it('images - prepend config.url to the path (without prefixing /)', function(){ + it('images - prepend config.url to the path (without prefixing /)', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -191,7 +193,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: hexo.config.url + '/test.jpg'})); }); - it('images - prepend config.url to the path (with prefixing /)', function(){ + it('images - prepend config.url to the path (with prefixing /)', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -201,7 +203,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:image', content: hexo.config.url + '/test.jpg'})); }); - it('site_name - options', function(){ + it('site_name - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -211,7 +213,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:site_name', content: 'foo'})); }); - it('description - page', function(){ + it('description - page', function() { var ctx = { page: {description: 'test'}, config: hexo.config, @@ -224,7 +226,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:description', content: ctx.page.description})); }); - it('description - options', function(){ + it('description - options', function() { var ctx = { page: {description: 'test'}, config: hexo.config, @@ -237,7 +239,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:description', content: 'foo'})); }); - it('description - excerpt', function(){ + it('description - excerpt', function() { var ctx = { page: {excerpt: 'test'}, config: hexo.config, @@ -250,7 +252,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:description', content: ctx.page.excerpt})); }); - it('description - content', function(){ + it('description - content', function() { var ctx = { page: {content: 'test'}, config: hexo.config, @@ -263,7 +265,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:description', content: ctx.page.content})); }); - it('description - config', function(){ + it('description - config', function() { var ctx = { page: {}, config: hexo.config, @@ -280,7 +282,7 @@ describe('open_graph', function(){ hexo.config.description = ''; }); - it('description - escape', function(){ + it('description - escape', function() { var ctx = { page: {description: 'Important! Today is "not" \'Xmas\'!'}, config: hexo.config, @@ -294,7 +296,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'og:description', content: escaped})); }); - it('twitter_card - options', function(){ + it('twitter_card - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -304,7 +306,7 @@ describe('open_graph', function(){ result.should.contain(meta({name: 'twitter:card', content: 'photo'})); }); - it('twitter_id - options (without prefixing @)', function(){ + it('twitter_id - options (without prefixing @)', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -314,7 +316,7 @@ describe('open_graph', function(){ result.should.contain(meta({name: 'twitter:creator', content: '@hexojs'})); }); - it('twitter_id - options (with prefixing @)', function(){ + it('twitter_id - options (with prefixing @)', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -324,7 +326,7 @@ describe('open_graph', function(){ result.should.contain(meta({name: 'twitter:creator', content: '@hexojs'})); }); - it('twitter_site - options', function(){ + it('twitter_site - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -334,7 +336,7 @@ describe('open_graph', function(){ result.should.contain(meta({name: 'twitter:site', content: 'Hello'})); }); - it('google_plus - options', function(){ + it('google_plus - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -344,7 +346,7 @@ describe('open_graph', function(){ result.should.contain(tag('link', {rel: 'publisher', href: '+123456789'})); }); - it('fb_admins - options', function(){ + it('fb_admins - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -354,7 +356,7 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'fb:admins', content: '123456789'})); }); - it('fb_app_id - options', function(){ + it('fb_app_id - options', function() { var result = openGraph.call({ page: {}, config: hexo.config, @@ -363,4 +365,4 @@ describe('open_graph', function(){ result.should.contain(meta({property: 'fb:app_id', content: '123456789'})); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/paginator.js b/test/scripts/helpers/paginator.js index 38dfd55b3a..890ae66cc1 100644 --- a/test/scripts/helpers/paginator.js +++ b/test/scripts/helpers/paginator.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('paginator', function(){ +describe('paginator', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -19,11 +19,11 @@ describe('paginator', function(){ var paginator = require('../../../lib/plugins/helper/paginator').bind(ctx); - function link(i){ + function link(i) { return ctx.url_for(i === 1 ? '' : 'page/' + i + '/'); } - function checkResult(result, data){ + function checkResult(result, data) { var expected = ''; var current = data.current; var total = data.total; @@ -32,23 +32,23 @@ describe('paginator', function(){ var prevNext = data.hasOwnProperty('prev_next') ? data.prev_next : true; var num; - if (prevNext && current > 1){ + if (prevNext && current > 1) { expected += 'Prev'; } - for (var i = 0, len = pages.length; i < len; i++){ + for (var i = 0, len = pages.length; i < len; i++) { num = pages[i]; - if (!num){ + if (!num) { expected += '' + space + ''; - } else if (num === current){ + } else if (num === current) { expected += '' + current + ''; } else { expected += '' + num + ''; } } - if (prevNext && current < total){ + if (prevNext && current < total) { expected += 'Next'; } @@ -66,11 +66,11 @@ describe('paginator', function(){ [1, 0, 6, 7, 8, 9, 10], [1, 0, 7, 8, 9, 10], [1, 0, 8, 9, 10] - ].forEach(function(pages, i, arr){ + ].forEach(function(pages, i, arr) { var current = i + 1; var total = arr.length; - it('current = ' + current, function(){ + it('current = ' + current, function() { var result = paginator({ current: current, total: total @@ -84,7 +84,7 @@ describe('paginator', function(){ }); }); - it('show_all', function(){ + it('show_all', function() { var result = paginator({ current: 5, show_all: true @@ -97,7 +97,7 @@ describe('paginator', function(){ }); }); - it('end_size', function(){ + it('end_size', function() { var result = paginator({ current: 5, end_size: 2 @@ -110,7 +110,7 @@ describe('paginator', function(){ }); }); - it('end_size = 0', function(){ + it('end_size = 0', function() { var result = paginator({ current: 5, end_size: 0 @@ -123,7 +123,7 @@ describe('paginator', function(){ }); }); - it('mid_size', function(){ + it('mid_size', function() { var result = paginator({ current: 5, mid_size: 1 @@ -136,7 +136,7 @@ describe('paginator', function(){ }); }); - it('mid_size = 0', function(){ + it('mid_size = 0', function() { var result = paginator({ current: 5, mid_size: 0 @@ -149,7 +149,7 @@ describe('paginator', function(){ }); }); - it('space', function(){ + it('space', function() { var result = paginator({ current: 5, space: '~' @@ -161,9 +161,9 @@ describe('paginator', function(){ pages: [1, 0, 3, 4, 5, 6, 7, 0, 10], space: '~' }); - }) + }); - it('no space', function(){ + it('no space', function() { var result = paginator({ current: 5, space: '' @@ -176,7 +176,7 @@ describe('paginator', function(){ }); }); - it('base', function(){ + it('base', function() { var result = paginator({ current: 1, base: 'archives/' @@ -192,7 +192,7 @@ describe('paginator', function(){ ].join('')); }); - it('format', function(){ + it('format', function() { var result = paginator({ current: 1, format: 'index-%d.html' @@ -208,7 +208,7 @@ describe('paginator', function(){ ].join('')); }); - it('prev_text / next_text', function(){ + it('prev_text / next_text', function() { var result = paginator({ current: 2, prev_text: 'Newer', @@ -227,7 +227,7 @@ describe('paginator', function(){ ].join('')); }); - it('prev_next', function(){ + it('prev_next', function() { var result = paginator({ current: 2, prev_next: false @@ -239,14 +239,14 @@ describe('paginator', function(){ '3', '4', '…', - '10', + '10' ].join('')); }); - it('transform', function(){ + it('transform', function() { var result = paginator({ current: 2, - transform: function(page){ + transform: function(page) { return 'Page ' + page; } }); @@ -263,7 +263,7 @@ describe('paginator', function(){ ].join('')); }); - it('context', function(){ + it('context', function() { ctx.page.current = 5; var result = paginator({ space: '' @@ -276,10 +276,10 @@ describe('paginator', function(){ }); }); - it('current = 0', function(){ + it('current = 0', function() { ctx.page.current = 0; var result = paginator({}); result.should.eql(''); - }) -}); \ No newline at end of file + }); +}); diff --git a/test/scripts/helpers/partial.js b/test/scripts/helpers/partial.js index 69396c667b..9c91fbf48b 100644 --- a/test/scripts/helpers/partial.js +++ b/test/scripts/helpers/partial.js @@ -1,12 +1,12 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('partial', function(){ +describe('partial', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'partial_test'), {silent: true}); var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); @@ -27,22 +27,22 @@ describe('partial', function(){ var partial = require('../../../lib/plugins/helper/partial')(hexo).bind(ctx); - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); - }).then(function(){ + }).then(function() { hexo.theme.setView('widget/tag.swig', 'tag widget'); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('default', function(){ + it('default', function() { // relative path partial('../widget/tag').should.eql('tag widget'); @@ -53,26 +53,26 @@ describe('partial', function(){ partial('foo').should.eql(''); }); - it('locals', function(){ + it('locals', function() { hexo.theme.setView('test.swig', '{{ foo }}'); partial('test', {foo: 'bar'}).should.eql('bar'); }); - it('cache', function(){ + it('cache', function() { hexo.theme.setView('test.swig', '{{ foo }}'); partial('test', {foo: 'bar'}, {cache: true}).should.eql('bar'); partial('test', {}, {cache: true}).should.eql('bar'); }); - it('only', function(){ + it('only', function() { hexo.theme.setView('test.swig', '{{ foo }}{{ bar }}'); partial('test', {bar: 'bar'}, {only: true}).should.eql('bar'); }); - it('a partial in another partial', function(){ + it('a partial in another partial', function() { hexo.theme.setView('partial/a.swig', '{{ partial("b") }}'); hexo.theme.setView('partial/b.swig', '{{ partial("c") }}'); hexo.theme.setView('partial/c.swig', 'c'); @@ -80,17 +80,17 @@ describe('partial', function(){ partial('partial/a').should.eql('c'); }); - it('name must be a string', function(){ + it('name must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'name must be a string!'); }); try { partial(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/relative_url.js b/test/scripts/helpers/relative_url.js index 0324d8151d..5ecdd2c321 100644 --- a/test/scripts/helpers/relative_url.js +++ b/test/scripts/helpers/relative_url.js @@ -1,32 +1,32 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('relative_url', function(){ +describe('relative_url', function() { var relativeURL = require('../../../lib/plugins/helper/relative_url'); - it('from root', function(){ + it('from root', function() { relativeURL('', 'css/style.css').should.eql('css/style.css'); relativeURL('index.html', 'css/style.css').should.eql('css/style.css'); }); - it('from same root', function(){ + it('from same root', function() { relativeURL('foo/', 'foo/style.css').should.eql('style.css'); relativeURL('foo/index.html', 'foo/style.css').should.eql('style.css'); relativeURL('foo/bar/', 'foo/bar/style.css').should.eql('style.css'); relativeURL('foo/bar/index.html', 'foo/bar/style.css').should.eql('style.css'); }); - it('from different root', function(){ + it('from different root', function() { relativeURL('foo/', 'css/style.css').should.eql('../css/style.css'); relativeURL('foo/index.html', 'css/style.css').should.eql('../css/style.css'); relativeURL('foo/bar/', 'css/style.css').should.eql('../../css/style.css'); relativeURL('foo/bar/index.html', 'css/style.css').should.eql('../../css/style.css'); }); - it('to root', function(){ + it('to root', function() { relativeURL('index.html', '/').should.eql('index.html'); relativeURL('foo/', '/').should.eql('../index.html'); relativeURL('foo/index.html', '/').should.eql('../index.html'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/render.js b/test/scripts/helpers/render.js index c1e4a6df39..4de802ac8e 100644 --- a/test/scripts/helpers/render.js +++ b/test/scripts/helpers/render.js @@ -1,17 +1,17 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('render', function(){ +describe('render', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var render = require('../../../lib/plugins/helper/render')(hexo); - before(function(){ + before(function() { return hexo.init(); }); - it('default', function(){ + it('default', function() { var body = [ 'foo: 1', 'bar:', @@ -27,4 +27,4 @@ describe('render', function(){ } }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/search_form.js b/test/scripts/helpers/search_form.js index 1e22a31aa0..6578cbcf3f 100644 --- a/test/scripts/helpers/search_form.js +++ b/test/scripts/helpers/search_form.js @@ -1,34 +1,34 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('search_form', function(){ +describe('search_form', function() { var searchForm = require('../../../lib/plugins/helper/search_form').bind({ config: {url: 'http://hexo.io'} }); - it('default', function(){ + it('default', function() { searchForm().should.eql(''); }); - it('class', function(){ + it('class', function() { searchForm({class: 'foo'}).should.eql(''); }); - it('text', function(){ + it('text', function() { searchForm({text: 'Find'}).should.eql(''); }); - it('button enabled', function(){ + it('button enabled', function() { searchForm({button: true, text: 'Find'}).should.eql(''); }); - it('button text', function(){ + it('button text', function() { searchForm({button: 'Go', text: 'Find'}).should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/tagcloud.js b/test/scripts/helpers/tagcloud.js index 662ee33486..60120095d9 100644 --- a/test/scripts/helpers/tagcloud.js +++ b/test/scripts/helpers/tagcloud.js @@ -1,9 +1,9 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); -describe('tagcloud', function(){ +describe('tagcloud', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Post = hexo.model('Post'); @@ -17,29 +17,29 @@ describe('tagcloud', function(){ var tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(ctx); - before(function(){ + before(function() { return Post.insert([ {source: 'foo', slug: 'foo'}, {source: 'bar', slug: 'bar'}, {source: 'baz', slug: 'baz'}, {source: 'boo', slug: 'boo'} - ]).then(function(posts){ + ]).then(function(posts) { // TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem return Promise.each([ ['bcd'], ['bcd', 'cde'], ['bcd', 'cde', 'abc'], ['bcd', 'cde', 'abc', 'def'] - ], function(tags, i){ + ], function(tags, i) { return posts[i].setTags(tags); }); - }).then(function(){ + }).then(function() { hexo.locals.invalidate(); ctx.site = hexo.locals.toObject(); }); }); - it('default', function(){ + it('default', function() { var result = tagcloud(); result.should.eql([ @@ -50,7 +50,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('specified collection', function(){ + it('specified collection', function() { var result = tagcloud(Tag.find({ name: /bc/ })); @@ -61,7 +61,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('font size', function(){ + it('font size', function() { var result = tagcloud({ min_font: 15, max_font: 30 @@ -88,7 +88,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('font unit', function(){ + it('font unit', function() { var result = tagcloud({ unit: 'em' }); @@ -101,7 +101,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('orderby', function(){ + it('orderby', function() { var result = tagcloud({ orderby: 'length' }); @@ -114,7 +114,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('order', function(){ + it('order', function() { var result = tagcloud({ order: -1 }); @@ -127,7 +127,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('amount', function(){ + it('amount', function() { var result = tagcloud({ amount: 2 }); @@ -138,9 +138,9 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('transform', function(){ + it('transform', function() { var result = tagcloud({ - transform: function(name){ + transform: function(name) { return name.toUpperCase(); } }); @@ -153,7 +153,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('color: name', function(){ + it('color: name', function() { var result = tagcloud({ color: true, start_color: 'red', @@ -168,7 +168,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('color: hex', function(){ + it('color: hex', function() { var result = tagcloud({ color: true, start_color: '#f00', // red @@ -183,7 +183,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('color: RGBA', function(){ + it('color: RGBA', function() { var result = tagcloud({ color: true, start_color: 'rgba(70, 130, 180, 0.3)', // steelblue @@ -198,7 +198,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('color: HSLA', function(){ + it('color: HSLA', function() { var result = tagcloud({ color: true, start_color: 'hsla(207, 44%, 49%, 0.3)', // rgba(70, 130, 180, 0.3) @@ -227,7 +227,7 @@ describe('tagcloud', function(){ ].join(' ')); }); - it('separator', function(){ + it('separator', function() { var result = tagcloud({ separator: ', ' }); diff --git a/test/scripts/helpers/toc.js b/test/scripts/helpers/toc.js index 4d75bb3d4d..4d6a86873b 100644 --- a/test/scripts/helpers/toc.js +++ b/test/scripts/helpers/toc.js @@ -1,9 +1,9 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var _ = require('lodash'); -describe('toc', function(){ +describe('toc', function() { var toc = require('../../../lib/plugins/helper/toc'); var html = [ @@ -17,14 +17,14 @@ describe('toc', function(){ 'file test
'); return fs.unlink(path); }); }); - it('render() - toString', function(){ + it('render() - toString', function() { var content = 'foo: 1'; return post.render(null, { content: content, engine: 'yaml' - }).then(function(data){ + }).then(function(data) { data.content.should.eql('{"foo":1}'); }); }); - it('render() - skip render phase if it\'s swig file', function(){ + it('render() - skip render phase if it\'s swig file', function() { var content = [ '{% quote Hello World %}', 'quote content', @@ -625,7 +627,7 @@ describe('Post', function(){ return post.render(null, { content: content, engine: 'swig' - }).then(function(data){ + }).then(function(data) { data.content.trim().should.eql([ '' @@ -633,7 +635,7 @@ describe('Post', function(){ }); }); - it('render() - escaping swig blocks with similar names', function(){ + it('render() - escaping swig blocks with similar names', function() { var code = 'alert("Hello world")'; var highlighted = util.highlight(code); @@ -649,7 +651,7 @@ describe('Post', function(){ return post.render(null, { content: content - }).then(function(data){ + }).then(function(data) { data.content.trim().should.eql([ highlighted, '', @@ -658,31 +660,32 @@ describe('Post', function(){ }); }); - it('render() - recover escaped swig blocks which is html escaped', function(){ + it('render() - recover escaped swig blocks which is html escaped', function() { var content = '`{% raw %}{{ test }}{% endraw %}`'; return post.render(null, { content: content, engine: 'markdown' - }).then(function(data){ + }).then(function(data) { data.content.trim().should.eql('quote content
\n', '
{{ test }}
{{ test }}
'); }); - it('author', function(){ + it('author', function() { var result = bq('John Doe', ''); result.should.eql(''); }); - it('source', function(){ + it('source', function() { var result = bq('Jane Austen, Pride and Prejudice'); result.should.eql(''); }); - it('link', function(){ + it('link', function() { var result = bq('John Doe http://hexo.io/'); result.should.eql(''); }); - it('link title', function(){ + it('link title', function() { var result = bq('John Doe http://hexo.io/ Hexo'); result.should.eql(''); }); - it('titlecase', function(){ + it('titlecase', function() { hexo.config.titlecase = true; var result = bq('Jane Austen, pride and prejudice'); @@ -50,4 +50,4 @@ describe('blockquote', function(){ hexo.config.titlecase = false; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/code.js b/test/scripts/tags/code.js index 552465ffb4..4b2c045360 100644 --- a/test/scripts/tags/code.js +++ b/test/scripts/tags/code.js @@ -1,9 +1,9 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var util = require('hexo-util'); -describe('code', function(){ +describe('code', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var codeTag = require('../../../lib/plugins/tag/code')(hexo); @@ -14,32 +14,32 @@ describe('code', function(){ '}' ].join('\n'); - function code(args, content){ + function code(args, content) { return codeTag(args.split(' '), content); } - function highlight(code, options){ + function highlight(code, options) { return util.highlight(code, options || {}) .replace(/{/g, '{') .replace(/}/g, '}'); } - it('default', function(){ + it('default', function() { var result = code('', fixture); result.should.eql(highlight(fixture)); }); - it('lang', function(){ + it('lang', function() { var result = code('lang:js', fixture); result.should.eql(highlight(fixture, {lang: 'js'})); }); - it('title', function(){ + it('title', function() { var result = code('Hello world', fixture); result.should.eql(highlight(fixture, {caption: 'Hello world'})); }); - it('link', function(){ + it('link', function() { var result = code('Hello world http://hexo.io/', fixture); var expected = highlight(fixture, { caption: 'Hello worldlink' @@ -48,7 +48,7 @@ describe('code', function(){ result.should.eql(expected); }); - it('link text', function(){ + it('link text', function() { var result = code('Hello world http://hexo.io/ Hexo', fixture); var expected = highlight(fixture, { caption: 'Hello worldHexo' @@ -57,7 +57,7 @@ describe('code', function(){ result.should.eql(expected); }); - it('disabled', function(){ + it('disabled', function() { hexo.config.highlight.enable = false; var result = code('', fixture); @@ -65,4 +65,4 @@ describe('code', function(){ hexo.config.highlight.enable = true; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/gist.js b/test/scripts/tags/gist.js index 5d1219d87f..4b05995ba8 100644 --- a/test/scripts/tags/gist.js +++ b/test/scripts/tags/gist.js @@ -1,18 +1,18 @@ 'use strict'; var cheerio = require('cheerio'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('gist', function(){ +describe('gist', function() { var gist = require('../../../lib/plugins/tag/gist'); - it('id', function(){ + it('id', function() { var $ = cheerio.load(gist(['foo'])); $('script').attr('src').should.eql('//gist.github.com/foo.js'); }); - it('file', function(){ + it('file', function() { var $ = cheerio.load(gist(['foo', 'bar'])); $('script').attr('src').should.eql('//gist.github.com/foo.js?file=bar'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/iframe.js b/test/scripts/tags/iframe.js index 2ed0874dad..66533ace6d 100644 --- a/test/scripts/tags/iframe.js +++ b/test/scripts/tags/iframe.js @@ -1,12 +1,12 @@ 'use strict'; var cheerio = require('cheerio'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('iframe', function(){ +describe('iframe', function() { var iframe = require('../../../lib/plugins/tag/iframe'); - it('url', function(){ + it('url', function() { var $ = cheerio.load(iframe(['http://zespia.tw'])); $('iframe').attr('src').should.eql('http://zespia.tw'); @@ -16,7 +16,7 @@ describe('iframe', function(){ $('iframe').attr('allowfullscreen').should.eql(''); }); - it('width', function(){ + it('width', function() { var $ = cheerio.load(iframe(['http://zespia.tw', '500'])); $('iframe').attr('src').should.eql('http://zespia.tw'); @@ -26,7 +26,7 @@ describe('iframe', function(){ $('iframe').attr('allowfullscreen').should.eql(''); }); - it('height', function(){ + it('height', function() { var $ = cheerio.load(iframe(['http://zespia.tw', '500', '600'])); $('iframe').attr('src').should.eql('http://zespia.tw'); @@ -35,4 +35,4 @@ describe('iframe', function(){ $('iframe').attr('frameborder').should.eql('0'); $('iframe').attr('allowfullscreen').should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/img.js b/test/scripts/tags/img.js index fc61d485e7..4e4671efaa 100644 --- a/test/scripts/tags/img.js +++ b/test/scripts/tags/img.js @@ -1,52 +1,52 @@ 'use strict'; var cheerio = require('cheerio'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('img', function(){ +describe('img', function() { var img = require('../../../lib/plugins/tag/img'); - it('src', function(){ + it('src', function() { var $ = cheerio.load(img(['http://placekitten.com/200/300'])); $('img').attr('src').should.eql('http://placekitten.com/200/300'); }); - it('internal src', function(){ + it('internal src', function() { var $ = cheerio.load(img(['/images/test.jpg'])); $('img').attr('src').should.eql('/images/test.jpg'); }); - it('class + src', function(){ + it('class + src', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); $('img').attr('class').should.eql('left'); }); - it('class + internal src', function(){ + it('class + internal src', function() { var $ = cheerio.load(img('left /images/test.jpg'.split(' '))); $('img').attr('src').should.eql('/images/test.jpg'); $('img').attr('class').should.eql('left'); }); - it('multiple classes + src', function(){ + it('multiple classes + src', function() { var $ = cheerio.load(img('left top http://placekitten.com/200/300'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); $('img').attr('class').should.eql('left top'); }); - it('multiple classes + internal src', function(){ + it('multiple classes + internal src', function() { var $ = cheerio.load(img('left top /images/test.jpg'.split(' '))); $('img').attr('src').should.eql('/images/test.jpg'); $('img').attr('class').should.eql('left top'); }); - it('class + src + width', function(){ + it('class + src + width', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 200'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -54,7 +54,7 @@ describe('img', function(){ $('img').attr('width').should.eql('200'); }); - it('class + src + width + height', function(){ + it('class + src + width + height', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 200 300'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -63,7 +63,7 @@ describe('img', function(){ $('img').attr('height').should.eql('300'); }); - it('class + src + title', function(){ + it('class + src + title', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 Place Kitten'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -71,7 +71,7 @@ describe('img', function(){ $('img').attr('title').should.eql('Place Kitten'); }); - it('class + src + width + title', function(){ + it('class + src + width + title', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 200 Place Kitten'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -80,7 +80,7 @@ describe('img', function(){ $('img').attr('title').should.eql('Place Kitten'); }); - it('class + src + width + height + title', function(){ + it('class + src + width + height + title', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 200 300 Place Kitten'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -90,7 +90,7 @@ describe('img', function(){ $('img').attr('title').should.eql('Place Kitten'); }); - it('class + src + width + height + title + alt', function(){ + it('class + src + width + height + title + alt', function() { var $ = cheerio.load(img('left http://placekitten.com/200/300 200 300 "Place Kitten" "A cute kitten"'.split(' '))); $('img').attr('src').should.eql('http://placekitten.com/200/300'); @@ -100,4 +100,4 @@ describe('img', function(){ $('img').attr('title').should.eql('Place Kitten'); $('img').attr('alt').should.eql('A cute kitten'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/include_code.js b/test/scripts/tags/include_code.js index c6b05e7ad7..bd36abd6c2 100644 --- a/test/scripts/tags/include_code.js +++ b/test/scripts/tags/include_code.js @@ -1,12 +1,12 @@ 'use strict'; var pathFn = require('path'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var highlight = require('hexo-util').highlight; var Promise = require('bluebird'); -describe('include_code', function(){ +describe('include_code', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'include_code_test')); var includeCode = Promise.method(require('../../../lib/plugins/tag/include_code')(hexo)); @@ -18,63 +18,63 @@ describe('include_code', function(){ '}' ].join('\n'); - function code(args){ + function code(args) { return includeCode(args.split(' ')); } - before(function(){ + before(function() { return fs.writeFile(path, fixture); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('default', function(){ + it('default', function() { var expected = highlight(fixture, { lang: 'js', caption: 'test.jsview raw' }); - return code('test.js').then(function(result){ + return code('test.js').then(function(result) { result.should.eql(expected); }); }); - it('title', function(){ + it('title', function() { var expected = highlight(fixture, { lang: 'js', caption: 'Hello worldview raw' }); - return code('Hello world test.js').then(function(result){ + return code('Hello world test.js').then(function(result) { result.should.eql(expected); }); }); - it('lang', function(){ + it('lang', function() { var expected = highlight(fixture, { lang: 'js', caption: 'Hello worldview raw' }); - return code('Hello world lang:js test.js').then(function(result){ + return code('Hello world lang:js test.js').then(function(result) { result.should.eql(expected); }); }); - it('file not found', function(){ - return code('nothing').then(function(result){ + it('file not found', function() { + return code('nothing').then(function(result) { should.not.exist(result); }); }); - it('disabled', function(){ + it('disabled', function() { hexo.config.highlight.enable = false; - return code('test.js').then(function(result){ + return code('test.js').then(function(result) { result.should.eql('123456 bold and italic
\n
' + fixture + '
');
hexo.config.highlight.enable = true;
});
});
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/index.js b/test/scripts/tags/index.js
index c4b74f7f01..e5e96f5efc 100644
--- a/test/scripts/tags/index.js
+++ b/test/scripts/tags/index.js
@@ -1,6 +1,6 @@
'use strict';
-describe('Tags', function(){
+describe('Tags', function() {
require('./asset_img');
require('./asset_link');
require('./asset_path');
@@ -17,4 +17,4 @@ describe('Tags', function(){
require('./pullquote');
require('./vimeo');
require('./youtube');
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/jsfiddle.js b/test/scripts/tags/jsfiddle.js
index eff7caf6da..8ba42b2962 100644
--- a/test/scripts/tags/jsfiddle.js
+++ b/test/scripts/tags/jsfiddle.js
@@ -1,18 +1,18 @@
'use strict';
var cheerio = require('cheerio');
-var should = require('chai').should();
+var should = require('chai').should(); // eslint-disable-line
-describe('jsfiddle', function(){
+describe('jsfiddle', function() {
var jsfiddle = require('../../../lib/plugins/tag/jsfiddle');
- it('id', function(){
+ it('id', function() {
var $ = cheerio.load(jsfiddle(['foo']));
$('iframe').attr('src').should.eql('http://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
});
- it('tabs', function(){
+ it('tabs', function() {
var $ = cheerio.load(jsfiddle(['foo', 'default']));
$('iframe').attr('src').should.eql('http://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
@@ -22,7 +22,7 @@ describe('jsfiddle', function(){
$('iframe').attr('src').should.eql('http://jsfiddle.net/foo/embedded/html,css/light');
});
- it('skin', function(){
+ it('skin', function() {
var $ = cheerio.load(jsfiddle(['foo', 'default', 'default']));
$('iframe').attr('src').should.eql('http://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
@@ -32,7 +32,7 @@ describe('jsfiddle', function(){
$('iframe').attr('src').should.eql('http://jsfiddle.net/foo/embedded/js,resources,html,css,result/dark');
});
- it('width', function(){
+ it('width', function() {
var $ = cheerio.load(jsfiddle(['foo', 'default', 'default', 'default']));
$('iframe').attr('width').should.eql('100%');
@@ -42,7 +42,7 @@ describe('jsfiddle', function(){
$('iframe').attr('width').should.eql('500');
});
- it('height', function(){
+ it('height', function() {
var $ = cheerio.load(jsfiddle(['foo', 'default', 'default', 'default', 'default']));
$('iframe').attr('height').should.eql('300');
@@ -51,4 +51,4 @@ describe('jsfiddle', function(){
$('iframe').attr('height').should.eql('500');
});
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/link.js b/test/scripts/tags/link.js
index f34f33128a..d2c4ac8d8e 100644
--- a/test/scripts/tags/link.js
+++ b/test/scripts/tags/link.js
@@ -1,19 +1,19 @@
'use strict';
var cheerio = require('cheerio');
-var should = require('chai').should();
+var should = require('chai').should(); // eslint-disable-line
-describe('link', function(){
+describe('link', function() {
var link = require('../../../lib/plugins/tag/link');
- it('text + url', function(){
+ it('text + url', function() {
var $ = cheerio.load(link('Click here to Google http://google.com'.split(' ')));
$('a').attr('href').should.eql('http://google.com');
$('a').html().should.eql('Click here to Google');
});
- it('text + url + external', function(){
+ it('text + url + external', function() {
var $ = cheerio.load(link('Click here to Google http://google.com true'.split(' ')));
$('a').attr('href').should.eql('http://google.com');
@@ -27,7 +27,7 @@ describe('link', function(){
should.not.exist($('a').attr('target'));
});
- it('text + url + title', function(){
+ it('text + url + title', function() {
var $ = cheerio.load(link('Click here to Google http://google.com Google link'.split(' ')));
$('a').attr('href').should.eql('http://google.com');
@@ -35,7 +35,7 @@ describe('link', function(){
$('a').attr('title').should.eql('Google link');
});
- it('text + url + external + title', function(){
+ it('text + url + external + title', function() {
var $ = cheerio.load(link('Click here to Google http://google.com true Google link'.split(' ')));
$('a').attr('href').should.eql('http://google.com');
@@ -50,4 +50,4 @@ describe('link', function(){
should.not.exist($('a').attr('target'));
$('a').attr('title').should.eql('Google link');
});
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/post_link.js b/test/scripts/tags/post_link.js
index 0b5b4ebcfc..bd56f9f734 100644
--- a/test/scripts/tags/post_link.js
+++ b/test/scripts/tags/post_link.js
@@ -1,8 +1,8 @@
'use strict';
-var should = require('chai').should();
+var should = require('chai').should(); // eslint-disable-line
-describe('post_link', function(){
+describe('post_link', function() {
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo(__dirname);
var postLink = require('../../../lib/plugins/tag/post_link')(hexo);
@@ -10,8 +10,8 @@ describe('post_link', function(){
hexo.config.permalink = ':title/';
- before(function(){
- return hexo.init().then(function(){
+ before(function() {
+ return hexo.init().then(function() {
return Post.insert({
source: 'foo',
slug: 'foo',
@@ -20,19 +20,19 @@ describe('post_link', function(){
});
});
- it('default', function(){
+ it('default', function() {
postLink(['foo']).should.eql('Hello world');
});
- it('title', function(){
+ it('title', function() {
postLink(['foo', 'test']).should.eql('test');
});
- it('no slug', function(){
+ it('no slug', function() {
should.not.exist(postLink([]));
});
- it('post not found', function(){
+ it('post not found', function() {
should.not.exist(postLink(['bar']));
});
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/post_path.js b/test/scripts/tags/post_path.js
index 36c1f0d730..77acf65887 100644
--- a/test/scripts/tags/post_path.js
+++ b/test/scripts/tags/post_path.js
@@ -1,8 +1,8 @@
'use strict';
-var should = require('chai').should();
+var should = require('chai').should(); // eslint-disable-line
-describe('post_path', function(){
+describe('post_path', function() {
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo(__dirname);
var postPath = require('../../../lib/plugins/tag/post_path')(hexo);
@@ -10,8 +10,8 @@ describe('post_path', function(){
hexo.config.permalink = ':title/';
- before(function(){
- return hexo.init().then(function(){
+ before(function() {
+ return hexo.init().then(function() {
return Post.insert({
source: 'foo',
slug: 'foo'
@@ -19,15 +19,15 @@ describe('post_path', function(){
});
});
- it('default', function(){
+ it('default', function() {
postPath(['foo']).should.eql('/foo/');
});
- it('no slug', function(){
+ it('no slug', function() {
should.not.exist(postPath([]));
});
- it('post not found', function(){
+ it('post not found', function() {
should.not.exist(postPath(['bar']));
});
-});
\ No newline at end of file
+});
diff --git a/test/scripts/tags/pullquote.js b/test/scripts/tags/pullquote.js
index ca1c64d3db..834a8dcca4 100644
--- a/test/scripts/tags/pullquote.js
+++ b/test/scripts/tags/pullquote.js
@@ -1,25 +1,25 @@
'use strict';
-var should = require('chai').should();
+var should = require('chai').should(); // eslint-disable-line
-describe('pullquote', function(){
+describe('pullquote', function() {
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo(__dirname);
var pullquote = require('../../../lib/plugins/tag/pullquote')(hexo);
- before(function(){
- return hexo.init().then(function(){
+ before(function() {
+ return hexo.init().then(function() {
return hexo.loadPlugin(require.resolve('hexo-renderer-marked'));
});
});
- it('default', function(){
+ it('default', function() {
var result = pullquote([], '123456 **bold** and *italic*');
result.should.eql(''); }); - it('class', function(){ + it('class', function() { var result = pullquote(['foo', 'bar'], ''); result.should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/vimeo.js b/test/scripts/tags/vimeo.js index 82ab098f56..136101bd28 100644 --- a/test/scripts/tags/vimeo.js +++ b/test/scripts/tags/vimeo.js @@ -1,12 +1,12 @@ 'use strict'; var cheerio = require('cheerio'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('vimeo', function(){ +describe('vimeo', function() { var vimeo = require('../../../lib/plugins/tag/vimeo'); - it('id', function(){ + it('id', function() { var $ = cheerio.load(vimeo(['foo'])); $('.video-container').html().should.be.ok; @@ -14,4 +14,4 @@ describe('vimeo', function(){ $('iframe').attr('frameborder').should.eql('0'); $('iframe').attr('allowfullscreen').should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/youtube.js b/test/scripts/tags/youtube.js index 3fb715560b..e83f18d287 100644 --- a/test/scripts/tags/youtube.js +++ b/test/scripts/tags/youtube.js @@ -1,12 +1,12 @@ 'use strict'; var cheerio = require('cheerio'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('youtube', function(){ +describe('youtube', function() { var youtube = require('../../../lib/plugins/tag/youtube'); - it('id', function(){ + it('id', function() { var $ = cheerio.load(youtube(['foo'])); $('.video-container').html().should.be.ok; @@ -14,4 +14,4 @@ describe('youtube', function(){ $('iframe').attr('frameborder').should.eql('0'); $('iframe').attr('allowfullscreen').should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme/index.js b/test/scripts/theme/index.js index 71774fec50..083f927ae8 100644 --- a/test/scripts/theme/index.js +++ b/test/scripts/theme/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Theme', function(){ +describe('Theme', function() { require('./theme'); require('./view'); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme/theme.js b/test/scripts/theme/theme.js index a237afbede..001800906c 100644 --- a/test/scripts/theme/theme.js +++ b/test/scripts/theme/theme.js @@ -1,29 +1,29 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('Theme', function(){ +describe('Theme', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'theme_test'), {silent: true}); var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('getView()', function(){ + it('getView()', function() { hexo.theme.setView('test.swig', ''); // With extension name @@ -38,7 +38,7 @@ describe('Theme', function(){ hexo.theme.removeView('test.swig'); }); - it('getView() - escape backslashes', function(){ + it('getView() - escape backslashes', function() { hexo.theme.setView('foo/bar.swig', ''); hexo.theme.getView('foo\\bar.swig').should.have.property('path', 'foo/bar.swig'); @@ -46,7 +46,7 @@ describe('Theme', function(){ hexo.theme.removeView('foo/bar.swig'); }); - it('setView()', function(){ + it('setView()', function() { hexo.theme.setView('test.swig', ''); var view = hexo.theme.getView('test.swig'); @@ -55,10 +55,10 @@ describe('Theme', function(){ hexo.theme.removeView('test.swig'); }); - it('removeView()', function(){ + it('removeView()', function() { hexo.theme.setView('test.swig', ''); hexo.theme.removeView('test.swig'); should.not.exist(hexo.theme.getView('test.swig')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme/view.js b/test/scripts/theme/view.js index 9a7aa2ed9c..601e32ad04 100644 --- a/test/scripts/theme/view.js +++ b/test/scripts/theme/view.js @@ -1,29 +1,29 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); var moment = require('moment'); -describe('View', function(){ +describe('View', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'theme_test')); var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); hexo.env.init = true; - function newView(path, data){ + function newView(path, data) { return new hexo.theme.View(path, data); } - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); - }).then(function(){ + }).then(function() { // Setup layout hexo.theme.setView('layout.swig', [ 'pre', @@ -33,11 +33,11 @@ describe('View', function(){ }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('constructor', function(){ + it('constructor', function() { var view = newView('index.swig', {}); view.path.should.eql('index.swig'); @@ -45,7 +45,7 @@ describe('View', function(){ view.data.should.eql({}); }); - it('parse front-matter', function(){ + it('parse front-matter', function() { var body = [ 'layout: false', '---', @@ -60,7 +60,7 @@ describe('View', function(){ }); }); - it('render()', function(){ + it('render()', function() { var body = [ '{{ test }}' ].join('\n'); @@ -69,12 +69,12 @@ describe('View', function(){ return view.render({ test: 'foo' - }).then(function(content){ + }).then(function(content) { content.should.eql('foo'); }); }); - it('render() - front-matter', function(){ + it('render() - front-matter', function() { // The priority of front-matter is higher var body = [ 'foo: bar', @@ -88,12 +88,12 @@ describe('View', function(){ return view.render({ foo: 'foo', test: 'test' - }).then(function(content){ + }).then(function(content) { content.should.eql('bar\ntest'); }); }); - it('render() - helper', function(){ + it('render() - helper', function() { var body = [ '{{ date() }}' ].join('\n'); @@ -103,34 +103,34 @@ describe('View', function(){ return view.render({ config: hexo.config, page: {} - }).then(function(content){ + }).then(function(content) { content.should.eql(moment().format(hexo.config.date_format)); }); }); - it('render() - layout', function(){ + it('render() - layout', function() { var body = 'content'; var view = newView('index.swig', body); return view.render({ layout: 'layout' - }).then(function(content){ + }).then(function(content) { content.should.eql('pre\n' + body + '\npost'); }); }); - it('render() - layout not found', function(){ + it('render() - layout not found', function() { var body = 'content'; var view = newView('index.swig', body); return view.render({ layout: 'wtf' - }).then(function(content){ + }).then(function(content) { content.should.eql(body); }); }); - it('render() - callback', function(callback){ + it('render() - callback', function(callback) { var body = [ '{{ test }}' ].join('\n'); @@ -139,14 +139,14 @@ describe('View', function(){ view.render({ test: 'foo' - }, function(err, content){ + }, function(err, content) { should.not.exist(err); content.should.eql('foo'); callback(); }); }); - it('render() - callback (without options)', function(callback){ + it('render() - callback (without options)', function(callback) { var body = [ 'test: foo', '---', @@ -155,14 +155,14 @@ describe('View', function(){ var view = newView('index.swig', body); - view.render(function(err, content){ + view.render(function(err, content) { should.not.exist(err); content.should.eql('foo'); callback(); }); }); - it('renderSync()', function(){ + it('renderSync()', function() { var body = [ '{{ test }}' ].join('\n'); @@ -171,7 +171,7 @@ describe('View', function(){ view.renderSync({test: 'foo'}).should.eql('foo'); }); - it('renderSync() - front-matter', function(){ + it('renderSync() - front-matter', function() { // The priority of front-matter is higher var body = [ 'foo: bar', @@ -188,7 +188,7 @@ describe('View', function(){ }).should.eql('bar\ntest'); }); - it('renderSync() - helper', function(){ + it('renderSync() - helper', function() { var body = [ '{{ date() }}' ].join('\n'); @@ -201,7 +201,7 @@ describe('View', function(){ }).should.eql(moment().format(hexo.config.date_format)); }); - it('renderSync() - layout', function(){ + it('renderSync() - layout', function() { var body = 'content'; var view = newView('index.swig', body); @@ -210,7 +210,7 @@ describe('View', function(){ }).should.eql('pre\n' + body + '\npost'); }); - it('renderSync() - layout not found', function(){ + it('renderSync() - layout not found', function() { var body = 'content'; var view = newView('index.swig', body); @@ -219,7 +219,7 @@ describe('View', function(){ }).should.eql(body); }); - it('_resolveLayout()', function(){ + it('_resolveLayout()', function() { var view = newView('partials/header.swig', 'header'); // Relative path @@ -231,4 +231,4 @@ describe('View', function(){ // Can't be itself should.not.exist(view._resolveLayout('header')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme_processors/config.js b/test/scripts/theme_processors/config.js index bcf5e3094b..e26dd9aff1 100644 --- a/test/scripts/theme_processors/config.js +++ b/test/scripts/theme_processors/config.js @@ -1,37 +1,37 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('config', function(){ +describe('config', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); var processor = require('../../../lib/theme/processors/config'); var process = Promise.method(processor.process.bind(hexo)); var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); - function newFile(options){ + function newFile(options) { options.source = pathFn.join(themeDir, options.path); return new hexo.theme.File(options); } - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('pattern', function(){ + it('pattern', function() { var pattern = processor.pattern; pattern.match('_config.yml').should.be.ok; @@ -40,7 +40,7 @@ describe('config', function(){ should.not.exist(pattern.match('foo.yml')); }); - it('type: create', function(){ + it('type: create', function() { var body = [ 'name:', ' first: John', @@ -53,7 +53,7 @@ describe('config', function(){ content: body }); - return process(file).then(function(){ + return process(file).then(function() { hexo.theme.config.should.eql({ name: {first: 'John', last: 'Doe'} }); @@ -62,7 +62,7 @@ describe('config', function(){ }); }); - it('type: delete', function(){ + it('type: delete', function() { var file = newFile({ path: '_config.yml', type: 'delete' @@ -70,14 +70,12 @@ describe('config', function(){ hexo.theme.config = {foo: 'bar'}; - return process(file).then(function(){ + return process(file).then(function() { hexo.theme.config.should.eql({}); }); }); - it('load failed', function(){ - var body = 'foo:bar'; - + it('load failed', function() { var file = newFile({ path: '_config.yml', type: 'create' @@ -89,6 +87,6 @@ describe('config', function(){ return process(file).catch(errorCallback).finally(function() { errorCallback.calledOnce.should.be.true; - }).catch(function(){}); // Catch again because it throws error + }).catch(function() {}); // Catch again because it throws error }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme_processors/i18n.js b/test/scripts/theme_processors/i18n.js index 52529fe096..07189ae4d9 100644 --- a/test/scripts/theme_processors/i18n.js +++ b/test/scripts/theme_processors/i18n.js @@ -1,18 +1,18 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('i18n', function(){ +describe('i18n', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); var processor = require('../../../lib/theme/processors/i18n'); var process = Promise.method(processor.process.bind(hexo)); var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); - function newFile(options){ + function newFile(options) { var path = options.path; options.params = { @@ -25,20 +25,20 @@ describe('i18n', function(){ return new hexo.theme.File(options); } - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('pattern', function(){ + it('pattern', function() { var pattern = processor.pattern; pattern.match('languages/default.yml').should.be.ok; @@ -46,7 +46,7 @@ describe('i18n', function(){ should.not.exist(pattern.match('default.yml')); }); - it('type: create', function(){ + it('type: create', function() { var body = [ 'ok: OK', 'index:', @@ -59,7 +59,7 @@ describe('i18n', function(){ content: body }); - return process(file).then(function(){ + return process(file).then(function() { var __ = hexo.theme.i18n.__('en'); __('ok').should.eql('OK'); @@ -67,7 +67,7 @@ describe('i18n', function(){ }); }); - it('type: delete', function(){ + it('type: delete', function() { hexo.theme.i18n.set('en', { foo: 'foo', bar: 'bar' @@ -78,8 +78,8 @@ describe('i18n', function(){ type: 'delete' }); - return process(file).then(function(){ + return process(file).then(function() { hexo.theme.i18n.get('en').should.eql({}); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme_processors/index.js b/test/scripts/theme_processors/index.js index 18e25cebfe..738352885c 100644 --- a/test/scripts/theme_processors/index.js +++ b/test/scripts/theme_processors/index.js @@ -1,8 +1,8 @@ 'use strict'; -describe('Theme processors', function(){ +describe('Theme processors', function() { require('./config'); require('./i18n'); require('./source'); require('./view'); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme_processors/source.js b/test/scripts/theme_processors/source.js index a405eda313..fb7b62edd2 100644 --- a/test/scripts/theme_processors/source.js +++ b/test/scripts/theme_processors/source.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('source', function(){ +describe('source', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'source_test'), {silent: true}); var processor = require('../../../lib/theme/processors/source'); @@ -13,7 +13,7 @@ describe('source', function(){ var themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); var Asset = hexo.model('Asset'); - function newFile(options){ + function newFile(options) { var path = options.path; options.params = {path: path}; @@ -23,20 +23,20 @@ describe('source', function(){ return new hexo.theme.File(options); } - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('pattern', function(){ + it('pattern', function() { var pattern = processor.pattern; pattern.match('source/foo.jpg').should.eql({path: 'foo.jpg'}); @@ -48,13 +48,13 @@ describe('source', function(){ pattern.match('package.json').should.be.false; }); - it('type: create', function(){ + it('type: create', function() { var file = newFile({ path: 'style.css', type: 'create' }); - return process(file).then(function(){ + return process(file).then(function() { var id = 'themes/test/' + file.path; var asset = Asset.findById(id); @@ -66,7 +66,7 @@ describe('source', function(){ }); }); - it('type: update', function(){ + it('type: update', function() { var file = newFile({ path: 'style.css', type: 'update' @@ -78,9 +78,9 @@ describe('source', function(){ _id: id, path: file.params.path, modified: false - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { var asset = Asset.findById(id); asset.modified.should.be.true; @@ -89,7 +89,7 @@ describe('source', function(){ }); }); - it('type: skip', function(){ + it('type: skip', function() { var file = newFile({ path: 'style.css', type: 'skip' @@ -101,9 +101,9 @@ describe('source', function(){ _id: id, path: file.params.path, modified: true - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { var asset = Asset.findById(id); asset.modified.should.be.false; @@ -112,7 +112,7 @@ describe('source', function(){ }); }); - it('type: delete', function(){ + it('type: delete', function() { var file = newFile({ path: 'style.css', type: 'delete' @@ -123,10 +123,10 @@ describe('source', function(){ return Asset.insert({ _id: id, path: file.params.path - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { should.not.exist(Asset.findById(id)); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/theme_processors/view.js b/test/scripts/theme_processors/view.js index 663139fd8e..8ff53bd653 100644 --- a/test/scripts/theme_processors/view.js +++ b/test/scripts/theme_processors/view.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('view', function(){ +describe('view', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'view_test'), {silent: true}); var processor = require('../../../lib/theme/processors/view'); @@ -14,7 +14,7 @@ describe('view', function(){ hexo.env.init = true; - function newFile(options){ + function newFile(options) { var path = options.path; options.params = {path: path}; @@ -24,20 +24,20 @@ describe('view', function(){ return new hexo.theme.File(options); } - before(function(){ + before(function() { return Promise.all([ fs.mkdirs(themeDir), fs.writeFile(hexo.config_path, 'theme: test') - ]).then(function(){ + ]).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('pattern', function(){ + it('pattern', function() { var pattern = processor.pattern; pattern.match('layout/index.swig').path.should.eql('index.swig'); @@ -45,7 +45,7 @@ describe('view', function(){ should.not.exist(pattern.match('view/index.swig')); }); - it('type: create', function(){ + it('type: create', function() { var body = [ 'foo: bar', '---', @@ -58,7 +58,7 @@ describe('view', function(){ content: new Buffer(body) }); - return process(file).then(function(){ + return process(file).then(function() { var view = hexo.theme.getView('index.swig'); view.path.should.eql('index.swig'); @@ -72,14 +72,14 @@ describe('view', function(){ }); }); - it('type: delete', function(){ + it('type: delete', function() { var file = newFile({ path: 'index.swig', type: 'delete' }); - return process(file).then(function(){ + return process(file).then(function() { should.not.exist(hexo.theme.getView('index.swig')); }); }); -}); \ No newline at end of file +}); diff --git a/test/util/index.js b/test/util/index.js index 7ceab788d4..1d03088e3e 100644 --- a/test/util/index.js +++ b/test/util/index.js @@ -1 +1,3 @@ -exports.stream = require('./stream'); \ No newline at end of file +'use strict'; + +exports.stream = require('./stream'); diff --git a/test/util/stream.js b/test/util/stream.js index f5ee7ecfd7..a0098437ee 100644 --- a/test/util/stream.js +++ b/test/util/stream.js @@ -1,15 +1,17 @@ +'use strict'; + var Promise = require('bluebird'); -function readStream(stream){ - return new Promise(function(resolve, reject){ - var data = []; +function readStream(stream) { + return new Promise(function(resolve, reject) { + var data = ''; - stream.on('data', function(chunk){ - data.push(chunk); - }).on('end', function(){ - resolve(Buffer.concat(data).toString()); + stream.on('data', function(chunk) { + data += chunk.toString(); + }).on('end', function() { + resolve(data); }).on('error', reject); }); } -exports.read = readStream; \ No newline at end of file +exports.read = readStream;123456 bold and italic
\n