From f01a9aa3db9dc5b52d056c7467186fa5f33c5857 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Wed, 23 Sep 2015 23:58:48 +0800 Subject: [PATCH] Use ESLint and JSCS instead of JSHint. Fix tests failed on Node.js 4 --- .eslintignore | 3 + .eslintrc | 45 ++++ .jscsrc | 85 +++++++ .jshintrc | 14 -- .npmignore | 1 - .travis.yml | 13 +- appveyor.yml | 17 +- gulpfile.js | 48 ---- lib/box/file.js | 28 +-- lib/box/index.js | 136 ++++++------ lib/box/shasum_stream.js | 10 +- lib/extend/console.js | 22 +- lib/extend/deployer.js | 12 +- lib/extend/filter.js | 32 +-- lib/extend/generator.js | 14 +- lib/extend/helper.js | 10 +- lib/extend/index.js | 2 +- lib/extend/migrator.js | 12 +- lib/extend/processor.js | 14 +- lib/extend/renderer.js | 20 +- lib/extend/tag.js | 62 +++--- lib/hexo/create_logger.js | 22 +- lib/hexo/default_config.js | 2 +- lib/hexo/index.js | 114 +++++----- lib/hexo/load_config.js | 18 +- lib/hexo/load_database.js | 10 +- lib/hexo/load_plugins.js | 32 +-- lib/hexo/locals.js | 22 +- lib/hexo/post.js | 82 +++---- lib/hexo/register_models.js | 6 +- lib/hexo/render.js | 44 ++-- lib/hexo/router.js | 50 +++-- lib/hexo/scaffold.js | 34 +-- lib/hexo/source.js | 4 +- lib/hexo/update_package.js | 12 +- lib/models/asset.js | 6 +- lib/models/cache.js | 4 +- lib/models/category.js | 24 +- lib/models/data.js | 4 +- lib/models/index.js | 2 +- lib/models/page.js | 8 +- lib/models/post.js | 52 ++--- lib/models/post_asset.js | 8 +- lib/models/post_category.js | 4 +- lib/models/post_tag.js | 4 +- lib/models/tag.js | 22 +- lib/models/types/cachestring.js | 6 +- lib/models/types/moment.js | 48 ++-- lib/plugins/console/clean.js | 17 +- lib/plugins/console/config.js | 25 +-- lib/plugins/console/deploy.js | 23 +- lib/plugins/console/generate.js | 65 +++--- lib/plugins/console/help.js | 25 ++- lib/plugins/console/index.js | 4 +- lib/plugins/console/init.js | 2 +- lib/plugins/console/list/common.js | 8 +- lib/plugins/console/list/index.js | 9 +- lib/plugins/console/list/page.js | 9 +- lib/plugins/console/list/post.js | 9 +- lib/plugins/console/list/route.js | 17 +- lib/plugins/console/list/tag.js | 9 +- lib/plugins/console/migrate.js | 9 +- lib/plugins/console/new.js | 11 +- lib/plugins/console/publish.js | 9 +- lib/plugins/console/render.js | 13 +- lib/plugins/console/version.js | 6 +- .../filter/after_post_render/excerpt.js | 8 +- .../filter/after_post_render/external_link.js | 7 +- lib/plugins/filter/after_post_render/index.js | 4 +- lib/plugins/filter/before_exit/index.js | 4 +- .../filter/before_exit/save_database.js | 7 +- lib/plugins/filter/before_generate/index.js | 4 +- .../filter/before_generate/render_post.js | 11 +- .../before_post_render/backtick_code_block.js | 15 +- .../filter/before_post_render/index.js | 4 +- .../filter/before_post_render/titlecase.js | 5 +- lib/plugins/filter/index.js | 4 +- lib/plugins/filter/new_post_path.js | 21 +- lib/plugins/filter/post_permalink.js | 11 +- lib/plugins/filter/template_locals/i18n.js | 13 +- lib/plugins/filter/template_locals/index.js | 4 +- lib/plugins/generator/asset.js | 23 +- lib/plugins/generator/index.js | 4 +- lib/plugins/generator/page.js | 37 ++-- lib/plugins/generator/post.js | 34 +-- lib/plugins/helper/css.js | 9 +- lib/plugins/helper/date.js | 30 ++- lib/plugins/helper/debug.js | 4 +- lib/plugins/helper/favicon_tag.js | 5 +- lib/plugins/helper/feed_tag.js | 5 +- lib/plugins/helper/format.js | 4 +- lib/plugins/helper/fragment_cache.js | 6 +- lib/plugins/helper/gravatar.js | 8 +- lib/plugins/helper/image_tag.js | 9 +- lib/plugins/helper/index.js | 2 +- lib/plugins/helper/is.js | 55 ++--- lib/plugins/helper/js.js | 9 +- lib/plugins/helper/link_to.js | 11 +- lib/plugins/helper/list_archives.js | 25 +-- lib/plugins/helper/list_categories.js | 33 ++- lib/plugins/helper/list_posts.js | 13 +- lib/plugins/helper/list_tags.js | 19 +- lib/plugins/helper/mail_to.js | 12 +- lib/plugins/helper/markdown.js | 5 +- lib/plugins/helper/number_format.js | 19 +- lib/plugins/helper/open_graph.js | 35 ++- lib/plugins/helper/paginator.js | 35 ++- lib/plugins/helper/partial.js | 18 +- lib/plugins/helper/relative_url.js | 10 +- lib/plugins/helper/render.js | 6 +- lib/plugins/helper/search_form.js | 5 +- lib/plugins/helper/tagcloud.js | 71 +++--- lib/plugins/helper/toc.js | 20 +- lib/plugins/helper/url_for.js | 7 +- lib/plugins/processor/asset.js | 68 +++--- lib/plugins/processor/common.js | 14 +- lib/plugins/processor/data.js | 29 ++- lib/plugins/processor/index.js | 6 +- lib/plugins/processor/post.js | 113 +++++----- lib/plugins/renderer/index.js | 4 +- lib/plugins/renderer/json.js | 4 +- lib/plugins/renderer/plain.js | 4 +- lib/plugins/renderer/swig.js | 4 +- lib/plugins/renderer/yaml.js | 4 +- lib/plugins/tag/asset_img.js | 4 +- lib/plugins/tag/asset_link.js | 6 +- lib/plugins/tag/asset_path.js | 6 +- lib/plugins/tag/blockquote.js | 20 +- lib/plugins/tag/code.js | 18 +- lib/plugins/tag/gist.js | 4 +- lib/plugins/tag/iframe.js | 4 +- lib/plugins/tag/img.js | 20 +- lib/plugins/tag/include_code.js | 18 +- lib/plugins/tag/index.js | 4 +- lib/plugins/tag/jsfiddle.js | 4 +- lib/plugins/tag/link.js | 14 +- lib/plugins/tag/post_link.js | 6 +- lib/plugins/tag/post_path.js | 6 +- lib/plugins/tag/pullquote.js | 6 +- lib/plugins/tag/vimeo.js | 4 +- lib/plugins/tag/youtube.js | 4 +- lib/theme/index.js | 24 +- lib/theme/processors/config.js | 10 +- lib/theme/processors/i18n.js | 8 +- lib/theme/processors/source.js | 26 +-- lib/theme/processors/view.js | 8 +- lib/theme/view.js | 24 +- package.json | 23 +- test/.eslintrc | 9 + test/.jshintrc | 15 -- test/fixtures/post_render.js | 2 +- test/index.js | 4 +- test/mocha.opts | 1 + test/scripts/box/box.js | 159 +++++++------ test/scripts/box/file.js | 94 ++++---- test/scripts/box/index.js | 4 +- test/scripts/console/clean.js | 22 +- test/scripts/console/config.js | 54 ++--- test/scripts/console/deploy.js | 46 ++-- test/scripts/console/generate.js | 94 ++++---- test/scripts/console/help.js | 16 +- test/scripts/console/index.js | 4 +- test/scripts/console/migrate.js | 12 +- test/scripts/console/new.js | 64 +++--- test/scripts/console/publish.js | 48 ++-- test/scripts/console/render.js | 52 ++--- test/scripts/extend/console.js | 46 ++-- test/scripts/extend/deployer.js | 37 ++-- test/scripts/extend/filter.js | 115 +++++----- test/scripts/extend/generator.js | 32 +-- test/scripts/extend/helper.js | 25 ++- test/scripts/extend/index.js | 4 +- test/scripts/extend/migrator.js | 37 ++-- test/scripts/extend/processor.js | 22 +- test/scripts/extend/renderer.js | 63 +++--- test/scripts/extend/tag.js | 62 +++--- test/scripts/filters/backtick_code_block.js | 34 +-- test/scripts/filters/excerpt.js | 14 +- test/scripts/filters/external_link.js | 10 +- test/scripts/filters/i18n_locals.js | 18 +- test/scripts/filters/index.js | 4 +- test/scripts/filters/new_post_path.js | 78 +++---- test/scripts/filters/post_permalink.js | 34 +-- test/scripts/filters/render_post.js | 22 +- test/scripts/filters/save_database.js | 18 +- test/scripts/filters/titlecase.js | 10 +- test/scripts/generators/asset.js | 48 ++-- test/scripts/generators/index.js | 4 +- test/scripts/generators/page.js | 44 ++-- test/scripts/generators/post.js | 36 +-- test/scripts/helpers/css.js | 20 +- test/scripts/helpers/date.js | 24 +- test/scripts/helpers/debug.js | 18 +- test/scripts/helpers/favicon_tag.js | 8 +- test/scripts/helpers/feed_tag.js | 12 +- test/scripts/helpers/fragment_cache.js | 14 +- test/scripts/helpers/gravatar.js | 14 +- test/scripts/helpers/image_tag.js | 14 +- test/scripts/helpers/index.js | 2 +- test/scripts/helpers/is.js | 22 +- test/scripts/helpers/js.js | 20 +- test/scripts/helpers/link_to.js | 20 +- test/scripts/helpers/list_archives.js | 36 +-- test/scripts/helpers/list_categories.js | 38 ++-- test/scripts/helpers/list_posts.js | 32 +-- test/scripts/helpers/list_tags.js | 36 +-- test/scripts/helpers/mail_to.js | 28 +-- test/scripts/helpers/markdown.js | 12 +- test/scripts/helpers/number_format.js | 14 +- test/scripts/helpers/open_graph.js | 70 +++--- test/scripts/helpers/paginator.js | 60 ++--- test/scripts/helpers/partial.js | 28 +-- test/scripts/helpers/relative_url.js | 14 +- test/scripts/helpers/render.js | 10 +- test/scripts/helpers/search_form.js | 16 +- test/scripts/helpers/tagcloud.js | 40 ++-- test/scripts/helpers/toc.js | 18 +- test/scripts/helpers/url_for.js | 14 +- test/scripts/hexo/hexo.js | 190 ++++++++-------- test/scripts/hexo/index.js | 6 +- test/scripts/hexo/load_config.js | 74 +++---- test/scripts/hexo/load_database.js | 40 ++-- test/scripts/hexo/load_plugins.js | 50 ++--- test/scripts/hexo/locals.js | 34 +-- test/scripts/hexo/post.js | 209 +++++++++--------- test/scripts/hexo/render.js | 96 ++++---- test/scripts/hexo/router.js | 102 ++++----- test/scripts/hexo/scaffold.js | 40 ++-- test/scripts/hexo/update_package.js | 38 ++-- test/scripts/models/asset.js | 18 +- test/scripts/models/cache.js | 8 +- test/scripts/models/cachestring.js | 8 +- test/scripts/models/category.js | 100 ++++----- test/scripts/models/index.js | 4 +- test/scripts/models/moment.js | 40 ++-- test/scripts/models/page.js | 22 +- test/scripts/models/post.js | 133 +++++------ test/scripts/models/post_asset.js | 32 +-- test/scripts/models/tag.js | 87 ++++---- test/scripts/processors/asset.js | 114 +++++----- test/scripts/processors/common.js | 14 +- test/scripts/processors/data.js | 40 ++-- test/scripts/processors/index.js | 4 +- test/scripts/processors/post.js | 208 ++++++++--------- test/scripts/renderers/index.js | 4 +- test/scripts/renderers/json.js | 8 +- test/scripts/renderers/plain.js | 8 +- test/scripts/renderers/swig.js | 13 +- test/scripts/renderers/yaml.js | 10 +- test/scripts/tags/asset_img.js | 20 +- test/scripts/tags/asset_link.js | 22 +- test/scripts/tags/asset_path.js | 20 +- test/scripts/tags/blockquote.js | 24 +- test/scripts/tags/code.js | 22 +- test/scripts/tags/gist.js | 10 +- test/scripts/tags/iframe.js | 12 +- test/scripts/tags/img.js | 30 +-- test/scripts/tags/include_code.js | 32 +-- test/scripts/tags/index.js | 4 +- test/scripts/tags/jsfiddle.js | 16 +- test/scripts/tags/link.js | 14 +- test/scripts/tags/post_link.js | 18 +- test/scripts/tags/post_path.js | 16 +- test/scripts/tags/pullquote.js | 14 +- test/scripts/tags/vimeo.js | 8 +- test/scripts/tags/youtube.js | 8 +- test/scripts/theme/index.js | 4 +- test/scripts/theme/theme.js | 20 +- test/scripts/theme/view.js | 60 ++--- test/scripts/theme_processors/config.js | 30 ++- test/scripts/theme_processors/i18n.js | 24 +- test/scripts/theme_processors/index.js | 4 +- test/scripts/theme_processors/source.js | 38 ++-- test/scripts/theme_processors/view.js | 24 +- test/util/index.js | 4 +- test/util/stream.js | 18 +- 276 files changed, 3623 insertions(+), 3563 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .jscsrc delete mode 100644 .jshintrc delete mode 100644 gulpfile.js create mode 100644 test/.eslintrc delete mode 100644 test/.jshintrc create mode 100644 test/mocha.opts 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 += ''; } else { - for (i = 0, len = data.length; i < len; i++){ + for (i = 0, len = data.length; i < len; i++) { item = data[i]; if (i) result += separator; @@ -95,7 +94,7 @@ function listArchivesHelper(options){ result += ''; result += transform ? transform(item.name) : item.name; - if (showCount){ + if (showCount) { result += '' + item.count + ''; } @@ -106,4 +105,4 @@ function listArchivesHelper(options){ return result; } -module.exports = listArchivesHelper; \ No newline at end of file +module.exports = listArchivesHelper; diff --git a/lib/plugins/helper/list_categories.js b/lib/plugins/helper/list_categories.js index b6bbfa6670..a4351b9e78 100644 --- a/lib/plugins/helper/list_categories.js +++ b/lib/plugins/helper/list_categories.js @@ -1,8 +1,7 @@ 'use strict'; -function listCategoriesHelper(categories, options){ - /* jshint validthis: true */ - if (!options && (!categories || !categories.hasOwnProperty('length'))){ +function listCategoriesHelper(categories, options) { + if (!options && (!categories || !categories.hasOwnProperty('length'))) { options = categories; categories = this.site.categories; } @@ -23,26 +22,26 @@ function listCategoriesHelper(categories, options){ var result = ''; var self = this; - function prepareQuery(parent){ + function prepareQuery(parent) { var query = {}; - if (parent){ + if (parent) { query.parent = parent; } else { query.parent = {$exists: false}; } - return categories.find(query).sort(orderby, order).filter(function(cat){ + return categories.find(query).sort(orderby, order).filter(function(cat) { return cat.length; }); } - function hierarchicalList(level, parent){ + function hierarchicalList(level, parent) { var result = ''; - prepareQuery(parent).forEach(function(cat, i){ + prepareQuery(parent).forEach(function(cat, i) { var child; - if (!depth || level + 1 < depth){ + if (!depth || level + 1 < depth) { child = hierarchicalList(level + 1, cat._id); } @@ -65,7 +64,7 @@ function listCategoriesHelper(categories, options){ } var additionalClassName = ''; - if (child && childrenIndicator){ + if (child && childrenIndicator) { additionalClassName = ' ' + childrenIndicator; } @@ -75,11 +74,11 @@ function listCategoriesHelper(categories, options){ result += transform ? transform(cat.name) : cat.name; result += ''; - if (showCount){ + if (showCount) { result += '' + cat.length + ''; } - if (child){ + if (child) { result += ''; } @@ -89,22 +88,22 @@ function listCategoriesHelper(categories, options){ return result; } - function flatList(level, parent){ + function flatList(level, parent) { var result = ''; - prepareQuery(parent).forEach(function(cat, i){ + prepareQuery(parent).forEach(function(cat, i) { if (i || level) result += separator; result += ''; result += transform ? transform(cat.name) : cat.name; - if (showCount){ + if (showCount) { result += '' + cat.length + ''; } result += ''; - if (!depth || level + 1 < depth){ + if (!depth || level + 1 < depth) { result += flatList(level + 1, cat._id); } }); @@ -112,7 +111,7 @@ function listCategoriesHelper(categories, options){ return result; } - if (style === 'list'){ + if (style === 'list') { result += ''; } else { result += flatList(0); diff --git a/lib/plugins/helper/list_posts.js b/lib/plugins/helper/list_posts.js index 00971a5708..8dd6b35673 100644 --- a/lib/plugins/helper/list_posts.js +++ b/lib/plugins/helper/list_posts.js @@ -1,8 +1,7 @@ 'use strict'; -function listPostsHelper(posts, options){ - /* jshint validthis: true */ - if (!options && (!posts || !posts.hasOwnProperty('length'))){ +function listPostsHelper(posts, options) { + if (!options && (!posts || !posts.hasOwnProperty('length'))) { options = posts; posts = this.site.posts; } @@ -25,10 +24,10 @@ function listPostsHelper(posts, options){ // Limit the number of posts if (amount) posts = posts.limit(amount); - if (style === 'list'){ + if (style === 'list') { result += ''; } else { - posts.forEach(function(post, i){ + posts.forEach(function(post, i) { if (i) result += separator; var title = post.title || post.slug; @@ -56,4 +55,4 @@ function listPostsHelper(posts, options){ return result; } -module.exports = listPostsHelper; \ No newline at end of file +module.exports = listPostsHelper; diff --git a/lib/plugins/helper/list_tags.js b/lib/plugins/helper/list_tags.js index 3fb70376be..37f0a26ed1 100644 --- a/lib/plugins/helper/list_tags.js +++ b/lib/plugins/helper/list_tags.js @@ -1,8 +1,7 @@ 'use strict'; -function listTagsHelper(tags, options){ - /* jshint validthis: true */ - if (!options && (!tags || !tags.hasOwnProperty('length'))){ +function listTagsHelper(tags, options) { + if (!options && (!tags || !tags.hasOwnProperty('length'))) { options = tags; tags = this.site.tags; } @@ -24,24 +23,24 @@ function listTagsHelper(tags, options){ tags = tags.sort(orderby, order); // Ignore tags with zero posts - tags = tags.filter(function(tag){ + tags = tags.filter(function(tag) { return tag.length; }); // Limit the number of tags if (options.amount) tags = tags.limit(options.amount); - if (style === 'list'){ + if (style === 'list') { result += ''; } else { - tags.forEach(function(tag, i){ + tags.forEach(function(tag, i) { if (i) result += separator; result += ''; result += transform ? transform(tag.name) : tag.name; - if (showCount){ + if (showCount) { result += '' + tag.length + ''; } @@ -67,4 +66,4 @@ function listTagsHelper(tags, options){ return result; } -module.exports = listTagsHelper; \ No newline at end of file +module.exports = listTagsHelper; diff --git a/lib/plugins/helper/mail_to.js b/lib/plugins/helper/mail_to.js index 0241b13a65..52315abaa9 100644 --- a/lib/plugins/helper/mail_to.js +++ b/lib/plugins/helper/mail_to.js @@ -3,7 +3,7 @@ var htmlTag = require('hexo-util').htmlTag; var qs = require('querystring'); -function mailToHelper(path, text, options){ +function mailToHelper(path, text, options) { options = options || {}; if (Array.isArray(path)) path = path.join(','); @@ -17,21 +17,21 @@ function mailToHelper(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.class && Array.isArray(attrs.class)){ + if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } var data = {}; - ['subject', 'cc', 'bcc', 'body'].forEach(function(i){ + ['subject', 'cc', 'bcc', 'body'].forEach(function(i) { var item = attrs[i]; - if (item){ + if (item) { data[i] = Array.isArray(item) ? item.join(',') : item; attrs[i] = null; } @@ -43,4 +43,4 @@ function mailToHelper(path, text, options){ return htmlTag('a', attrs, text); } -module.exports = mailToHelper; \ No newline at end of file +module.exports = mailToHelper; diff --git a/lib/plugins/helper/markdown.js b/lib/plugins/helper/markdown.js index d37d7423b5..7df352843d 100644 --- a/lib/plugins/helper/markdown.js +++ b/lib/plugins/helper/markdown.js @@ -1,8 +1,7 @@ 'use strict'; -function markdownHelper(text, options){ - /* jshint validthis: true */ +function markdownHelper(text, options) { return this.render(text, 'markdown', options); } -module.exports = markdownHelper; \ No newline at end of file +module.exports = markdownHelper; diff --git a/lib/plugins/helper/number_format.js b/lib/plugins/helper/number_format.js index 57ee40bcf7..de0ed9fb45 100644 --- a/lib/plugins/helper/number_format.js +++ b/lib/plugins/helper/number_format.js @@ -1,7 +1,6 @@ 'use strict'; -function numberFormatHelper(num, options){ - /* jshint validthis: true */ +function numberFormatHelper(num, options) { options = options || {}; var split = num.toString().split('.'); @@ -12,42 +11,42 @@ function numberFormatHelper(num, options){ var precision = options.precision; var i, len; - if (delimiter){ + if (delimiter) { var beforeArr = []; var beforeLength = before.length; var beforeFirst = beforeLength % 3; if (beforeFirst) beforeArr.push(before.substr(0, beforeFirst)); - for (i = beforeFirst; i < beforeLength; i += 3){ + for (i = beforeFirst; i < beforeLength; i += 3) { beforeArr.push(before.substr(i, 3)); } before = beforeArr.join(delimiter); } - if (precision){ + if (precision) { var afterLength = after.length; var afterResult = ''; - if (afterLength > precision){ + if (afterLength > precision) { var afterLast = after[precision]; - var last = parseInt(after[precision - 1]); + var last = parseInt(after[precision - 1], 10); afterResult = after.substr(0, precision - 1) + (afterLast < 5 ? last : last + 1); } else { afterResult = after; - for (i = 0, len = precision - afterLength; i < len; i++){ + for (i = 0, len = precision - afterLength; i < len; i++) { afterResult += '0'; } } after = afterResult; - } else if (precision === 0 || precision === '0'){ + } else if (precision === 0 || precision === '0') { after = ''; } return before + (after ? separator + after : ''); } -module.exports = numberFormatHelper; \ No newline at end of file +module.exports = numberFormatHelper; diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js index d5c5401cd2..bd5be9bbc2 100644 --- a/lib/plugins/helper/open_graph.js +++ b/lib/plugins/helper/open_graph.js @@ -7,22 +7,21 @@ var htmlTag = util.htmlTag; var stripHTML = util.stripHTML; var cheerio; -function meta(name, content){ +function meta(name, content) { return htmlTag('meta', { name: name, content: content }) + '\n'; } -function og(name, content){ +function og(name, content) { return htmlTag('meta', { property: name, content: content }) + '\n'; } -function openGraphHelper(options){ - /* jshint validthis: true */ +function openGraphHelper(options) { options = options || {}; if (!cheerio) cheerio = require('cheerio'); @@ -42,7 +41,7 @@ function openGraphHelper(options){ if (!Array.isArray(images)) images = [images]; - if (description){ + if (description) { description = stripHTML(description).substring(0, 200) .replace(/^\s+|\s+$/g, '') // Remove prefixing/trailing spaces .replace(/'; - function link(i){ + function link(i) { return self.url_for(i === 1 ? base : base + format.replace('%d', i)); } - function pageLink(i){ + function pageLink(i) { return '' + (transform ? transform(i) : i) + ''; } // Display the link to the previous page - if (prevNext && current > 1){ + if (prevNext && current > 1) { result += ''; } - if (options.show_all){ + if (options.show_all) { // Display pages on the left side of the current page - for (i = 1; i < current; i++){ + for (i = 1; i < current; i++) { result += pageLink(i); } @@ -50,7 +49,7 @@ function paginatorHelper(options){ result += currentPage; // Display pages on the right side of the current page - for (i = current + 1; i <= total; i++){ + for (i = current + 1; i <= total; i++) { result += pageLink(i); } } else { @@ -62,18 +61,18 @@ function paginatorHelper(options){ var spaceHtml = '' + space + ''; // Display pages on the left edge - for (i = 1; i <= leftEnd; i++){ + for (i = 1; i <= leftEnd; i++) { result += pageLink(i); } // Display spaces between edges and middle pages - if (space && current - endSize - midSize > 1){ + if (space && current - endSize - midSize > 1) { result += spaceHtml; } // Display left middle pages - if (leftMid > leftEnd){ - for (i = leftMid; i < current; i++){ + if (leftMid > leftEnd) { + for (i = leftMid; i < current; i++) { result += pageLink(i); } } @@ -82,29 +81,29 @@ function paginatorHelper(options){ result += currentPage; // Display right middle pages - if (rightMid < rightEnd){ - for (i = current + 1; i <= rightMid; i++){ + if (rightMid < rightEnd) { + for (i = current + 1; i <= rightMid; i++) { result += pageLink(i); } } // Display spaces between edges and middle pages - if (space && total - endSize - midSize > current){ + if (space && total - endSize - midSize > current) { result += spaceHtml; } // Dispaly pages on the right edge - for (i = rightEnd; i <= total; i++){ + for (i = rightEnd; i <= total; i++) { result += pageLink(i); } } // Display the link to the next page - if (prevNext && current < total){ + if (prevNext && current < total) { result += ''; } return result; } -module.exports = paginatorHelper; \ No newline at end of file +module.exports = paginatorHelper; diff --git a/lib/plugins/helper/partial.js b/lib/plugins/helper/partial.js index ade3610d82..ceddb1be72 100644 --- a/lib/plugins/helper/partial.js +++ b/lib/plugins/helper/partial.js @@ -4,8 +4,8 @@ var pathFn = require('path'); var _ = require('lodash'); var chalk = require('chalk'); -module.exports = function(ctx){ - return function partial(name, locals, options){ +module.exports = function(ctx) { + return function partial(name, locals, options) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); options = options || {}; @@ -18,12 +18,12 @@ module.exports = function(ctx){ var view = ctx.theme.getView(path) || ctx.theme.getView(name); var viewLocals = {}; - if (!view){ + if (!view) { ctx.log.warn('Partial %s does not exist. %s', chalk.magenta(name), chalk.gray('(in ' + currentView + ')')); return ''; } - if (only){ + if (only) { _.extend(viewLocals, locals); } else { _.extend(viewLocals, this, locals); @@ -32,14 +32,14 @@ module.exports = function(ctx){ // Partial don't need layout viewLocals.layout = false; - if (cache){ + if (cache) { var cacheId = typeof cache === 'string' ? cache : view.path; - return this.fragment_cache(cacheId, function(){ + return this.fragment_cache(cacheId, function() { return view.renderSync(viewLocals); }); - } else { - return view.renderSync(viewLocals); } + + return view.renderSync(viewLocals); }; -}; \ No newline at end of file +}; diff --git a/lib/plugins/helper/relative_url.js b/lib/plugins/helper/relative_url.js index 1c71da79b1..8f85847dd8 100644 --- a/lib/plugins/helper/relative_url.js +++ b/lib/plugins/helper/relative_url.js @@ -1,6 +1,6 @@ 'use strict'; -function relativeUrlHelper(from, to){ +function relativeUrlHelper(from, to) { from = from || ''; to = to || ''; @@ -9,18 +9,20 @@ function relativeUrlHelper(from, to){ var length = Math.min(fromParts.length, toParts.length); var i = 0; - for (; i < length && fromParts[i] === toParts[i]; i++); + for (; i < length; i++) { + if (fromParts[i] !== toParts[i]) break; + } var out = toParts.slice(i); - for (var j = fromParts.length - i - 1; j > 0; j--){ + for (var j = fromParts.length - i - 1; j > 0; j--) { out.unshift('..'); } var outLength = out.length; // If the last 2 elements of `out` is empty strings, replace them with `index.html`. - if (outLength > 1 && !out[outLength - 1] && !out[outLength] - 2){ + if (outLength > 1 && !out[outLength - 1] && !out[outLength] - 2) { out = out.slice(0, outLength - 2).concat('index.html'); } diff --git a/lib/plugins/helper/render.js b/lib/plugins/helper/render.js index f17cab5d38..8a9257e457 100644 --- a/lib/plugins/helper/render.js +++ b/lib/plugins/helper/render.js @@ -1,10 +1,10 @@ 'use strict'; -module.exports = function(ctx){ - return function render(text, engine, options){ +module.exports = function(ctx) { + return function render(text, engine, options) { return ctx.render.renderSync({ text: text, engine: engine }, options); }; -}; \ No newline at end of file +}; diff --git a/lib/plugins/helper/search_form.js b/lib/plugins/helper/search_form.js index a0ce916d5f..f3a69f5eb1 100644 --- a/lib/plugins/helper/search_form.js +++ b/lib/plugins/helper/search_form.js @@ -1,7 +1,6 @@ 'use strict'; -function searchFormHelper(options){ - /* jshint validthis: true */ +function searchFormHelper(options) { options = options || {}; var config = this.config; @@ -16,4 +15,4 @@ function searchFormHelper(options){ ''; } -module.exports = searchFormHelper; \ No newline at end of file +module.exports = searchFormHelper; diff --git a/lib/plugins/helper/tagcloud.js b/lib/plugins/helper/tagcloud.js index df141edf5a..8c3567cf7b 100644 --- a/lib/plugins/helper/tagcloud.js +++ b/lib/plugins/helper/tagcloud.js @@ -157,9 +157,8 @@ var colorNames = { yellowgreen: {r: 154, g: 205, b: 50, a: 1} }; -function tagcloudHelper(tags, options){ - /* jshint validthis: true */ - if (!options && (!tags || !tags.hasOwnProperty('length'))){ +function tagcloudHelper(tags, options) { + if (!options && (!tags || !tags.hasOwnProperty('length'))) { options = tags; tags = this.site.tags; } @@ -179,7 +178,7 @@ function tagcloudHelper(tags, options){ var self = this; var startColor, endColor; - if (color){ + if (color) { startColor = new Color(options.start_color); endColor = new Color(options.end_color); @@ -187,25 +186,25 @@ function tagcloudHelper(tags, options){ } // Sort the tags - if (orderby === 'random' || orderby === 'rand'){ + if (orderby === 'random' || orderby === 'rand') { tags = tags.random(); } else { tags = tags.sort(orderby, order); } // Ignore tags with zero posts - tags = tags.filter(function(tag){ + tags = tags.filter(function(tag) { return tag.length; }); // Limit the number of tags - if (options.amount){ + if (options.amount) { tags = tags.limit(options.amount); } var sizes = []; - tags.sort('length').forEach(function(tag){ + tags.sort('length').forEach(function(tag) { var length = tag.length; if (~sizes.indexOf(length)) return; @@ -214,12 +213,12 @@ function tagcloudHelper(tags, options){ var length = sizes.length - 1; - tags.forEach(function(tag){ - var ratio = length? (sizes.indexOf(tag.length) / length): 0; + tags.forEach(function(tag) { + var ratio = length ? (sizes.indexOf(tag.length) / length) : 0; var size = min + (max - min) * ratio; var style = 'font-size: ' + parseFloat(size.toFixed(2)) + unit + ';'; - if (color){ + if (color) { var midColor = startColor.mix(endColor, ratio); style += ' color: ' + midColor.toString(); } @@ -234,13 +233,13 @@ function tagcloudHelper(tags, options){ return result.join(separator); } -function Color(color){ - if (typeof color === 'object'){ +function Color(color) { + if (typeof color === 'object') { this.r = color.r; this.g = color.g; this.b = color.b; this.a = color.a; - } else if (typeof color === 'string'){ + } else if (typeof color === 'string') { this.parse(color); } else { throw new TypeError('color is required!'); @@ -249,15 +248,15 @@ function Color(color){ if (this.r < 0 || this.r > 255 || this.g < 0 || this.g > 255 || this.b < 0 || this.b > 255 || - this.a < 0 || this.a > 1){ + this.a < 0 || this.a > 1) { throw new Error(color + ' is invalid.'); } } -Color.prototype.parse = function(color){ +Color.prototype.parse = function(color) { color = color.toLowerCase(); - if (colorNames.hasOwnProperty(color)){ + if (colorNames.hasOwnProperty(color)) { var obj = colorNames[color]; this.r = obj.r; @@ -270,7 +269,7 @@ Color.prototype.parse = function(color){ var match, txt, code; - if (rHex3.test(color)){ + if (rHex3.test(color)) { txt = color.substring(1); code = parseInt(txt, 16); @@ -278,7 +277,7 @@ Color.prototype.parse = function(color){ this.g = ((code & 0xF0) >> 4) * 17; this.b = (code & 0xF) * 17; this.a = 1; - } else if (rHex6.test(color)){ + } else if (rHex6.test(color)) { txt = color.substring(1); code = parseInt(txt, 16); @@ -286,14 +285,14 @@ Color.prototype.parse = function(color){ this.g = (code & 0xFF00) >> 8; this.b = code & 0xFF; this.a = 1; - } else if (rRGB.test(color)){ + } else if (rRGB.test(color)) { match = color.match(rRGB); this.r = match[1] | 0; this.g = match[2] | 0; this.b = match[3] | 0; this.a = match[4] ? +match[4] : 1; - } else if (rHSL.test(color)){ + } else if (rHSL.test(color)) { match = color.match(rHSL); var h = +match[1] / 360; @@ -302,7 +301,7 @@ Color.prototype.parse = function(color){ this.a = match[4] ? +match[4] : 1; - if (!s){ + if (!s) { this.r = this.g = this.b = l * 255; } @@ -321,23 +320,23 @@ Color.prototype.parse = function(color){ } }; -Color.prototype.toString = function(){ - if (this.a === 1){ +Color.prototype.toString = function() { + if (this.a === 1) { var r = convertRGB(this.r); var g = convertRGB(this.g); var b = convertRGB(this.b); - if (this.r % 17 || this.g % 17 || this.b % 17){ + if (this.r % 17 || this.g % 17 || this.b % 17) { return '#' + r + g + b; - } else { - return '#' + r[0] + g[0] + b[0]; } - } else { - return 'rgba(' + this.r + ', ' + this.g + ', ' + this.b + ', ' + parseFloat(this.a.toFixed(2)) + ')'; + + return '#' + r[0] + g[0] + b[0]; } + + return 'rgba(' + this.r + ', ' + this.g + ', ' + this.b + ', ' + parseFloat(this.a.toFixed(2)) + ')'; }; -Color.prototype.mix = function(color, ratio){ +Color.prototype.mix = function(color, ratio) { switch (ratio){ case 0: return new Color(this); @@ -354,17 +353,17 @@ Color.prototype.mix = function(color, ratio){ }); }; -function convertHue(p, q, h){ +function convertHue(p, q, h) { if (h < 0) h++; if (h > 1) h--; var color; - if (h * 6 < 1){ + if (h * 6 < 1) { color = p + (q - p) * h * 6; - } else if (h * 2 < 1){ + } else if (h * 2 < 1) { color = q; - } else if (h * 3 < 2){ + } else if (h * 3 < 2) { color = p + (q - p) * ((2 / 3) - h) * 6; } else { color = p; @@ -373,14 +372,14 @@ function convertHue(p, q, h){ return Math.round(color * 255); } -function convertRGB(value){ +function convertRGB(value) { var str = value.toString(16); if (value < 16) return '0' + str; return str; } -function mixValue(a, b, ratio){ +function mixValue(a, b, ratio) { return a + (b - a) * ratio; } diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index 2b3a2c54a9..b0be2c6485 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -2,7 +2,7 @@ var cheerio; -function tocHelper(str, options){ +function tocHelper(str, options) { options = options || {}; if (!cheerio) cheerio = require('cheerio'); @@ -20,23 +20,23 @@ function tocHelper(str, options){ var lastLevel = 0; var i = 0; - headings.each(function(){ + headings.each(function() { var level = +this.name[1]; var id = $(this).attr('id'); var text = $(this).text(); lastNumber[level - 1]++; - for (i = level; i <= 5; i++){ + for (i = level; i <= 5; i++) { lastNumber[i] = 0; } - if (firstLevel){ - for (i = level; i < lastLevel; i++){ + if (firstLevel) { + for (i = level; i < lastLevel; i++) { result += ''; } - if (level > lastLevel){ + if (level > lastLevel) { result += '
    '; } else { result += ''; @@ -48,10 +48,10 @@ function tocHelper(str, options){ result += '
  1. '; result += ''; - if (listNumber){ + if (listNumber) { result += ''; - for (i = firstLevel - 1; i < level; i++){ + for (i = firstLevel - 1; i < level; i++) { result += lastNumber[i] + '.'; } @@ -63,11 +63,11 @@ function tocHelper(str, options){ lastLevel = level; }); - for (i = firstLevel - 1; i < lastLevel; i++){ + for (i = firstLevel - 1; i < lastLevel; i++) { result += '
'; } return result; } -module.exports = tocHelper; \ No newline at end of file +module.exports = tocHelper; diff --git a/lib/plugins/helper/url_for.js b/lib/plugins/helper/url_for.js index 7a9aba73cd..7c925047c3 100644 --- a/lib/plugins/helper/url_for.js +++ b/lib/plugins/helper/url_for.js @@ -3,8 +3,7 @@ var url = require('url'); var _ = require('lodash'); -function urlForHelper(path, options){ - /* jshint validthis: true */ +function urlForHelper(path, options) { path = path || '/'; var config = this.config; @@ -16,12 +15,12 @@ function urlForHelper(path, options){ }, options); // Exit if this is an external path - if (data.protocol || path.substring(0, 2) === '//'){ + if (data.protocol || path.substring(0, 2) === '//') { return path; } // Resolve relative url - if (options.relative){ + if (options.relative) { return this.relative_url(this.path, path); } diff --git a/lib/plugins/processor/asset.js b/lib/plugins/processor/asset.js index 99f9f0e091..bacec5f6ad 100644 --- a/lib/plugins/processor/asset.js +++ b/lib/plugins/processor/asset.js @@ -5,18 +5,18 @@ var Promise = require('bluebird'); var yfm = require('hexo-front-matter'); var pathFn = require('path'); -exports.process = function(file){ - if (this.render.isRenderable(file.path)){ +exports.process = function(file) { + if (this.render.isRenderable(file.path)) { return processPage.call(this, file); - } else { - return processAsset.call(this, file); } + + return processAsset.call(this, file); }; exports.pattern = common.ignoreTmpAndHiddenFile; -function processPage(file){ - /* jshint validthis: true */ +function processPage(file) { + var Page = this.model('Page'); var path = file.path; var doc = Page.findOne({source: path}); @@ -24,22 +24,22 @@ function processPage(file){ var config = this.config; var timezone = config.timezone; - if (file.type === 'skip' && doc){ + if (file.type === 'skip' && doc) { return; } - if (file.type === 'delete'){ - if (doc){ + if (file.type === 'delete') { + if (doc) { return doc.remove(); - } else { - return; } + + return; } return Promise.all([ file.stat(), file.read() - ]).spread(function(stats, content){ + ]).spread(function(stats, content) { var data = yfm(content); var output = self.render.getOutput(path); @@ -48,7 +48,7 @@ function processPage(file){ data.date = common.toDate(data.date); - if (data.date){ + if (data.date) { if (timezone) data.date = common.timezone(data.date, timezone); } else { data.date = stats.ctime; @@ -56,21 +56,21 @@ function processPage(file){ data.updated = common.toDate(data.updated); - if (data.updated){ + if (data.updated) { if (timezone) data.updated = common.timezone(data.updated, timezone); } else { data.updated = stats.mtime; } - if (data.permalink){ + if (data.permalink) { data.path = data.permalink; delete data.permalink; - if (data.path[data.path.length - 1] === '/'){ + if (data.path[data.path.length - 1] === '/') { data.path += 'index'; } - if (!pathFn.extname(data.path)){ + if (!pathFn.extname(data.path)) { data.path += '.' + output; } } else { @@ -78,41 +78,41 @@ function processPage(file){ data.path = path.substring(0, path.length - extname.length) + '.' + output; } - if (!data.layout && output !== 'html' && output !== 'htm'){ + if (!data.layout && output !== 'html' && output !== 'htm') { data.layout = false; } - if (doc){ + if (doc) { return doc.replace(data); - } else { - return Page.insert(data); } + + return Page.insert(data); }); } -function processAsset(file){ - /* jshint validthis: true */ +function processAsset(file) { + var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/'); var Asset = this.model('Asset'); 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 = file.path; doc.modified = file.type !== 'skip'; return doc.save(); - } else { - return Asset.insert({ - _id: id, - path: file.path - }); } -} \ No newline at end of file + + return Asset.insert({ + _id: id, + path: file.path + }); +} diff --git a/lib/plugins/processor/common.js b/lib/plugins/processor/common.js index c20c64888b..64eeb582dc 100644 --- a/lib/plugins/processor/common.js +++ b/lib/plugins/processor/common.js @@ -5,17 +5,17 @@ var moment = require('moment-timezone'); var DURATION_MINUTE = 1000 * 60; -function isTmpFile(path){ +function isTmpFile(path) { var last = path[path.length - 1]; return last === '%' || last === '~'; } -function isHiddenFile(path){ +function isHiddenFile(path) { if (path[0] === '_') return true; return /\/_/.test(path); } -exports.ignoreTmpAndHiddenFile = new Pattern(function(path){ +exports.ignoreTmpAndHiddenFile = new Pattern(function(path) { if (isTmpFile(path) || isHiddenFile(path)) return false; return true; }); @@ -23,10 +23,10 @@ exports.ignoreTmpAndHiddenFile = new Pattern(function(path){ exports.isTmpFile = isTmpFile; exports.isHiddenFile = isHiddenFile; -exports.toDate = function(date){ +exports.toDate = function(date) { if (!date || moment.isMoment(date)) return date; - if (!(date instanceof Date)){ + if (!(date instanceof Date)) { date = new Date(date); } @@ -35,7 +35,7 @@ exports.toDate = function(date){ return date; }; -exports.timezone = function(date, timezone){ +exports.timezone = function(date, timezone) { if (moment.isMoment(date)) date = date.toDate(); var offset = date.getTimezoneOffset(); @@ -44,4 +44,4 @@ exports.timezone = function(date, timezone){ var diff = (offset - target) * DURATION_MINUTE; return new Date(ms - diff); -}; \ No newline at end of file +}; diff --git a/lib/plugins/processor/data.js b/lib/plugins/processor/data.js index b6d167e611..58d2176d2e 100644 --- a/lib/plugins/processor/data.js +++ b/lib/plugins/processor/data.js @@ -4,7 +4,7 @@ var util = require('hexo-util'); var pathFn = require('path'); var Pattern = util.Pattern; -exports.process = function(file){ +exports.process = function(file) { if (this.render.getOutput(file.path) !== 'json') return; var Data = this.model('Data'); @@ -13,32 +13,31 @@ exports.process = function(file){ var id = path.substring(0, path.length - extname.length); var doc = Data.findById(id); - if (file.type === 'skip' && doc){ + if (file.type === 'skip' && doc) { return; } - if (file.type === 'delete'){ - if (doc){ + if (file.type === 'delete') { + if (doc) { return doc.remove(); - } else { - return; } + + return; } - return file.render().then(function(result){ + return file.render().then(function(result) { if (typeof result !== 'object') return; - if (doc){ + if (doc) { doc.data = result; - return doc.save(); - } else { - return Data.insert({ - _id: id, - data: result - }); } + + return Data.insert({ + _id: id, + data: result + }); }); }; -exports.pattern = new Pattern('_data/*path'); \ No newline at end of file +exports.pattern = new Pattern('_data/*path'); diff --git a/lib/plugins/processor/index.js b/lib/plugins/processor/index.js index 2c71126af7..7b42c77462 100644 --- a/lib/plugins/processor/index.js +++ b/lib/plugins/processor/index.js @@ -1,9 +1,9 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var processor = ctx.extend.processor; - function register(name){ + function register(name) { var obj = require('./' + name); processor.register(obj.pattern, obj.process); } @@ -11,4 +11,4 @@ module.exports = function(ctx){ register('asset'); register('data'); register('post'); -}; \ No newline at end of file +}; diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index 712b8ddfec..7987df24e6 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -23,29 +23,29 @@ var preservedKeys = { i_day: true }; -function startsWith(str, prefix){ +function startsWith(str, prefix) { return str.substring(0, prefix.length) === prefix; } -exports.process = function(file){ - if (this.render.isRenderable(file.path)){ +exports.process = function(file) { + if (this.render.isRenderable(file.path)) { return processPost.call(this, file); - } else if (this.config.post_asset_folder){ + } else if (this.config.post_asset_folder) { return processAsset.call(this, file); } }; -exports.pattern = new Pattern(function(path){ +exports.pattern = new Pattern(function(path) { if (common.isTmpFile(path)) return false; var result; - if (startsWith(path, postDir)){ + if (startsWith(path, postDir)) { result = { published: true, path: path.substring(postDir.length) }; - } else if (startsWith(path, draftDir)){ + } else if (startsWith(path, draftDir)) { result = { published: false, path: path.substring(draftDir.length) @@ -58,8 +58,7 @@ exports.pattern = new Pattern(function(path){ return result; }); -function processPost(file){ - /* jshint validthis: true */ +function processPost(file) { var Post = this.model('Post'); var path = file.params.path; var doc = Post.findOne({source: file.path}); @@ -68,22 +67,22 @@ function processPost(file){ var timezone = config.timezone; var categories, tags; - if (file.type === 'skip' && doc){ + if (file.type === 'skip' && doc) { return; } - if (file.type === 'delete'){ - if (doc){ + if (file.type === 'delete') { + if (doc) { return doc.remove(); - } else { - return; } + + return; } return Promise.all([ file.stat(), file.read() - ]).spread(function(stats, content){ + ]).spread(function(stats, content) { var data = yfm(content); var info = parseFilename(config.new_post_name, path); var keys = Object.keys(info); @@ -93,20 +92,20 @@ function processPost(file){ data.raw = content; data.slug = info.title; - if (file.params.published){ + if (file.params.published) { if (!data.hasOwnProperty('published')) data.published = true; } else { data.published = false; } - 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]) data[key] = info[key]; } - if (data.date){ + if (data.date) { data.date = common.toDate(data.date); - } else if (info && info.year && (info.month || info.i_month) && (info.day || info.i_day)){ + } else if (info && info.year && (info.month || info.i_month) && (info.day || info.i_day)) { data.date = new Date( info.year, parseInt(info.month || info.i_month, 10) - 1, @@ -114,7 +113,7 @@ function processPost(file){ ); } - if (data.date){ + if (data.date) { if (timezone) data.date = common.timezone(data.date, timezone); } else { data.date = stats.ctime; @@ -122,18 +121,18 @@ function processPost(file){ data.updated = common.toDate(data.updated); - if (data.updated){ + if (data.updated) { if (timezone) data.updated = common.timezone(data.updated, timezone); } else { data.updated = stats.mtime; } - if (data.category && !data.categories){ + if (data.category && !data.categories) { data.categories = data.category; delete data.category; } - if (data.tag && !data.tags){ + if (data.tag && !data.tags) { data.tags = data.tag; delete data.tag; } @@ -144,30 +143,30 @@ function processPost(file){ if (!Array.isArray(categories)) categories = [categories]; if (!Array.isArray(tags)) tags = [tags]; - if (data.photo && !data.photos){ + if (data.photo && !data.photos) { data.photos = data.photo; delete data.photo; } - if (data.photos && !Array.isArray(data.photos)){ + if (data.photos && !Array.isArray(data.photos)) { data.photos = [data.photos]; } - if (data.link && !data.title){ + if (data.link && !data.title) { data.title = data.link.replace(/^https?:\/\/|\/$/g, ''); } - if (data.permalink){ + if (data.permalink) { data.slug = data.permalink; delete data.permalink; } - if (doc){ + if (doc) { return doc.replace(data); - } else { - return Post.insert(data); } - }).then(function(doc){ + + return Post.insert(data); + }).then(function(doc) { return Promise.all([ doc.setCategories(categories), doc.setTags(tags), @@ -176,11 +175,11 @@ function processPost(file){ }); } -function parseFilename(config, path){ +function parseFilename(config, path) { config = config.substring(0, config.length - pathFn.extname(config).length); path = path.substring(0, path.length - pathFn.extname(path).length); - if (!permalink || permalink.rule !== config){ + if (!permalink || permalink.rule !== config) { permalink = new Permalink(config, { segments: { year: /(\d{4})/, @@ -194,17 +193,17 @@ function parseFilename(config, path){ var data = permalink.parse(path); - if (data){ + if (data) { return data; - } else { - return { - title: slugize(path) - }; } + + return { + title: slugize(path) + }; } -function scanAssetDir(post){ - /* jshint validthis: true */ +function scanAssetDir(post) { + if (!this.config.post_asset_folder) return; var assetDir = post.asset_dir; @@ -212,11 +211,11 @@ function scanAssetDir(post){ var baseDirLength = baseDir.length; var PostAsset = this.model('PostAsset'); - return fs.exists(assetDir).then(function(exist){ + return fs.exists(assetDir).then(function(exist) { return exist ? fs.listDir(assetDir) : []; - }).filter(function(item){ + }).filter(function(item) { return !common.isTmpFile(item) && !common.isHiddenFile(item); - }).map(function(item){ + }).map(function(item) { var id = pathFn.join(assetDir, item).substring(baseDirLength).replace(/\\/g, '/'); var asset = PostAsset.findById(id); if (asset) return; @@ -230,43 +229,43 @@ function scanAssetDir(post){ }); } -function processAsset(file){ - /* jshint validthis: true */ +function processAsset(file) { + var PostAsset = this.model('PostAsset'); var Post = this.model('Post'); var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/'); var doc = PostAsset.findById(id); var post; - if (file.type === 'skip' && doc){ + if (file.type === 'skip' && doc) { return; } - if (file.type === 'delete'){ - if (doc){ + if (file.type === 'delete') { + if (doc) { return doc.remove(); - } else { - return; } + + return; } - if (doc){ + if (doc) { post = Post.findById(doc.post); - if (post){ + if (post) { doc.modified = file.type !== 'skip'; return doc.save(); - } else { - return doc.remove(); } + + return doc.remove(); } var posts = Post.toArray(); - for (var i = 0, len = posts.length; i < len; i++){ + for (var i = 0, len = posts.length; i < len; i++) { post = posts[i]; - if (startsWith(file.source, post.asset_dir)){ + if (startsWith(file.source, post.asset_dir)) { return PostAsset.insert({ _id: id, slug: file.source.substring(post.asset_dir.length), @@ -274,4 +273,4 @@ function processAsset(file){ }); } } -} \ No newline at end of file +} diff --git a/lib/plugins/renderer/index.js b/lib/plugins/renderer/index.js index d44614b9d9..fc40b06768 100644 --- a/lib/plugins/renderer/index.js +++ b/lib/plugins/renderer/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(ctx){ +module.exports = function(ctx) { var renderer = ctx.extend.renderer; var plain = require('./plain'); @@ -18,4 +18,4 @@ module.exports = function(ctx){ renderer.register('yml', 'json', yaml, true); renderer.register('yaml', 'json', yaml, true); -}; \ No newline at end of file +}; diff --git a/lib/plugins/renderer/json.js b/lib/plugins/renderer/json.js index db850c9820..8dbe42cacc 100644 --- a/lib/plugins/renderer/json.js +++ b/lib/plugins/renderer/json.js @@ -1,7 +1,7 @@ 'use strict'; -function jsonRenderer(data){ +function jsonRenderer(data) { return JSON.parse(data.text); } -module.exports = jsonRenderer; \ No newline at end of file +module.exports = jsonRenderer; diff --git a/lib/plugins/renderer/plain.js b/lib/plugins/renderer/plain.js index 16d5cfb422..4b436b763a 100644 --- a/lib/plugins/renderer/plain.js +++ b/lib/plugins/renderer/plain.js @@ -1,7 +1,7 @@ 'use strict'; -function planRenderer(data){ +function planRenderer(data) { return data.text; } -module.exports = planRenderer; \ No newline at end of file +module.exports = planRenderer; diff --git a/lib/plugins/renderer/swig.js b/lib/plugins/renderer/swig.js index 0c472625fe..a4c13d53ad 100644 --- a/lib/plugins/renderer/swig.js +++ b/lib/plugins/renderer/swig.js @@ -23,7 +23,7 @@ swig.setDefaults({ }); // Hack: Override for tag of Swig -swig.setTag('for', forTag.parse, function(compiler, args, content, parents, options, blockName){ +swig.setTag('for', forTag.parse, function(compiler, args, content, parents, options, blockName) { var compile = forTag.compile.apply(this, arguments).split('\n'); compile.splice(3, 0, ' if (!Array.isArray(__l) && typeof __l.toArray === "function") { __l = __l.toArray(); }'); @@ -31,7 +31,7 @@ swig.setTag('for', forTag.parse, function(compiler, args, content, parents, opti return compile.join('\n'); }, forTag.ends, true); -function swigRenderer(data, locals){ +function swigRenderer(data, locals) { return swig.render(data.text, { locals: locals, filename: data.path diff --git a/lib/plugins/renderer/yaml.js b/lib/plugins/renderer/yaml.js index 256b5e9e3f..f277649303 100644 --- a/lib/plugins/renderer/yaml.js +++ b/lib/plugins/renderer/yaml.js @@ -3,8 +3,8 @@ var yaml = require('js-yaml'); var escapeYAML = require('hexo-front-matter').escape; -function yamlHelper(data){ +function yamlHelper(data) { return yaml.load(escapeYAML(data.text)); } -module.exports = yamlHelper; \ No newline at end of file +module.exports = yamlHelper; diff --git a/lib/plugins/tag/asset_img.js b/lib/plugins/tag/asset_img.js index f0e8899556..d99e25d3dc 100644 --- a/lib/plugins/tag/asset_img.js +++ b/lib/plugins/tag/asset_img.js @@ -6,10 +6,10 @@ * Syntax: * {% asset_img slug [title]%} */ -module.exports = function(ctx){ +module.exports = function(ctx) { var PostAsset = ctx.model('PostAsset'); - return function assetImgTag(args){ + return function assetImgTag(args) { var slug = args.shift(); if (!slug) return; diff --git a/lib/plugins/tag/asset_link.js b/lib/plugins/tag/asset_link.js index 9ed6cd58cb..95db93b802 100644 --- a/lib/plugins/tag/asset_link.js +++ b/lib/plugins/tag/asset_link.js @@ -6,10 +6,10 @@ * Syntax: * {% asset_link slug [title] %} */ -module.exports = function(ctx){ +module.exports = function(ctx) { var PostAsset = ctx.model('PostAsset'); - return function assetLinkTag(args){ + return function assetLinkTag(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/asset_path.js b/lib/plugins/tag/asset_path.js index 2884f63bd1..ac0a24c114 100644 --- a/lib/plugins/tag/asset_path.js +++ b/lib/plugins/tag/asset_path.js @@ -6,10 +6,10 @@ * Syntax: * {% asset_path slug %} */ -module.exports = function(ctx){ +module.exports = function(ctx) { var PostAsset = ctx.model('PostAsset'); - return function assetPathTag(args){ + return function assetPathTag(args) { var slug = args.shift(); if (!slug) return; @@ -18,4 +18,4 @@ module.exports = function(ctx){ return ctx.config.root + asset.path; }; -}; \ No newline at end of file +}; diff --git a/lib/plugins/tag/blockquote.js b/lib/plugins/tag/blockquote.js index cbc367a82a..b684767519 100644 --- a/lib/plugins/tag/blockquote.js +++ b/lib/plugins/tag/blockquote.js @@ -18,8 +18,8 @@ var rAuthor = /(.+)/; * {% endblockquote %} */ -module.exports = function(ctx){ - return function blockquoteTag(args, content){ +module.exports = function(ctx) { + return function blockquoteTag(args, content) { var str = args.join(' '); var author = ''; var source = ''; @@ -28,31 +28,31 @@ module.exports = function(ctx){ var result = ''; var match; - if (str){ - if (rFullCiteWithTitle.test(str)){ + if (str) { + if (rFullCiteWithTitle.test(str)) { match = str.match(rFullCiteWithTitle); author = match[1]; source = match[2] + match[3]; title = ctx.config.titlecase ? titlecase(match[4]) : match[4]; - } else if (rFullCite.test(str)){ + } else if (rFullCite.test(str)) { match = str.match(rFullCite); author = match[1]; source = match[2] + match[3]; - } else if (rAuthorTitle.test(str)){ + } else if (rAuthorTitle.test(str)) { match = str.match(rAuthorTitle); author = match[1]; title = ctx.config.titlecase ? titlecase(match[2]) : match[2]; - } else if (rAuthor.test(str)){ + } else if (rAuthor.test(str)) { match = str.match(rAuthor); author = match[1]; } if (author) footer += '' + author + ''; - if (source){ + if (source) { var link = source.replace(/^https?:\/\/|\/(index.html?)?$/g, ''); footer += '' + (title ? title : link) + ''; - } else if (title){ + } else if (title) { footer += '' + title + ''; } } @@ -64,4 +64,4 @@ module.exports = function(ctx){ return result; }; -}; \ No newline at end of file +}; diff --git a/lib/plugins/tag/code.js b/lib/plugins/tag/code.js index c58821d054..7f5eb83858 100644 --- a/lib/plugins/tag/code.js +++ b/lib/plugins/tag/code.js @@ -20,12 +20,12 @@ var rLang = /\s*lang:(\w+)/i; * {% endcodeblock %} */ -module.exports = function(ctx){ - return function codeTag(args, content){ +module.exports = function(ctx) { + return function codeTag(args, content) { var arg = args.join(' '); var config = ctx.config.highlight || {}; - if (!config.enable){ + if (!config.enable) { return '
' + 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', '

quote content

\n', '
Hello World
' -].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('' + highlight(code, {lang: 'js'}) + ''); }); - it('without language name', function(){ + it('without language name', function() { var data = { content: [ '```', @@ -87,7 +87,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('without language name - ignore tab character', function(){ + it('without language name - ignore tab character', function() { var data = { content: [ '``` \t', @@ -102,7 +102,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('title', function(){ + it('title', function() { var data = { content: [ '``` js Hello world', @@ -120,7 +120,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('url', function(){ + it('url', function() { var data = { content: [ '``` js Hello world http://hexo.io/', @@ -138,7 +138,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('link text', function(){ + it('link text', function() { var data = { content: [ '``` js Hello world http://hexo.io/ Hexo', @@ -156,8 +156,8 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('indent', function(){ - var indentCode = code.split('\n').map(function(line){ + it('indent', function() { + var indentCode = code.split('\n').map(function(line) { return ' ' + line; }).join('\n'); @@ -178,7 +178,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('line number', function(){ + it('line number', function() { hexo.config.highlight.line_number = false; var data = { @@ -198,7 +198,7 @@ describe('Backtick code block', function(){ data.content.should.eql('' + expected + ''); }); - it('tab replace', function(){ + it('tab replace', function() { hexo.config.highlight.tab_replace = ' '; var code = [ @@ -223,4 +223,4 @@ describe('Backtick code block', function(){ codeBlock(data); data.content.should.eql('' + expected + ''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/excerpt.js b/test/scripts/filters/excerpt.js index 446b644e60..06f32f5d32 100644 --- a/test/scripts/filters/excerpt.js +++ b/test/scripts/filters/excerpt.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Excerpt', function(){ +describe('Excerpt', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var excerpt = require('../../../lib/plugins/filter/after_post_render/excerpt').bind(hexo); - it('without ', function(){ + it('without ', function() { var content = [ 'foo', 'bar', @@ -24,7 +24,7 @@ describe('Excerpt', function(){ data.more.should.eql(content); }); - it('with ', function(){ + it('with ', function() { var content = [ 'foo', 'bar', @@ -47,7 +47,7 @@ describe('Excerpt', function(){ data.excerpt.should.eql([ 'foo', - 'bar', + 'bar' ].join('\n')); data.more.should.eql([ @@ -55,7 +55,7 @@ describe('Excerpt', function(){ ].join('\n')); }); - it('multiple ', function(){ + it('multiple ', function() { var content = [ 'foo', '', @@ -88,4 +88,4 @@ describe('Excerpt', function(){ 'baz' ].join('\n')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/external_link.js b/test/scripts/filters/external_link.js index b32dc2e977..e58e3dbf9f 100644 --- a/test/scripts/filters/external_link.js +++ b/test/scripts/filters/external_link.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('External link', function(){ +describe('External link', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var externalLink = require('../../../lib/plugins/filter/after_post_render/external_link').bind(hexo); @@ -10,7 +10,7 @@ describe('External link', function(){ hexo.config.external_link = true; hexo.config.url = 'http://maji.moe'; - it('disabled', function(){ + it('disabled', function() { var content = 'foo' + 'Hexo' + 'bar'; @@ -23,7 +23,7 @@ describe('External link', function(){ hexo.config.external_link = true; }); - it('enabled', function(){ + it('enabled', function() { var content = [ '# External link test', '1. External link', @@ -56,4 +56,4 @@ describe('External link', function(){ 'moe' ].join('\n')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/i18n_locals.js b/test/scripts/filters/i18n_locals.js index 55bff6bc17..4147355c69 100644 --- a/test/scripts/filters/i18n_locals.js +++ b/test/scripts/filters/i18n_locals.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('i18n locals', function(){ +describe('i18n locals', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var i18nFilter = require('../../../lib/plugins/filter/template_locals/i18n').bind(hexo); @@ -21,7 +21,7 @@ describe('i18n locals', function(){ Home: '首頁' }); - it('page.lang set', function(){ + it('page.lang set', function() { var locals = { config: hexo.config, page: { @@ -34,7 +34,7 @@ describe('i18n locals', function(){ locals.__('Home').should.eql('首頁'); }); - it('page.language set', function(){ + it('page.language set', function() { var locals = { config: hexo.config, page: { @@ -47,7 +47,7 @@ describe('i18n locals', function(){ locals.__('Home').should.eql('首頁'); }); - it('detect by path (lang found)', function(){ + it('detect by path (lang found)', function() { var locals = { config: hexo.config, page: {}, @@ -61,7 +61,7 @@ describe('i18n locals', function(){ locals.__('Home').should.eql('首頁'); }); - it('detect by path (lang not found)', function(){ + it('detect by path (lang not found)', function() { var locals = { config: hexo.config, page: {}, @@ -75,7 +75,7 @@ describe('i18n locals', function(){ locals.__('Home').should.eql('Home'); }); - it('use config by default', function(){ + it('use config by default', function() { var locals = { config: hexo.config, page: {}, @@ -89,7 +89,7 @@ describe('i18n locals', function(){ locals.__('Home').should.eql('Home'); }); - it('use config by default - with multiple languages, first language should be used', function(){ + it('use config by default - with multiple languages, first language should be used', function() { var oldConfig = hexo.config.language; hexo.config.language = ['zh-tw', 'en']; @@ -107,4 +107,4 @@ describe('i18n locals', function(){ hexo.config.language = oldConfig; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/index.js b/test/scripts/filters/index.js index edaf36f98b..3385e21f4b 100644 --- a/test/scripts/filters/index.js +++ b/test/scripts/filters/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Filters', function(){ +describe('Filters', function() { require('./backtick_code_block'); require('./excerpt'); require('./external_link'); @@ -10,4 +10,4 @@ describe('Filters', function(){ require('./render_post'); require('./save_database'); require('./titlecase'); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/new_post_path.js b/test/scripts/filters/new_post_path.js index 3073bbd40e..2027c7b93e 100644 --- a/test/scripts/filters/new_post_path.js +++ b/test/scripts/filters/new_post_path.js @@ -1,6 +1,6 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); var moment = require('moment'); @@ -9,7 +9,7 @@ var fs = require('hexo-fs'); var NEW_POST_NAME = ':title.md'; -describe('new_post_path', function(){ +describe('new_post_path', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'new_post_path_test')); var newPostPath = require('../../../lib/plugins/filter/new_post_path').bind(hexo); @@ -17,134 +17,134 @@ describe('new_post_path', function(){ var draftDir = pathFn.join(sourceDir, '_drafts'); var postDir = pathFn.join(sourceDir, '_posts'); - before(function(){ + before(function() { hexo.config.new_post_name = NEW_POST_NAME; - return fs.mkdirs(hexo.base_dir).then(function(){ + return fs.mkdirs(hexo.base_dir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('page layout + path', function(){ + it('page layout + path', function() { return newPostPath({ path: 'foo', layout: 'page' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(sourceDir, 'foo.md')); }); }); - it('draft layout + path', function(){ + it('draft layout + path', function() { return newPostPath({ path: 'foo', layout: 'draft' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(draftDir, 'foo.md')); }); }); - it('default layout + path', function(){ + it('default layout + path', function() { return newPostPath({ path: 'foo' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, 'foo.md')); }); }); - it('page layout + slug', function(){ + it('page layout + slug', function() { return newPostPath({ slug: 'foo', layout: 'page' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(sourceDir, 'foo', 'index.md')); }); }); - it('draft layout + slug', function(){ + it('draft layout + slug', function() { return newPostPath({ slug: 'foo', layout: 'draft' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(draftDir, 'foo.md')); - }) + }); }); - it('default layout + slug', function(){ + it('default layout + slug', function() { var now = moment(); hexo.config.new_post_name = ':year-:month-:day-:title.md'; return newPostPath({ slug: 'foo' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, now.format('YYYY-MM-DD') + '-foo.md')); hexo.config.new_post_name = NEW_POST_NAME; }); }); - it('date', function(){ + it('date', function() { var date = moment([2014, 0, 1]); hexo.config.new_post_name = ':year-:i_month-:i_day-:title.md'; return newPostPath({ slug: 'foo', date: date.toDate() - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, date.format('YYYY-M-D') + '-foo.md')); hexo.config.new_post_name = NEW_POST_NAME; - }) + }); }); - it('extra data', function(){ + it('extra data', function() { hexo.config.new_post_name = ':foo-:bar-:title.md'; return newPostPath({ slug: 'foo', foo: 'oh', bar: 'ya' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, 'oh-ya-foo.md')); hexo.config.new_post_name = NEW_POST_NAME; }); }); - it('append extension name if not existed', function(){ + it('append extension name if not existed', function() { hexo.config.new_post_name = ':title'; return newPostPath({ slug: 'foo' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, 'foo.md')); hexo.config.new_post_name = NEW_POST_NAME; }); }); - it('don\'t append extension name if existed', function(){ + it('don\'t append extension name if existed', function() { return newPostPath({ path: 'foo.markdown' - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, 'foo.markdown')); }); }); - it('replace existing files', function(){ + it('replace existing files', function() { var filename = 'test.md'; var path = pathFn.join(postDir, filename); - return fs.writeFile(path, '').then(function(){ + return fs.writeFile(path, '').then(function() { return newPostPath({ path: filename }, true); - }).then(function(target){ + }).then(function(target) { target.should.eql(path); return fs.unlink(path); }); }); - it('rename if target existed', function(){ + it('rename if target existed', function() { var filename = [ 'test.md', 'test-1.md', @@ -152,26 +152,26 @@ describe('new_post_path', function(){ 'test-foo.md' ]; - var path = filename.map(function(item){ + var path = filename.map(function(item) { return pathFn.join(postDir, item); }); - return Promise.map(path, function(item){ + return Promise.map(path, function(item) { return fs.writeFile(item, ''); - }).then(function(){ + }).then(function() { return newPostPath({ path: filename[0] }); - }).then(function(target){ + }).then(function(target) { target.should.eql(pathFn.join(postDir, 'test-3.md')); return path; - }).map(function(item){ + }).map(function(item) { return fs.unlink(item); }); }); - it('data is required', function(){ - var errorCallback = sinon.spy(function(err){ + it('data is required', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Either data.path or data.slug is required!'); }); @@ -179,4 +179,4 @@ describe('new_post_path', function(){ errorCallback.calledOnce.should.be.true; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/post_permalink.js b/test/scripts/filters/post_permalink.js index 48be605cc6..8ac46e1eae 100644 --- a/test/scripts/filters/post_permalink.js +++ b/test/scripts/filters/post_permalink.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var moment = require('moment'); var PERMALINK = ':year/:month/:day/:title/'; -describe('post_permalink', function(){ +describe('post_permalink', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var postPermalink = require('../../../lib/plugins/filter/post_permalink').bind(hexo); @@ -14,53 +14,53 @@ describe('post_permalink', function(){ hexo.config.permalink = PERMALINK; - before(function(){ + before(function() { var id; - return hexo.init().then(function(){ + return hexo.init().then(function() { return Post.insert({ source: 'foo.md', slug: 'foo', date: moment('2014-01-02') }); - }).then(function(post){ + }).then(function(post) { id = post._id; return post.setCategories(['foo', 'bar']); - }).then(function(){ + }).then(function() { post = Post.findById(id); }); }); - it('default', function(){ + it('default', function() { postPermalink(post).should.eql('2014/01/02/foo/'); }); - it('categories', function(){ + it('categories', function() { hexo.config.permalink = ':category/:title/'; postPermalink(post).should.eql('foo/bar/foo/'); hexo.config.permalink = PERMALINK; }); - it('uncategorized', function(){ + it('uncategorized', function() { hexo.config.permalink = ':category/:title/'; return Post.insert({ source: 'bar.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { postPermalink(post).should.eql(hexo.config.default_category + '/bar/'); hexo.config.permalink = PERMALINK; return Post.removeById(post._id); }); }); - it('extra data', function(){ + it('extra data', function() { hexo.config.permalink = ':layout/:title/'; postPermalink(post).should.eql(post.layout + '/foo/'); hexo.config.permalink = PERMALINK; }); - it('id', function(){ + it('id', function() { hexo.config.permalink = ':id'; postPermalink(post).should.eql(post._id); @@ -71,20 +71,20 @@ describe('post_permalink', function(){ hexo.config.permalink = PERMALINK; }); - it('name', function(){ + it('name', function() { hexo.config.permalink = ':title/:name'; return Post.insert({ source: 'sub/bar.md', slug: 'sub/bar' - }).then(function(post){ + }).then(function(post) { postPermalink(post).should.eql('sub/bar/bar'); hexo.config.permalink = PERMALINK; return Post.removeById(post._id); }); }); - it('post_title', function(){ + it('post_title', function() { hexo.config.permalink = ':year/:month/:day/:post_title/'; return Post.insert({ @@ -92,10 +92,10 @@ describe('post_permalink', function(){ slug: '2015-05-06-my-new-post', title: 'My New Post', date: moment('2015-05-06') - }).then(function(post){ + }).then(function(post) { postPermalink(post).should.eql('2015/05/06/my-new-post/'); hexo.config.permalink = PERMALINK; return Post.removeById(post._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/render_post.js b/test/scripts/filters/render_post.js index 6db71a2b16..b50d1b8b27 100644 --- a/test/scripts/filters/render_post.js +++ b/test/scripts/filters/render_post.js @@ -1,32 +1,32 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fixture = require('../../fixtures/post_render'); -describe('Render post', function(){ +describe('Render post', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Post = hexo.model('Post'); var Page = hexo.model('Page'); var renderPost = require('../../../lib/plugins/filter/before_generate/render_post').bind(hexo); - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return hexo.loadPlugin(require.resolve('hexo-renderer-marked')); }); }); - it('post', function(){ + it('post', function() { var id; return Post.insert({ source: 'foo.md', slug: 'foo', _content: fixture.content - }).then(function(post){ + }).then(function(post) { id = post._id; return renderPost(); - }).then(function(){ + }).then(function() { var post = Post.findById(id); post.content.trim().should.eql(fixture.expected); @@ -34,21 +34,21 @@ describe('Render post', function(){ }); }); - it('page', function(){ + it('page', function() { var id; return Page.insert({ source: 'foo.md', path: 'foo.html', _content: fixture.content - }).then(function(page){ + }).then(function(page) { id = page._id; return renderPost(); - }).then(function(){ + }).then(function() { var page = Page.findById(id); page.content.trim().should.eql(fixture.expected); return page.remove(); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/save_database.js b/test/scripts/filters/save_database.js index 29b9d9990e..9fe4c1d229 100644 --- a/test/scripts/filters/save_database.js +++ b/test/scripts/filters/save_database.js @@ -1,33 +1,33 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var fs = require('hexo-fs'); var Promise = require('bluebird'); -describe('Save database', function(){ +describe('Save database', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var saveDatabase = Promise.method(require('../../../lib/plugins/filter/before_exit/save_database')).bind(hexo); var dbPath = hexo.database.options.path; - it('default', function(){ + it('default', function() { hexo.env.init = true; - return saveDatabase().then(function(){ + return saveDatabase().then(function() { return fs.exists(dbPath); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.true; return fs.unlink(dbPath); }); }); - it('do nothing if hexo is not initialized', function(){ + it('do nothing if hexo is not initialized', function() { hexo.env.init = false; - return saveDatabase().then(function(){ + return saveDatabase().then(function() { return fs.exists(dbPath); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/filters/titlecase.js b/test/scripts/filters/titlecase.js index 256614fcee..8b9c8ac9ca 100644 --- a/test/scripts/filters/titlecase.js +++ b/test/scripts/filters/titlecase.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('Titlecase', function(){ +describe('Titlecase', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var titlecase = require('../../../lib/plugins/filter/before_post_render/titlecase').bind(hexo); - it('disabled', function(){ + it('disabled', function() { var title = 'Today is a good day'; var data = {title: title}; hexo.config.titlecase = false; @@ -16,7 +16,7 @@ describe('Titlecase', function(){ data.title.should.eql(title); }); - it('enabled', function(){ + it('enabled', function() { var title = 'Today is a good day'; var data = {title: title}; hexo.config.titlecase = true; @@ -24,4 +24,4 @@ describe('Titlecase', function(){ titlecase(data); data.title.should.eql('Today Is a Good Day'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/generators/asset.js b/test/scripts/generators/asset.js index 33be16e4f7..aae0e85c97 100644 --- a/test/scripts/generators/asset.js +++ b/test/scripts/generators/asset.js @@ -1,34 +1,34 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); var pathFn = require('path'); var fs = require('hexo-fs'); var testUtil = require('../../util'); -describe('asset', function(){ +describe('asset', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'asset_test'), {silent: true}); var generator = require('../../../lib/plugins/generator/asset').bind(hexo); var Asset = hexo.model('Asset'); - function checkStream(stream, expected){ - return testUtil.stream.read(stream).then(function(data){ + function checkStream(stream, expected) { + return testUtil.stream.read(stream).then(function(data) { data.should.eql(expected); }); } - 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); }); - it('renderable', function(){ + it('renderable', function() { var path = 'test.yml'; var source = pathFn.join(hexo.base_dir, path); var content = 'foo: bar'; @@ -36,16 +36,16 @@ describe('asset', function(){ return Promise.all([ Asset.insert({_id: path, path: path}), fs.writeFile(source, content) - ]).then(function(){ + ]).then(function() { return generator(hexo.locals); - }).then(function(data){ + }).then(function(data) { data[0].path.should.eql('test.json'); data[0].data.modified.should.be.true; - return data[0].data.data().then(function(result){ + return data[0].data.data().then(function(result) { result.should.eql('{"foo":"bar"}'); }); - }).then(function(){ + }).then(function() { return Promise.all([ Asset.removeById(path), fs.unlink(source) @@ -53,7 +53,7 @@ describe('asset', function(){ }); }); - it('not renderable', function(){ + it('not renderable', function() { var path = 'test.txt'; var source = pathFn.join(hexo.base_dir, path); var content = 'test content'; @@ -61,44 +61,44 @@ describe('asset', function(){ return Promise.all([ Asset.insert({_id: path, path: path}), fs.writeFile(source, content) - ]).then(function(){ + ]).then(function() { return generator(hexo.locals); - }).then(function(data){ + }).then(function(data) { data[0].path.should.eql(path); data[0].data.modified.should.be.true; return checkStream(data[0].data.data(), content); - }).then(function(){ + }).then(function() { return Promise.all([ Asset.removeById(path), fs.unlink(source) ]); - }) + }); }); - it('remove assets which does not exist', function(){ + it('remove assets which does not exist', function() { var path = 'test.txt'; return Asset.insert({ _id: path, path: path - }).then(function(){ + }).then(function() { return generator(hexo.locals); - }).then(function(){ + }).then(function() { should.not.exist(Asset.findById(path)); }); }); - it('don\'t remove extension name', function(){ + it('don\'t remove extension name', function() { var path = 'test.min.js'; var source = pathFn.join(hexo.base_dir, path); return Promise.all([ Asset.insert({_id: path, path: path}), fs.writeFile(source, '') - ]).then(function(){ + ]).then(function() { return generator(hexo.locals); - }).then(function(data){ + }).then(function(data) { data[0].path.should.eql('test.min.js'); return Promise.all([ @@ -107,4 +107,4 @@ describe('asset', function(){ ]); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/generators/index.js b/test/scripts/generators/index.js index d4a4bc9b5a..ea5989e709 100644 --- a/test/scripts/generators/index.js +++ b/test/scripts/generators/index.js @@ -1,7 +1,7 @@ 'use strict'; -describe('Generators', function(){ +describe('Generators', function() { require('./asset'); require('./page'); require('./post'); -}); \ No newline at end of file +}); diff --git a/test/scripts/generators/page.js b/test/scripts/generators/page.js index 8b78d6d90b..507ae33912 100644 --- a/test/scripts/generators/page.js +++ b/test/scripts/generators/page.js @@ -1,26 +1,26 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); var _ = require('lodash'); -describe('page', function(){ +describe('page', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname, {silent: true}); var Page = hexo.model('Page'); var generator = Promise.method(require('../../../lib/plugins/generator/page').bind(hexo)); - function locals(){ + function locals() { hexo.locals.invalidate(); return hexo.locals.toObject(); } - it('default layout', function(){ + it('default layout', function() { return Page.insert({ source: 'foo', path: 'bar' - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { data.should.eql([ { path: page.path, @@ -34,13 +34,13 @@ describe('page', function(){ }); }); - it('custom layout', function(){ + it('custom layout', function() { return Page.insert({ source: 'foo', path: 'bar', layout: 'photo' - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { data[0].layout.should.eql(['photo', 'page', 'post', 'index']); return page.remove(); @@ -48,13 +48,13 @@ describe('page', function(){ }); }); - it('layout disabled', function(){ + it('layout disabled', function() { return Page.insert({ source: 'foo', path: 'bar', layout: false - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { should.not.exist(data[0].layout); return page.remove(); @@ -62,7 +62,7 @@ describe('page', function(){ }); }); - it('skip render', function(){ + it('skip render', function() { hexo.config.skip_render = 'lab/**/*.js'; return Page.insert({ @@ -70,8 +70,8 @@ describe('page', function(){ path: 'lab/assets/jquery.min.js', layout: false, raw: 'jquery raw' - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { data.should.eql([ {path: page.source, data: page.raw} ]); @@ -82,7 +82,7 @@ describe('page', function(){ }); }); - it('skip render - multiple rules', function(){ + it('skip render - multiple rules', function() { hexo.config.skip_render = ['lab/**/*.js']; return Page.insert({ @@ -90,8 +90,8 @@ describe('page', function(){ path: 'lab/assets/jquery.min.js', layout: false, raw: 'jquery raw' - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { data.should.eql([ {path: page.source, data: page.raw} ]); @@ -102,7 +102,7 @@ describe('page', function(){ }); }); - it('skip render - don\'t replace extension name', function(){ + it('skip render - don\'t replace extension name', function() { hexo.config.skip_render = 'README.md'; return Page.insert({ @@ -110,8 +110,8 @@ describe('page', function(){ path: 'README.html', layout: 'page', raw: 'readme raw' - }).then(function(page){ - return generator(locals()).then(function(data){ + }).then(function(page) { + return generator(locals()).then(function(data) { data.should.eql([ {path: page.source, data: page.raw} ]); @@ -121,4 +121,4 @@ describe('page', function(){ }); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/generators/post.js b/test/scripts/generators/post.js index 07600762d5..f7eaed7a47 100644 --- a/test/scripts/generators/post.js +++ b/test/scripts/generators/post.js @@ -1,10 +1,10 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); var _ = require('lodash'); -describe('post', function(){ +describe('post', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname, {silent: true}); var Post = hexo.model('Post'); @@ -12,21 +12,21 @@ describe('post', function(){ hexo.config.permalink = ':title/'; - function locals(){ + function locals() { hexo.locals.invalidate(); return hexo.locals.toObject(); } - before(function(){ + before(function() { return hexo.init(); }); - it('default layout', function(){ + it('default layout', function() { return Post.insert({ source: 'foo', slug: 'bar' - }).then(function(post){ - return generator(locals()).then(function(data){ + }).then(function(post) { + return generator(locals()).then(function(data) { data.should.eql([ { path: 'bar/', @@ -40,13 +40,13 @@ describe('post', function(){ }); }); - it('custom layout', function(){ + it('custom layout', function() { return Post.insert({ source: 'foo', slug: 'bar', layout: 'photo' - }).then(function(post){ - return generator(locals()).then(function(data){ + }).then(function(post) { + return generator(locals()).then(function(data) { data[0].layout.should.eql(['photo', 'post', 'page', 'index']); return post.remove(); @@ -54,13 +54,13 @@ describe('post', function(){ }); }); - it('layout disabled', function(){ + it('layout disabled', function() { return Post.insert({ source: 'foo', slug: 'bar', layout: false - }).then(function(post){ - return generator(locals()).then(function(data){ + }).then(function(post) { + return generator(locals()).then(function(data) { should.not.exist(data[0].layout); return post.remove(); @@ -68,13 +68,13 @@ describe('post', function(){ }); }); - it('prev/next post', function(){ + it('prev/next post', function() { return Post.insert([ {source: 'foo', slug: 'foo', date: 1e8}, {source: 'bar', slug: 'bar', date: 1e8 + 1}, {source: 'baz', slug: 'baz', date: 1e8 - 1} - ]).then(function(posts){ - return generator(locals()).then(function(data){ + ]).then(function(posts) { + return generator(locals()).then(function(data) { should.not.exist(data[0].data.prev); data[0].data.next._id.should.eql(posts[0]._id); @@ -84,8 +84,8 @@ describe('post', function(){ data[2].data.prev._id.should.eql(posts[0]._id); should.not.exist(data[2].data.next); }).thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/css.js b/test/scripts/helpers/css.js index e870c6619e..8d5c8a8b5c 100644 --- a/test/scripts/helpers/css.js +++ b/test/scripts/helpers/css.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('css', function(){ +describe('css', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,36 +14,36 @@ describe('css', function(){ var css = require('../../../lib/plugins/helper/css').bind(ctx); - function assertResult(result){ + function assertResult(result) { var expected = ''; - for (var i = 1, len = arguments.length; i < len; i++){ + for (var i = 1, len = arguments.length; i < len; i++) { expected += '\n'; } result.should.eql(expected.trim()); } - it('a string', function(){ + it('a string', function() { assertResult(css('style'), '/style.css'); assertResult(css('style.css'), '/style.css'); assertResult(css('http://hexo.io/style.css'), 'http://hexo.io/style.css'); assertResult(css('//hexo.io/style.css'), '//hexo.io/style.css'); }); - it('an array', function(){ + it('an array', function() { assertResult(css(['foo', 'bar', 'baz']), '/foo.css', '/bar.css', '/baz.css'); }); - it('multiple strings', function(){ + it('multiple strings', function() { assertResult(css('foo', 'bar', 'baz'), '/foo.css', '/bar.css', '/baz.css'); }); - it('multiple arrays', function(){ + it('multiple arrays', function() { assertResult(css(['foo', 'bar'], ['baz']), '/foo.css', '/bar.css', '/baz.css'); }); - it('mixed', function(){ + it('mixed', function() { assertResult(css(['foo', 'bar'], 'baz'), '/foo.css', '/bar.css', '/baz.css'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/date.js b/test/scripts/helpers/date.js index 6051973296..baf2fe5467 100644 --- a/test/scripts/helpers/date.js +++ b/test/scripts/helpers/date.js @@ -1,24 +1,24 @@ 'use strict'; var moment = require('moment-timezone'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); -describe('date', function(){ +describe('date', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var dateHelper = require('../../../lib/plugins/helper/date'); var clock; - before(function(){ + before(function() { clock = sinon.useFakeTimers(Date.now()); }); - after(function(){ + after(function() { clock.restore(); }); - it('date', function(){ + it('date', function() { var ctx = { config: hexo.config, page: {} @@ -57,7 +57,7 @@ describe('date', function(){ ctx.config.timezone = ''; }); - it('date_xml', function(){ + it('date_xml', function() { var dateXML = dateHelper.date_xml; // now @@ -73,7 +73,7 @@ describe('date', function(){ dateXML(Date.now()).should.eql(moment().toISOString()); }); - it('time', function(){ + it('time', function() { var ctx = { config: hexo.config, page: {} @@ -112,7 +112,7 @@ describe('date', function(){ ctx.config.timezone = ''; }); - it('full_date', function(){ + it('full_date', function() { var ctx = { config: hexo.config, date: dateHelper.date, @@ -154,7 +154,7 @@ describe('date', function(){ ctx.config.timezone = ''; }); - it('time_tag', function(){ + it('time_tag', function() { var ctx = { config: hexo.config, date: dateHelper.date, @@ -163,13 +163,13 @@ describe('date', function(){ var timeTag = dateHelper.time_tag.bind(ctx); - function result(date, format){ + function result(date, format) { date = date || new Date(); format = format || hexo.config.date_format; return ''; } - function check(date, format){ + function check(date, format) { format = format || hexo.config.date_format; timeTag(date, format).should.eql(result(date, format)); } @@ -204,4 +204,4 @@ describe('date', function(){ timeTag(Date.now(), 'LLL').should.eql(''); ctx.config.timezone = ''; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/debug.js b/test/scripts/helpers/debug.js index acb4ddbe62..7f81527788 100644 --- a/test/scripts/helpers/debug.js +++ b/test/scripts/helpers/debug.js @@ -1,29 +1,29 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('debug', function(){ +describe('debug', function() { var debug = require('../../../lib/plugins/helper/debug'); var inspect = require('util').inspect; - it('inspect simple object', function(){ - var obj = { foo: "bar" }; + it('inspect simple object', function() { + var obj = { foo: 'bar' }; debug.inspectObject(obj).should.eql(inspect(obj)); }); - it('inspect circular object', function(){ - var obj = { foo: "bar" }; + it('inspect circular object', function() { + var obj = { foo: 'bar' }; obj.circular = obj; debug.inspectObject(obj).should.eql(inspect(obj)); }); - it('inspect deep object', function(){ - var obj = { baz: { thud: "narf", dur: { foo: "bar", baz: { bang: "zoom" } } } }; + it('inspect deep object', function() { + var obj = { baz: { thud: 'narf', dur: { foo: 'bar', baz: { bang: 'zoom' } } } }; debug.inspectObject(obj).should.not.eql(inspect(obj, {depth: 5})); debug.inspectObject(obj, {depth: 5}).should.eql(inspect(obj, {depth: 5})); }); - it('log should print to console', function(){ + it('log should print to console', function() { debug.log('Hello %s from debug.log()!', 'World'); // console should print 'Hello World from debug.log()!' debug.should.be.a('object'); // void assert diff --git a/test/scripts/helpers/favicon_tag.js b/test/scripts/helpers/favicon_tag.js index d9424b89ff..3d07c12be7 100644 --- a/test/scripts/helpers/favicon_tag.js +++ b/test/scripts/helpers/favicon_tag.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('favicon_tag', function(){ +describe('favicon_tag', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,7 +14,7 @@ describe('favicon_tag', function(){ var favicon = require('../../../lib/plugins/helper/favicon_tag').bind(ctx); - it('path', function(){ + it('path', function() { favicon('favicon.ico').should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/feed_tag.js b/test/scripts/helpers/feed_tag.js index e45fa4cd65..93bfe40af7 100644 --- a/test/scripts/helpers/feed_tag.js +++ b/test/scripts/helpers/feed_tag.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('feed_tag', function(){ +describe('feed_tag', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,15 +14,15 @@ describe('feed_tag', function(){ var feed = require('../../../lib/plugins/helper/feed_tag').bind(ctx); - it('path', function(){ + it('path', function() { feed('atom.xml').should.eql(''); }); - it('title', function(){ + it('title', function() { feed('atom.xml', {title: 'RSS Feed'}).should.eql(''); }); - it('type', function(){ + it('type', function() { feed('rss.xml', {type: 'rss'}).should.eql(''); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/fragment_cache.js b/test/scripts/helpers/fragment_cache.js index fef79d28bb..ecdf4a9a8d 100644 --- a/test/scripts/helpers/fragment_cache.js +++ b/test/scripts/helpers/fragment_cache.js @@ -1,21 +1,21 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('fragment_cache', function(){ +describe('fragment_cache', function() { var fragment_cache = require('../../../lib/plugins/helper/fragment_cache')(); - fragment_cache.call({cache: true}, 'foo', function(){ + fragment_cache.call({cache: true}, 'foo', function() { return 123; }); - it('cache enabled', function(){ + it('cache enabled', function() { fragment_cache.call({cache: true}, 'foo').should.eql(123); }); - it('cache disabled', function(){ - fragment_cache.call({cache: false}, 'foo', function(){ + it('cache disabled', function() { + fragment_cache.call({cache: false}, 'foo', function() { return 456; }).should.eql(456); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/gravatar.js b/test/scripts/helpers/gravatar.js index 2dc914fb53..90b19ae353 100644 --- a/test/scripts/helpers/gravatar.js +++ b/test/scripts/helpers/gravatar.js @@ -1,31 +1,31 @@ 'use strict'; var crypto = require('crypto'); -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('gravatar', function(){ +describe('gravatar', function() { var gravatar = require('../../../lib/plugins/helper/gravatar'); - function md5(str){ + function md5(str) { return crypto.createHash('md5').update(str).digest('hex'); } var email = 'abc@abc.com'; var hash = md5(email); - it('default', function(){ + it('default', function() { gravatar(email).should.eql('http://www.gravatar.com/avatar/' + hash); }); - it('size', function(){ + it('size', function() { gravatar(email, 100).should.eql('http://www.gravatar.com/avatar/' + hash + '?s=100'); }); - it('options', function(){ + it('options', function() { gravatar(email, { s: 200, r: 'pg', d: 'mm' }).should.eql('http://www.gravatar.com/avatar/' + hash + '?s=200&r=pg&d=mm'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/image_tag.js b/test/scripts/helpers/image_tag.js index 06df650bb5..6c9ba8163d 100644 --- a/test/scripts/helpers/image_tag.js +++ b/test/scripts/helpers/image_tag.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('image_tag', function(){ +describe('image_tag', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,22 +14,22 @@ describe('image_tag', function(){ var img = require('../../../lib/plugins/helper/image_tag').bind(ctx); - it('path', function(){ + it('path', function() { img('http://hexo.io/image.jpg').should.eql(''); }); - it('class (string)', function(){ + it('class (string)', function() { img('http://hexo.io/image.jpg', {class: 'foo'}) .should.eql(''); }); - it('class (array)', function(){ + it('class (array)', function() { img('http://hexo.io/image.jpg', {class: ['foo', 'bar']}) .should.eql(''); }); - it('alt', function(){ + it('alt', function() { img('http://hexo.io/image.jpg', {alt: 'Image caption'}) .should.eql('Image caption'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/index.js b/test/scripts/helpers/index.js index fe9c493c62..1ebb7a69e9 100644 --- a/test/scripts/helpers/index.js +++ b/test/scripts/helpers/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Helpers', function(){ +describe('Helpers', function() { require('./debug'); require('./css'); require('./date'); diff --git a/test/scripts/helpers/is.js b/test/scripts/helpers/is.js index 64d17fa801..1dcd7bc665 100644 --- a/test/scripts/helpers/is.js +++ b/test/scripts/helpers/is.js @@ -1,41 +1,41 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('is', function(){ +describe('is', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var is = require('../../../lib/plugins/helper/is'); - it('is_current', function(){ + it('is_current', function() { is.current.call({path: 'index.html', config: hexo.config}).should.be.true; is.current.call({path: 'foo/bar', config: hexo.config}, 'foo').should.be.true; is.current.call({path: 'foo/bar', config: hexo.config}, 'foo/bar').should.be.true; is.current.call({path: 'foo/bar', config: hexo.config}, 'foo/baz').should.be.false; }); - it('is_home', function(){ + it('is_home', function() { is.home.call({page: {__index: true}}).should.be.true; is.home.call({page: {}}).should.be.false; }); - it('is_post', function(){ + it('is_post', function() { is.post.call({page: {__post: true}}).should.be.true; is.post.call({page: {}}).should.be.false; }); - it('is_page', function(){ + it('is_page', function() { is.page.call({page: {__page: true}}).should.be.true; is.page.call({page: {}}).should.be.false; }); - it('is_archive', function(){ + it('is_archive', function() { is.archive.call({page: {}}).should.be.false; is.archive.call({page: {archive: true}}).should.be.true; is.archive.call({page: {archive: false}}).should.be.false; }); - it('is_year', function(){ + it('is_year', function() { is.year.call({page: {}}).should.be.false; is.year.call({page: {archive: true}}).should.be.false; is.year.call({page: {archive: true, year: 2014}}).should.be.true; @@ -44,7 +44,7 @@ describe('is', function(){ is.year.call({page: {archive: true, year: 2014, month: 10}}).should.be.true; }); - it('is_month', function(){ + it('is_month', function() { is.month.call({page: {}}).should.be.false; is.month.call({page: {archive: true}}).should.be.false; is.month.call({page: {archive: true, year: 2014}}).should.be.false; @@ -56,12 +56,12 @@ describe('is', function(){ is.month.call({page: {archive: true, year: 2014, month: 10}}, 12).should.be.false; }); - it('is_category', function(){ + it('is_category', function() { is.category.call({page: {category: 'foo'}}).should.be.true; is.category.call({page: {}}).should.be.false; }); - it('is_tag', function(){ + it('is_tag', function() { is.tag.call({page: {tag: 'foo'}}).should.be.true; is.tag.call({page: {}}).should.be.false; }); diff --git a/test/scripts/helpers/js.js b/test/scripts/helpers/js.js index 70b4a703a5..5c7cf79ec9 100644 --- a/test/scripts/helpers/js.js +++ b/test/scripts/helpers/js.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('js', function(){ +describe('js', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,36 +14,36 @@ describe('js', function(){ var js = require('../../../lib/plugins/helper/js').bind(ctx); - function assertResult(result){ + function assertResult(result) { var expected = ''; - for (var i = 1, len = arguments.length; i < len; i++){ + for (var i = 1, len = arguments.length; i < len; i++) { expected += '\n'; } result.should.eql(expected.trim()); } - it('a string', function(){ + it('a string', function() { assertResult(js('script'), '/script.js'); assertResult(js('script.js'), '/script.js'); assertResult(js('http://hexo.io/script.js'), 'http://hexo.io/script.js'); assertResult(js('//hexo.io/script.js'), '//hexo.io/script.js'); }); - it('an array', function(){ + it('an array', function() { assertResult(js(['foo', 'bar', 'baz']), '/foo.js', '/bar.js', '/baz.js'); }); - it('multiple strings', function(){ + it('multiple strings', function() { assertResult(js('foo', 'bar', 'baz'), '/foo.js', '/bar.js', '/baz.js'); }); - it('multiple arrays', function(){ + it('multiple arrays', function() { assertResult(js(['foo', 'bar'], ['baz']), '/foo.js', '/bar.js', '/baz.js'); }); - it('mixed', function(){ + it('mixed', function() { assertResult(js(['foo', 'bar'], 'baz'), '/foo.js', '/bar.js', '/baz.js'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/link_to.js b/test/scripts/helpers/link_to.js index 5ebb54b2aa..fdea9ae958 100644 --- a/test/scripts/helpers/link_to.js +++ b/test/scripts/helpers/link_to.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('link_to', function(){ +describe('link_to', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -14,36 +14,36 @@ describe('link_to', function(){ var linkTo = require('../../../lib/plugins/helper/link_to').bind(ctx); - it('path', function(){ + it('path', function() { linkTo('http://hexo.io/').should.eql('hexo.io'); }); - it('title', function(){ + it('title', function() { linkTo('http://hexo.io/', 'Hexo').should.eql('Hexo'); }); - it('external (boolean)', function(){ + it('external (boolean)', function() { linkTo('http://hexo.io/', 'Hexo', true) .should.eql('Hexo'); }); - it('external (object)', function(){ + it('external (object)', function() { linkTo('http://hexo.io/', 'Hexo', {external: true}) .should.eql('Hexo'); }); - it('class (string)', function(){ + it('class (string)', function() { linkTo('http://hexo.io/', 'Hexo', {class: 'foo'}) .should.eql('Hexo'); }); - it('class (array)', function(){ + it('class (array)', function() { linkTo('http://hexo.io/', 'Hexo', {class: ['foo', 'bar']}) .should.eql('Hexo'); }); - it('id', function(){ + it('id', function() { linkTo('http://hexo.io/', 'Hexo', {id: 'foo'}) .should.eql('Hexo'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/list_archives.js b/test/scripts/helpers/list_archives.js index ffbf90342c..fc1371dc0b 100644 --- a/test/scripts/helpers/list_archives.js +++ b/test/scripts/helpers/list_archives.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('list_archives', function(){ +describe('list_archives', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Post = hexo.model('Post'); @@ -16,23 +16,23 @@ describe('list_archives', function(){ var listArchives = require('../../../lib/plugins/helper/list_archives').bind(ctx); - function resetLocals(){ + function resetLocals() { hexo.locals.invalidate(); ctx.site = hexo.locals.toObject(); } - before(function(){ + before(function() { return Post.insert([ {source: 'foo', slug: 'foo', date: new Date(2014, 1, 2)}, {source: 'bar', slug: 'bar', date: new Date(2013, 5, 6)}, {source: 'baz', slug: 'baz', date: new Date(2013, 9, 10)}, {source: 'boo', slug: 'boo', date: new Date(2013, 5, 8)} - ]).then(function(){ + ]).then(function() { resetLocals(); }); }); - it('default', function(){ + it('default', function() { var result = listArchives(); result.should.eql([ @@ -44,7 +44,7 @@ describe('list_archives', function(){ ].join('')); }); - it('type: yearly', function(){ + it('type: yearly', function() { var result = listArchives({ type: 'yearly' }); @@ -57,7 +57,7 @@ describe('list_archives', function(){ ].join('')); }); - it('format', function(){ + it('format', function() { var result = listArchives({ format: 'YYYY/M' }); @@ -71,7 +71,7 @@ describe('list_archives', function(){ ].join('')); }); - it('style: false', function(){ + it('style: false', function() { var result = listArchives({ style: false }); @@ -83,7 +83,7 @@ describe('list_archives', function(){ ].join(', ')); }); - it('show_count', function(){ + it('show_count', function() { var result = listArchives({ show_count: false }); @@ -97,7 +97,7 @@ describe('list_archives', function(){ ].join('')); }); - it('order', function(){ + it('order', function() { var result = listArchives({ order: 1 }); @@ -111,9 +111,9 @@ describe('list_archives', function(){ ].join('')); }); - it('transform', function(){ + it('transform', function() { var result = listArchives({ - transform: function(str){ + transform: function(str) { return str.toUpperCase(); } }); @@ -127,7 +127,7 @@ describe('list_archives', function(){ ].join('')); }); - it('separator', function(){ + it('separator', function() { var result = listArchives({ style: false, separator: '' @@ -140,7 +140,7 @@ describe('list_archives', function(){ ].join('')); }); - it('class', function(){ + it('class', function() { var result = listArchives({ class: 'test' }); @@ -154,7 +154,7 @@ describe('list_archives', function(){ ].join('')); }); - it('page.lang', function(){ + it('page.lang', function() { ctx.page.lang = 'zh-tw'; var result = listArchives(); ctx.page.lang = ''; @@ -168,7 +168,7 @@ describe('list_archives', function(){ ].join('')); }); - it('config.language', function(){ + it('config.language', function() { ctx.config.language = 'de'; var result = listArchives(); ctx.config.language = ''; @@ -183,4 +183,4 @@ describe('list_archives', function(){ }); it('timezone'); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/list_categories.js b/test/scripts/helpers/list_categories.js index e369ede862..39a549c8d2 100644 --- a/test/scripts/helpers/list_categories.js +++ b/test/scripts/helpers/list_categories.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('list_categories', function(){ +describe('list_categories', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Post = hexo.model('Post'); @@ -17,29 +17,29 @@ describe('list_categories', function(){ var listCategories = require('../../../lib/plugins/helper/list_categories').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) { return Promise.each([ ['baz'], ['baz', 'bar'], ['foo'], ['baz'] - ], function(cats, i){ + ], function(cats, i) { return posts[i].setCategories(cats); }); - }).then(function(){ + }).then(function() { hexo.locals.invalidate(); ctx.site = hexo.locals.toObject(); ctx.page = ctx.site.posts.data[1]; }); }); - it('default', function(){ + it('default', function() { var result = listCategories(); result.should.eql([ @@ -59,7 +59,7 @@ describe('list_categories', function(){ ].join('')); }); - it('specified collection', function(){ + it('specified collection', function() { var result = listCategories(Category.find({ parent: {$exists: false} })); @@ -76,7 +76,7 @@ describe('list_categories', function(){ ].join('')); }); - it('style: false', function(){ + it('style: false', function() { var result = listCategories({ style: false }); @@ -88,7 +88,7 @@ describe('list_categories', function(){ ].join(', ')); }); - it('show_count: false', function(){ + it('show_count: false', function() { var result = listCategories({ show_count: false }); @@ -110,7 +110,7 @@ describe('list_categories', function(){ ].join('')); }); - it('class', function(){ + it('class', function() { var result = listCategories({ class: 'test' }); @@ -132,7 +132,7 @@ describe('list_categories', function(){ ].join('')); }); - it('depth', function(){ + it('depth', function() { var result = listCategories({ depth: 1 }); @@ -149,7 +149,7 @@ describe('list_categories', function(){ ].join('')); }); - it('orderby', function(){ + it('orderby', function() { var result = listCategories({ orderby: 'length' }); @@ -171,7 +171,7 @@ describe('list_categories', function(){ ].join('')); }); - it('order', function(){ + it('order', function() { var result = listCategories({ order: -1 }); @@ -193,9 +193,9 @@ describe('list_categories', function(){ ].join('')); }); - it('transform', function(){ + it('transform', function() { var result = listCategories({ - transform: function(name){ + transform: function(name) { return name.toUpperCase(); } }); @@ -217,7 +217,7 @@ describe('list_categories', function(){ ].join('')); }); - it('separator', function(){ + it('separator', function() { var result = listCategories({ style: false, separator: '' @@ -230,7 +230,7 @@ describe('list_categories', function(){ ].join('')); }); - it('children-indicator', function(){ + it('children-indicator', function() { var result = listCategories({ children_indicator: 'has-children' }); @@ -252,7 +252,7 @@ describe('list_categories', function(){ ].join('')); }); - it('show-current', function(){ + it('show-current', function() { var result = listCategories({ show_current: true }); diff --git a/test/scripts/helpers/list_posts.js b/test/scripts/helpers/list_posts.js index e1d5483d6a..0533570a4b 100644 --- a/test/scripts/helpers/list_posts.js +++ b/test/scripts/helpers/list_posts.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('list_posts', function(){ +describe('list_posts', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Post = hexo.model('Post'); @@ -17,20 +17,20 @@ describe('list_posts', function(){ hexo.config.permalink = ':title/'; - before(function(){ + before(function() { return Post.insert([ {source: 'foo', slug: 'foo', title: 'Its', date: 1e8}, {source: 'bar', slug: 'bar', title: 'Chemistry', date: 1e8 + 1}, {source: 'baz', slug: 'baz', title: 'Bitch', date: 1e8 - 1} - ]).then(function(){ + ]).then(function() { return hexo.init(); - }).then(function(){ + }).then(function() { hexo.locals.invalidate(); ctx.site = hexo.locals.toObject(); }); }); - it('default', function(){ + it('default', function() { var result = listPosts(); result.should.eql([ @@ -42,7 +42,7 @@ describe('list_posts', function(){ ].join('')); }); - it('specified collection', function(){ + it('specified collection', function() { var result = listPosts(Post.find({ title: 'Its' })); @@ -54,7 +54,7 @@ describe('list_posts', function(){ ].join('')); }); - it('style: false', function(){ + it('style: false', function() { var result = listPosts({ style: false }); @@ -66,7 +66,7 @@ describe('list_posts', function(){ ].join(', ')); }); - it('orderby', function(){ + it('orderby', function() { var result = listPosts({ orderby: 'title' }); @@ -80,7 +80,7 @@ describe('list_posts', function(){ ].join('')); }); - it('order', function(){ + it('order', function() { var result = listPosts({ order: 1 }); @@ -94,7 +94,7 @@ describe('list_posts', function(){ ].join('')); }); - it('class', function(){ + it('class', function() { var result = listPosts({ class: 'test' }); @@ -108,9 +108,9 @@ describe('list_posts', function(){ ].join('')); }); - it('transform', function(){ + it('transform', function() { var result = listPosts({ - transform: function(str){ + transform: function(str) { return str.toUpperCase(); } }); @@ -124,7 +124,7 @@ describe('list_posts', function(){ ].join('')); }); - it('separator', function(){ + it('separator', function() { var result = listPosts({ style: false, separator: '' @@ -137,7 +137,7 @@ describe('list_posts', function(){ ].join('')); }); - it('amount', function(){ + it('amount', function() { var result = listPosts({ amount: 2 }); @@ -149,4 +149,4 @@ describe('list_posts', function(){ '' ].join('')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/list_tags.js b/test/scripts/helpers/list_tags.js index 4ed733d07f..4564051b3b 100644 --- a/test/scripts/helpers/list_tags.js +++ b/test/scripts/helpers/list_tags.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('list_tags', function(){ +describe('list_tags', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var Post = hexo.model('Post'); @@ -17,29 +17,29 @@ describe('list_tags', function(){ var listTags = require('../../../lib/plugins/helper/list_tags').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([ ['foo'], ['baz'], ['baz'], ['bar'] - ], 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 = listTags(); result.should.eql([ @@ -51,7 +51,7 @@ describe('list_tags', function(){ ].join('')); }); - it('specified collection', function(){ + it('specified collection', function() { var result = listTags(Tag.find({ name: /^b/ })); @@ -64,7 +64,7 @@ describe('list_tags', function(){ ].join('')); }); - it('style: false', function(){ + it('style: false', function() { var result = listTags({ style: false }); @@ -76,7 +76,7 @@ describe('list_tags', function(){ ].join(', ')); }); - it('show_count: false', function(){ + it('show_count: false', function() { var result = listTags({ show_count: false }); @@ -90,7 +90,7 @@ describe('list_tags', function(){ ].join('')); }); - it('class', function(){ + it('class', function() { var result = listTags({ class: 'test' }); @@ -104,7 +104,7 @@ describe('list_tags', function(){ ].join('')); }); - it('orderby', function(){ + it('orderby', function() { var result = listTags({ orderby: 'length' }); @@ -118,7 +118,7 @@ describe('list_tags', function(){ ].join('')); }); - it('order', function(){ + it('order', function() { var result = listTags({ order: -1 }); @@ -132,9 +132,9 @@ describe('list_tags', function(){ ].join('')); }); - it('transform', function(){ + it('transform', function() { var result = listTags({ - transform: function(name){ + transform: function(name) { return name.toUpperCase(); } }); @@ -148,7 +148,7 @@ describe('list_tags', function(){ ].join('')); }); - it('separator', function(){ + it('separator', function() { var result = listTags({ style: false, separator: '' @@ -161,7 +161,7 @@ describe('list_tags', function(){ ].join('')); }); - it('amount', function(){ + it('amount', function() { var result = listTags({ amount: 2 }); @@ -173,4 +173,4 @@ describe('list_tags', function(){ '' ].join('')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/mail_to.js b/test/scripts/helpers/mail_to.js index 8e002b0c62..93cb3cf404 100644 --- a/test/scripts/helpers/mail_to.js +++ b/test/scripts/helpers/mail_to.js @@ -1,9 +1,9 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var qs = require('querystring'); -describe('mail_to', function(){ +describe('mail_to', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -15,20 +15,20 @@ describe('mail_to', function(){ var mailto = require('../../../lib/plugins/helper/mail_to').bind(ctx); - it('path', function(){ + it('path', function() { mailto('abc@example.com').should.eql('abc@example.com'); }); - it('text', function(){ + it('text', function() { mailto('abc@example.com', 'Email').should.eql('Email'); }); - it('subject', function(){ + it('subject', function() { mailto('abc@example.com', 'Email', {subject: 'Hello'}) .should.eql('Email'); }); - it('cc (string)', function(){ + it('cc (string)', function() { var data = {cc: 'abc@abc.com'}; var querystring = qs.stringify(data); @@ -36,7 +36,7 @@ describe('mail_to', function(){ .should.eql('Email'); }); - it('cc (array)', function(){ + it('cc (array)', function() { var data = {cc: 'abc@abc.com,bcd@bcd.com'}; var querystring = qs.stringify(data); @@ -44,7 +44,7 @@ describe('mail_to', function(){ .should.eql('Email'); }); - it('bcc (string)', function(){ + it('bcc (string)', function() { var data = {bcc: 'abc@abc.com'}; var querystring = qs.stringify(data); @@ -52,7 +52,7 @@ describe('mail_to', function(){ .should.eql('Email'); }); - it('bcc (array)', function(){ + it('bcc (array)', function() { var data = {bcc: 'abc@abc.com,bcd@bcd.com'}; var querystring = qs.stringify(data); @@ -60,23 +60,23 @@ describe('mail_to', function(){ .should.eql('Email'); }); - it('body', function(){ + it('body', function() { mailto('abc@example.com', 'Email', {body: 'Hello'}) .should.eql('Email'); }); - it('class (string)', function(){ + it('class (string)', function() { mailto('abc@example.com', 'Email', {class: 'foo'}) .should.eql('Email'); }); - it('class (array)', function(){ + it('class (array)', function() { mailto('abc@example.com', 'Email', {class: ['foo', 'bar']}) .should.eql('Email'); }); - it('id', function(){ + it('id', function() { mailto('abc@example.com', 'Email', {id: 'foo'}) .should.eql('Email'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/markdown.js b/test/scripts/helpers/markdown.js index b073801ee8..0e5a54f6a8 100644 --- a/test/scripts/helpers/markdown.js +++ b/test/scripts/helpers/markdown.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('markdown', function(){ +describe('markdown', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); @@ -12,13 +12,13 @@ describe('markdown', function(){ var markdown = require('../../../lib/plugins/helper/markdown').bind(ctx); - 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() { markdown('123456 **bold** and *italic*').should.eql('

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 += ''; } - 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 += ''; } @@ -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('
' + '' + '' + @@ -36,11 +36,11 @@ describe('search_form', function(){ '
'); }); - 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(){ '

Title 2.1

' ].join(''); - var genResult = function(options){ + var genResult = function(options) { options = _.extend({ class: 'toc', list_number: true }, options); - var className = options.class, - listNumber = options.list_number; + var className = options.class; + var listNumber = options.list_number; var result = [ '
    ', @@ -90,11 +90,11 @@ describe('toc', function(){ return result; }; - it('default', function(){ + it('default', function() { genResult().should.eql(toc(html)); }); - it('class', function(){ + it('class', function() { var options = { class: 'foo' }; @@ -102,11 +102,11 @@ describe('toc', function(){ genResult(options).should.eql(toc(html, options)); }); - it('list_number', function(){ + it('list_number', function() { var options = { list_number: false }; genResult(options).should.eql(toc(html, options)); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/helpers/url_for.js b/test/scripts/helpers/url_for.js index de4fe79649..1be9eb3b0e 100644 --- a/test/scripts/helpers/url_for.js +++ b/test/scripts/helpers/url_for.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('url_for', function(){ +describe('url_for', function() { var ctx = { config: {}, relative_url: require('../../../lib/plugins/helper/relative_url') @@ -10,7 +10,7 @@ describe('url_for', function(){ var urlFor = require('../../../lib/plugins/helper/url_for').bind(ctx); - it('internal url (relative off)', function(){ + it('internal url (relative off)', function() { ctx.config.root = '/'; urlFor('index.html').should.eql('/index.html'); urlFor('/').should.eql('/'); @@ -22,7 +22,7 @@ describe('url_for', function(){ urlFor('/index.html').should.eql('/blog/index.html'); }); - it('internal url (relative on)', function(){ + it('internal url (relative on)', function() { ctx.config.relative_link = true; ctx.config.root = '/'; @@ -35,7 +35,7 @@ describe('url_for', function(){ ctx.config.relative_link = false; }); - it('internal url (options.relative)', function(){ + it('internal url (options.relative)', function() { ctx.path = ''; urlFor('index.html', {relative: true}).should.eql('index.html'); @@ -44,11 +44,11 @@ describe('url_for', function(){ ctx.config.relative_link = false; }); - it('external url', function(){ + it('external url', function() { [ 'http://hexo.io/', '//google.com/' - ].forEach(function(url){ + ].forEach(function(url) { urlFor(url).should.eql(url); }); }); diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index 2f98ea0718..55cbe86e54 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.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,7 +8,7 @@ var sinon = require('sinon'); var sep = pathFn.sep; var testUtil = require('../../util'); -describe('Hexo', function(){ +describe('Hexo', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'hexo_test'), {silent: true}); var coreDir = pathFn.join(__dirname, '../../..'); @@ -18,40 +18,41 @@ describe('Hexo', function(){ var Data = hexo.model('Data'); var route = hexo.route; - function checkStream(stream, expected){ - return testUtil.stream.read(stream).then(function(data){ + function checkStream(stream, expected) { + return testUtil.stream.read(stream).then(function(data) { data.should.eql(expected); }); } - function loadAssetGenerator(){ + function loadAssetGenerator() { hexo.extend.generator.register('asset', require('../../../lib/plugins/generator/asset')); } - 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() { // Unregister all generators hexo.extend.generator.store = {}; // Remove all routes route.routes = {}; }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - hexo.extend.console.register('test', function(args){ + hexo.extend.console.register('test', function(args) { return args; }); - it('constructor', function(){ + it('constructor', function() { var hexo = new Hexo(__dirname); + /* eslint-disable no-path-concat */ hexo.core_dir.should.eql(coreDir + sep); hexo.lib_dir.should.eql(pathFn.join(coreDir, 'lib') + sep); hexo.version.should.eql(version); @@ -61,6 +62,7 @@ describe('Hexo', function(){ hexo.plugin_dir.should.eql(pathFn.join(__dirname, 'node_modules') + sep); hexo.script_dir.should.eql(pathFn.join(__dirname, 'scripts') + sep); hexo.scaffold_dir.should.eql(pathFn.join(__dirname, 'scaffolds') + sep); + /* eslint-enable no-path-concat */ hexo.env.should.eql({ args: {}, debug: false, @@ -73,14 +75,14 @@ describe('Hexo', function(){ hexo.config_path.should.eql(pathFn.join(__dirname, '_config.yml')); }); - it('call()', function(){ - return hexo.call('test', {foo: 'bar'}).then(function(data){ + it('call()', function() { + return hexo.call('test', {foo: 'bar'}).then(function(data) { data.should.eql({foo: 'bar'}); }); }); - it('call() - callback', function(callback){ - hexo.call('test', {foo: 'bar'}, function(err, data){ + it('call() - callback', function(callback) { + hexo.call('test', {foo: 'bar'}, function(err, data) { should.not.exist(err); data.should.eql({foo: 'bar'}); @@ -88,30 +90,30 @@ describe('Hexo', function(){ }); }); - it('call() - console not registered', function(){ - var errorCallback = sinon.spy(function(err){ + it('call() - console not registered', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Console `nothing` has not been registered yet!'); }); - return hexo.call('nothing').catch(errorCallback).finally(function(){ + return hexo.call('nothing').catch(errorCallback).finally(function() { errorCallback.calledOnce.should.be.true; }); }); - it('init()', function(){ + it('init()', function() { var hexo = new Hexo(pathFn.join(__dirname, 'hexo_test'), {silent: true}); var hook = sinon.spy(); hexo.extend.filter.register('after_init', hook); - return hexo.init().then(function(){ + return hexo.init().then(function() { hook.calledOnce.should.be.true; }); }); it('model()'); - it('_showDrafts()', function(){ + it('_showDrafts()', function() { hexo._showDrafts().should.be.false; hexo.env.args.draft = true; @@ -127,81 +129,81 @@ describe('Hexo', function(){ hexo.config.render_drafts = false; }); - function testLoad(path){ + function testLoad(path) { var target = pathFn.join(path, 'test.txt'); var body = 'test'; loadAssetGenerator(); - return fs.writeFile(target, body).then(function(){ + return fs.writeFile(target, body).then(function() { return hexo.load(); - }).then(function(){ + }).then(function() { return checkStream(route.get('test.txt'), body); - }).then(function(){ + }).then(function() { return fs.unlink(target); }); } - it('load() - source', function(){ + it('load() - source', function() { return testLoad(hexo.source_dir); }); - it('load() - theme', function(){ + it('load() - theme', function() { return testLoad(pathFn.join(hexo.theme_dir, 'source')); }); - function testWatch(path){ + function testWatch(path) { var target = pathFn.join(path, 'test.txt'); var body = 'test'; var newBody = body + body; loadAssetGenerator(); - return fs.writeFile(target, body).then(function(){ + return fs.writeFile(target, body).then(function() { return hexo.watch(); - }).then(function(){ + }).then(function() { // Test for first generation return checkStream(route.get('test.txt'), body); - }).then(function(){ + }).then(function() { // Update the file return fs.writeFile(target, newBody); - }).delay(300).then(function(){ + }).delay(300).then(function() { // Check the new route return checkStream(route.get('test.txt'), newBody); - }).then(function(){ + }).then(function() { // Stop watching return hexo.unwatch(); - }).then(function(){ + }).then(function() { // Delete the file return fs.unlink(target); }); } - it('watch() - source', function(){ + it('watch() - source', function() { return testWatch(hexo.source_dir); }); - it('watch() - theme', function(){ + it('watch() - theme', function() { return testWatch(pathFn.join(hexo.theme_dir, 'source')); }); it('unwatch()'); - it('exit()', function(){ + it('exit()', function() { var hook = sinon.spy(); var listener = sinon.spy(); hexo.extend.filter.register('before_exit', hook); hexo.once('exit', listener); - return hexo.exit().then(function(){ + return hexo.exit().then(function() { hook.calledOnce.should.be.true; listener.calledOnce.should.be.true; }); }); - it('exit() - error handling', function(callback){ - hexo.once('exit', function(err){ + it('exit() - error handling', function(callback) { + hexo.once('exit', function(err) { err.should.eql({foo: 'bar'}); callback(); }); @@ -209,11 +211,11 @@ describe('Hexo', function(){ return hexo.exit({foo: 'bar'}); }); - it('draft visibility', function(){ + it('draft visibility', function() { return Post.insert([ {source: 'foo', slug: 'foo', published: true}, {source: 'bar', slug: 'bar', published: false} - ]).then(function(posts){ + ]).then(function(posts) { hexo.locals.invalidate(); hexo.locals.get('posts').toArray().should.eql(posts.slice(0, 1)); @@ -224,17 +226,17 @@ describe('Hexo', function(){ hexo.config.render_drafts = false; return posts; - }).map(function(post){ + }).map(function(post) { return Post.removeById(post._id); }); }); - it('future posts', function(){ + it('future posts', function() { return Post.insert([ {source: 'foo', slug: 'foo', date: Date.now() - 3600}, {source: 'bar', slug: 'bar', date: Date.now() + 3600} - ]).then(function(posts){ - function mapper(post){ + ]).then(function(posts) { + function mapper(post) { return post._id; } @@ -249,17 +251,17 @@ describe('Hexo', function(){ hexo.locals.get('posts').map(mapper).should.eql([posts[0]._id]); return posts; - }).map(function(post){ + }).map(function(post) { return Post.removeById(post._id); }); }); - it('future pages', function(){ + it('future pages', function() { return Page.insert([ {source: 'foo', path: 'foo', date: Date.now() - 3600}, {source: 'bar', path: 'bar', date: Date.now() + 3600} - ]).then(function(pages){ - function mapper(page){ + ]).then(function(pages) { + function mapper(page) { return page._id; } @@ -274,16 +276,16 @@ describe('Hexo', function(){ hexo.locals.get('pages').map(mapper).should.eql([pages[0]._id]); return pages; - }).map(function(page){ + }).map(function(page) { return Page.removeById(page._id); }); }); - it('locals.data', function(){ + it('locals.data', function() { return Data.insert([ {_id: 'users', data: {foo: 1}}, {_id: 'comments', data: {bar: 2}} - ]).then(function(data){ + ]).then(function(data) { hexo.locals.invalidate(); hexo.locals.get('data').should.eql({ users: {foo: 1}, @@ -291,14 +293,14 @@ describe('Hexo', function(){ }); return data; - }).map(function(data){ + }).map(function(data) { return data.remove(); }); }); - it('_generate()', function(){ + it('_generate()', function() { // object - hexo.extend.generator.register('test_obj', function(locals){ + hexo.extend.generator.register('test_obj', function(locals) { locals.test.should.eql('foo'); return { @@ -308,7 +310,7 @@ describe('Hexo', function(){ }); // array - hexo.extend.generator.register('test_arr', function(locals){ + hexo.extend.generator.register('test_arr', function(locals) { locals.test.should.eql('foo'); return [ @@ -321,7 +323,7 @@ describe('Hexo', function(){ var afterListener = sinon.spy(); var afterHook = sinon.spy(); - var beforeHook = sinon.spy(function(){ + var beforeHook = sinon.spy(function() { hexo.locals.set('test', 'foo'); }); @@ -330,7 +332,7 @@ describe('Hexo', function(){ hexo.extend.filter.register('before_generate', beforeHook); hexo.extend.filter.register('after_generate', afterHook); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { route.list().should.eql(['foo', 'bar', 'baz']); beforeListener.calledOnce.should.be.true; @@ -346,7 +348,7 @@ describe('Hexo', function(){ }); }); - it('_generate() - layout', function(){ + it('_generate() - layout', function() { hexo.theme.setView('test.swig', [ '{{ config.title }}', '{{ page.foo }}', @@ -354,7 +356,7 @@ describe('Hexo', function(){ '{{ view_dir }}' ].join('\n')); - hexo.extend.generator.register('test', function(){ + hexo.extend.generator.register('test', function() { return { path: 'test', layout: 'test', @@ -371,41 +373,41 @@ describe('Hexo', function(){ pathFn.join(hexo.theme_dir, 'layout') + pathFn.sep ].join('\n'); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { return checkStream(route.get('test'), expected); }); }); - it('_generate() - layout array', function(){ + it('_generate() - layout array', function() { hexo.theme.setView('baz.swig', 'baz'); - hexo.extend.generator.register('test', function(){ + hexo.extend.generator.register('test', function() { return { path: 'test', layout: ['foo', 'bar', 'baz'] }; }); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { return checkStream(route.get('test'), 'baz'); }); }); - it('_generate() - layout not exist', function(){ - hexo.extend.generator.register('test', function(){ + it('_generate() - layout not exist', function() { + hexo.extend.generator.register('test', function() { return { path: 'test', layout: 'nothing' }; }); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { return checkStream(route.get('test'), ''); }); }); - it('_generate() - remove old routes', function(){ - hexo.extend.generator.register('test', function(){ + it('_generate() - remove old routes', function() { + hexo.extend.generator.register('test', function() { return { path: 'bar', data: 'newbar' @@ -416,7 +418,7 @@ describe('Hexo', function(){ route.set('bar', 'bar'); route.set('baz', 'baz'); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { should.not.exist(route.get('foo')); should.not.exist(route.get('baz')); @@ -424,38 +426,38 @@ describe('Hexo', function(){ }); }); - it('_generate() - return nothing in generator', function(){ - hexo.extend.generator.register('test_nothing', function(){ + it('_generate() - return nothing in generator', function() { + hexo.extend.generator.register('test_nothing', function() { // }); - hexo.extend.generator.register('test_normal', function(){ + hexo.extend.generator.register('test_normal', function() { return { path: 'bar', data: 'bar' }; }); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { return checkStream(route.get('bar'), 'bar'); }); }); - it('_generate() - validate locals', function(){ + it('_generate() - validate locals', function() { hexo.theme.setView('test.swig', [ '{{ path }}', '{{ url }}', '{{ view_dir }}' ].join('\n')); - hexo.extend.generator.register('test', function(){ + hexo.extend.generator.register('test', function() { return { path: 'test', layout: 'test' }; }); - return hexo._generate().then(function(){ + return hexo._generate().then(function() { return checkStream(route.get('test'), [ 'test', hexo.config.url + '/test', @@ -464,7 +466,7 @@ describe('Hexo', function(){ }); }); - it('_generate() - do nothing if it\'s generating', function(){ + it('_generate() - do nothing if it\'s generating', function() { var spy = sinon.spy(); hexo.extend.generator.register('test', spy); @@ -474,12 +476,12 @@ describe('Hexo', function(){ hexo._isGenerating = false; }); - it('_generate() - reset cache for new route', function(){ + it('_generate() - reset cache for new route', function() { var count = 0; hexo.theme.setView('test.swig', '{{ page.count }}'); - hexo.extend.generator.register('test', function(){ + hexo.extend.generator.register('test', function() { return { path: 'test', layout: 'test', @@ -488,51 +490,51 @@ describe('Hexo', function(){ }); // First generation - return hexo._generate({cache: true}).then(function(){ + return hexo._generate({cache: true}).then(function() { return checkStream(route.get('test'), '0'); - }).then(function(){ + }).then(function() { // Second generation return hexo._generate({cache: true}); - }).then(function(){ + }).then(function() { return checkStream(route.get('test'), '1'); }); }); - it('_generate() - cache disabled & update template', function(){ + it('_generate() - cache disabled & update template', function() { hexo.theme.setView('test.swig', '0'); - hexo.extend.generator.register('test', function(){ + hexo.extend.generator.register('test', function() { return { path: 'test', layout: 'test' }; }); - return hexo._generate({cache: false}).then(function(){ + return hexo._generate({cache: false}).then(function() { return checkStream(route.get('test'), '0'); - }).then(function(){ + }).then(function() { hexo.theme.setView('test.swig', '1'); return checkStream(route.get('test'), '1'); }); }); - it('execFilter()', function(){ - hexo.extend.filter.register('exec_test', function(data){ + it('execFilter()', function() { + hexo.extend.filter.register('exec_test', function(data) { data.should.eql(''); return data + 'foo'; }); - return hexo.execFilter('exec_test', '').then(function(result){ + return hexo.execFilter('exec_test', '').then(function(result) { result.should.eql('foo'); }); }); - it('execFilterSync()', function(){ - hexo.extend.filter.register('exec_sync_test', function(data){ + it('execFilterSync()', function() { + hexo.extend.filter.register('exec_sync_test', function(data) { data.should.eql(''); return data + 'foo'; }); hexo.execFilterSync('exec_sync_test', '').should.eql('foo'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/index.js b/test/scripts/hexo/index.js index e7a3e9f913..85b2a4f46c 100644 --- a/test/scripts/hexo/index.js +++ b/test/scripts/hexo/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Core', function(){ +describe('Core', function() { require('./hexo'); require('./load_config'); require('./load_database'); @@ -10,5 +10,5 @@ describe('Core', function(){ require('./render'); require('./router'); require('./scaffold'); - require('./update_package') -}); \ No newline at end of file + require('./update_package'); +}); diff --git a/test/scripts/hexo/load_config.js b/test/scripts/hexo/load_config.js index cbaa99f22a..bcb55ab3c3 100644 --- a/test/scripts/hexo/load_config.js +++ b/test/scripts/hexo/load_config.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 _ = require('lodash'); -describe('Load config', function(){ +describe('Load config', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); var loadConfig = require('../../../lib/hexo/load_config'); @@ -13,32 +13,32 @@ describe('Load config', function(){ hexo.env.init = true; - function reset(){ + function reset() { hexo.config = _.clone(defaultConfig); } - 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); }); - it('config file does not exist', function(){ - return loadConfig(hexo).then(function(){ + it('config file does not exist', function() { + return loadConfig(hexo).then(function() { hexo.config.should.eql(defaultConfig); }); }); - it('_config.yml exists', function(){ + it('_config.yml exists', function() { var configPath = pathFn.join(hexo.base_dir, '_config.yml'); - return fs.writeFile(configPath, 'foo: 1').then(function(){ + return fs.writeFile(configPath, 'foo: 1').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.foo.should.eql(1); reset(); @@ -46,12 +46,12 @@ describe('Load config', function(){ }); }); - it('_config.json exists', function(){ + it('_config.json exists', function() { var configPath = pathFn.join(hexo.base_dir, '_config.json'); - return fs.writeFile(configPath, '{"baz": 3}').then(function(){ + return fs.writeFile(configPath, '{"baz": 3}').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.baz.should.eql(3); reset(); @@ -59,12 +59,12 @@ describe('Load config', function(){ }); }); - it('_config.txt exists', function(){ + it('_config.txt exists', function() { var configPath = pathFn.join(hexo.base_dir, '_config.txt'); - return fs.writeFile(configPath, 'foo: 1').then(function(){ + return fs.writeFile(configPath, 'foo: 1').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.should.eql(defaultConfig); reset(); @@ -72,12 +72,12 @@ describe('Load config', function(){ }); }); - it('custom config path', function(){ + it('custom config path', function() { var configPath = hexo.config_path = pathFn.join(__dirname, 'werwerwer.yml'); - return fs.writeFile(configPath, 'foo: 1').then(function(){ + return fs.writeFile(configPath, 'foo: 1').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.foo.should.eql(1); reset(); @@ -86,13 +86,13 @@ describe('Load config', function(){ }); }); - it('custom config path with different extension name', function(){ - var configPath = hexo.config_path = pathFn.join(__dirname, 'werwerwer.yml'); + it('custom config path with different extension name', function() { var realPath = pathFn.join(__dirname, 'werwerwer.json'); + hexo.config_path = pathFn.join(__dirname, 'werwerwer.yml'); - return fs.writeFile(realPath, '{"foo": 2}').then(function(){ + return fs.writeFile(realPath, '{"foo": 2}').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.foo.should.eql(2); hexo.config_path.should.eql(realPath); @@ -102,15 +102,15 @@ describe('Load config', function(){ }); }); - it('handle trailing "/" of url', function(){ + it('handle trailing "/" of url', function() { var content = [ 'root: foo', 'url: http://hexo.io/' ].join('\n'); - return fs.writeFile(hexo.config_path, content).then(function(){ + return fs.writeFile(hexo.config_path, content).then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.root.should.eql('foo/'); hexo.config.url.should.eql('http://hexo.io'); @@ -119,10 +119,10 @@ describe('Load config', function(){ }); }); - it('custom public_dir', function(){ - return fs.writeFile(hexo.config_path, 'public_dir: foo').then(function(){ + it('custom public_dir', function() { + return fs.writeFile(hexo.config_path, 'public_dir: foo').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.public_dir.should.eql(pathFn.resolve(hexo.base_dir, 'foo') + pathFn.sep); reset(); @@ -130,10 +130,10 @@ describe('Load config', function(){ }); }); - it('custom source_dir', function(){ - return fs.writeFile(hexo.config_path, 'source_dir: bar').then(function(){ + it('custom source_dir', function() { + return fs.writeFile(hexo.config_path, 'source_dir: bar').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.source_dir.should.eql(pathFn.resolve(hexo.base_dir, 'bar') + pathFn.sep); reset(); @@ -141,10 +141,10 @@ describe('Load config', function(){ }); }); - it('custom theme', function(){ - return fs.writeFile(hexo.config_path, 'theme: test').then(function(){ + it('custom theme', function() { + return fs.writeFile(hexo.config_path, 'theme: test').then(function() { return loadConfig(hexo); - }).then(function(){ + }).then(function() { hexo.config.theme.should.eql('test'); hexo.theme_dir.should.eql(pathFn.join(hexo.base_dir, 'themes', 'test') + pathFn.sep); hexo.theme_script_dir.should.eql(pathFn.join(hexo.theme_dir, 'scripts') + pathFn.sep); @@ -154,4 +154,4 @@ describe('Load config', function(){ return fs.unlink(hexo.config_path); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/load_database.js b/test/scripts/hexo/load_database.js index d97ffc9b57..ace8420265 100644 --- a/test/scripts/hexo/load_database.js +++ b/test/scripts/hexo/load_database.js @@ -1,10 +1,10 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); -describe('Load database', function(){ +describe('Load database', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'db_test'), {silent: true}); var loadDatabase = require('../../../lib/hexo/load_database'); @@ -17,33 +17,33 @@ describe('Load database', function(){ }, models: { Test: [ - {_id: "A"}, - {_id: "B"}, - {_id: "C"} + {_id: 'A'}, + {_id: 'B'}, + {_id: 'C'} ] } }; - before(function(){ + before(function() { return fs.mkdirs(hexo.base_dir); }); - beforeEach(function(){ + beforeEach(function() { hexo._dbLoaded = false; }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('database does not exist', function(){ + it('database does not exist', function() { return loadDatabase(hexo); }); - it('database load success', function(){ - return fs.writeFile(dbPath, JSON.stringify(fixture)).then(function(){ + it('database load success', function() { + return fs.writeFile(dbPath, JSON.stringify(fixture)).then(function() { return loadDatabase(hexo); - }).then(function(){ + }).then(function() { hexo._dbLoaded.should.be.true; hexo.model('Test').toArray({lean: true}).should.eql(fixture.models.Test); hexo.model('Test').destroy(); @@ -52,12 +52,12 @@ describe('Load database', function(){ }); }); - it('don\'t load database if loaded', function(){ + it('don\'t load database if loaded', function() { hexo._dbLoaded = true; - return fs.writeFile(dbPath, JSON.stringify(fixture)).then(function(){ + return fs.writeFile(dbPath, JSON.stringify(fixture)).then(function() { return loadDatabase(hexo); - }).then(function(){ + }).then(function() { hexo.model('Test').length.should.eql(0); return fs.unlink(dbPath); }); @@ -65,14 +65,14 @@ describe('Load database', function(){ // I don't know why this test case can't pass on Windows // It always throws EPERM error - it.skip('database load failed', function(){ - return fs.writeFile(dbPath, '{1423432: 324').then(function(){ + it.skip('database load failed', function() { + return fs.writeFile(dbPath, '{1423432: 324').then(function() { return loadDatabase(hexo); - }).then(function(){ + }).then(function() { hexo._dbLoaded.should.be.false; return fs.exists(dbPath); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.false; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/load_plugins.js b/test/scripts/hexo/load_plugins.js index f12f724400..55685a5213 100644 --- a/test/scripts/hexo/load_plugins.js +++ b/test/scripts/hexo/load_plugins.js @@ -1,11 +1,11 @@ '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('Load plugins', function(){ +describe('Load plugins', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'plugin_test'), {silent: true}); var loadPlugins = require('../../../lib/hexo/load_plugins'); @@ -19,7 +19,7 @@ describe('Load plugins', function(){ '}' ].join('\n'); - function validate(path){ + function validate(path) { var result = hexo._script_test; result.filename.should.eql(path); @@ -30,7 +30,7 @@ describe('Load plugins', function(){ delete hexo._script_test; } - function createPackageFile(){ + function createPackageFile() { var pkg = { name: 'hexo-site', version: '0.0.0', @@ -38,7 +38,7 @@ describe('Load plugins', function(){ dependencies: {} }; - for (var i = 0, len = arguments.length; i < len; i++){ + for (var i = 0, len = arguments.length; i < len; i++) { pkg.dependencies[arguments[i]] = '*'; } @@ -48,30 +48,30 @@ describe('Load plugins', function(){ hexo.env.init = true; hexo.theme_script_dir = pathFn.join(hexo.base_dir, 'themes', 'test', 'scripts'); - before(function(){ + before(function() { return fs.mkdir(hexo.base_dir); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('load plugins', function(){ + it('load plugins', function() { var name = 'hexo-plugin-test'; var path = pathFn.join(hexo.plugin_dir, name, 'index.js'); return Promise.all([ createPackageFile(name), fs.writeFile(path, script) - ]).then(function(){ + ]).then(function() { return loadPlugins(hexo); - }).then(function(){ + }).then(function() { validate(path); return fs.unlink(path); }); }); - it('ignore plugins whose name is not started with "hexo-"', function(){ + it('ignore plugins whose name is not started with "hexo-"', function() { var script = 'hexo._script_test = true'; var name = 'another-plugin'; var path = pathFn.join(hexo.plugin_dir, name, 'index.js'); @@ -79,53 +79,53 @@ describe('Load plugins', function(){ return Promise.all([ createPackageFile(name), fs.writeFile(path, script) - ]).then(function(){ + ]).then(function() { return loadPlugins(hexo); - }).then(function(){ + }).then(function() { should.not.exist(hexo._script_test); return fs.unlink(path); }); }); - it('ignore plugins which are in package.json but not exist actually', function(){ - return createPackageFile('hexo-plugin-test').then(function(){ + it('ignore plugins which are in package.json but not exist actually', function() { + return createPackageFile('hexo-plugin-test').then(function() { return loadPlugins(hexo); }); }); - it('load scripts', function(){ + it('load scripts', function() { var path = pathFn.join(hexo.script_dir, 'test.js'); - return fs.writeFile(path, script).then(function(){ + return fs.writeFile(path, script).then(function() { return loadPlugins(hexo); - }).then(function(){ + }).then(function() { validate(path); return fs.unlink(path); }); }); - it('load theme scripts', function(){ + it('load theme scripts', function() { var path = pathFn.join(hexo.theme_script_dir, 'test.js'); - return fs.writeFile(path, script).then(function(){ + return fs.writeFile(path, script).then(function() { return loadPlugins(hexo); - }).then(function(){ + }).then(function() { validate(path); return fs.unlink(path); }); }); - it('don\'t load plugins in safe mode', function(){ + it('don\'t load plugins in safe mode', function() { var script = 'hexo._script_test = true'; var path = pathFn.join(hexo.script_dir, 'test.js'); - return fs.writeFile(path, script).then(function(){ + return fs.writeFile(path, script).then(function() { hexo.env.safe = true; return loadPlugins(hexo); - }).then(function(){ + }).then(function() { hexo.env.safe = false; should.not.exist(hexo._script_test); return fs.unlink(path); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/locals.js b/test/scripts/hexo/locals.js index 9b51b19877..9d039503ee 100644 --- a/test/scripts/hexo/locals.js +++ b/test/scripts/hexo/locals.js @@ -1,28 +1,28 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); -describe('Locals', function(){ +describe('Locals', function() { var Locals = require('../../../lib/hexo/locals'); var locals = new Locals(); - it('get() - name must be a string', function(){ + it('get() - name must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'name must be a string!'); }); try { locals.get(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('set() - function', function(){ - locals.set('foo', function(){ + it('set() - function', function() { + locals.set('foo', function() { return 'foo'; }); @@ -33,40 +33,40 @@ describe('Locals', function(){ locals.cache.foo.should.eql('foo'); }); - it('set() - not function', function(){ + it('set() - not function', function() { locals.set('foo', 'foo'); locals.get('foo').should.eql('foo'); }); - it('set() - name must be a string', function(){ + it('set() - name must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'name must be a string!'); }); try { locals.set(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('set() - value is required', function(){ + it('set() - value is required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'value is required!'); }); try { locals.set('test'); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('remove()', function(){ + it('remove()', function() { locals.set('foo', 'foo'); locals.get('foo'); locals.remove('foo'); @@ -75,21 +75,21 @@ describe('Locals', function(){ should.not.exist(locals.cache.foo); }); - it('remove() - name must be a string', function(){ + it('remove() - name must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'name must be a string!'); }); try { locals.remove(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('toObject()', function(){ + it('toObject()', function() { var locals = new Locals(); locals.set('foo', 'foo'); @@ -98,11 +98,11 @@ describe('Locals', function(){ locals.toObject().should.eql({foo: 'foo'}); }); - it('invalidate()', function(){ + it('invalidate()', function() { locals.set('foo', 'foo'); locals.get('foo'); locals.invalidate(); should.not.exist(locals.cache.foo); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index c8a5e1d465..ca28509485 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.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 moment = require('moment'); var Promise = require('bluebird'); @@ -10,29 +10,29 @@ var sinon = require('sinon'); var frontMatter = require('hexo-front-matter'); var fixture = require('../../fixtures/post_render'); -describe('Post', function(){ +describe('Post', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'post_test')); var post = hexo.post; var now = Date.now(); var clock; - before(function(){ + before(function() { clock = sinon.useFakeTimers(now); - return fs.mkdirs(hexo.base_dir, function(){ + return fs.mkdirs(hexo.base_dir, function() { return hexo.init(); - }).then(function(){ + }).then(function() { // Load marked renderer for testing return hexo.loadPlugin(require.resolve('hexo-renderer-marked')); - }).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:', @@ -41,12 +41,12 @@ describe('Post', function(){ }); }); - after(function(){ + after(function() { clock.restore(); return fs.rmdir(hexo.base_dir); }); - it('create()', function(){ + it('create()', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); var listener = sinon.spy(); @@ -62,19 +62,19 @@ describe('Post', function(){ return post.create({ title: 'Hello World' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); listener.calledOnce.should.be.true; return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - slug', function(){ + it('create() - slug', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'foo.md'); var date = moment(now); @@ -88,18 +88,18 @@ describe('Post', function(){ return post.create({ title: 'Hello World', slug: 'foo' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - filename_case', function(){ + it('create() - filename_case', function() { hexo.config.filename_case = 1; var path = pathFn.join(hexo.source_dir, '_posts', 'hello-world.md'); @@ -114,19 +114,19 @@ describe('Post', function(){ return post.create({ title: 'Hello World' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); hexo.config.filename_case = 0; return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - layout', function(){ + it('create() - layout', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -141,18 +141,18 @@ describe('Post', function(){ return post.create({ title: 'Hello World', layout: 'photo' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - extra data', function(){ + it('create() - extra data', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -167,30 +167,30 @@ describe('Post', function(){ return post.create({ title: 'Hello World', foo: 'bar' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - rename if target existed', function(){ + it('create() - 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 post.create({ title: 'Hello World' }); - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); return fs.exists(path); - }).then(function(exist){ + }).then(function(exist) { exist.should.be.true; return Promise.all([ @@ -200,50 +200,50 @@ describe('Post', function(){ }); }); - it('create() - replace existing files', function(){ + it('create() - 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 post.create({ title: 'Hello World' }, true); - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); return fs.unlink(path); }); }); - it('create() - asset folder', function(){ + it('create() - asset folder', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World'); hexo.config.post_asset_folder = true; return post.create({ title: 'Hello World' - }).then(function(post){ + }).then(function(post) { hexo.config.post_asset_folder = false; return fs.stat(path); - }).then(function(stats){ + }).then(function(stats) { stats.isDirectory().should.be.true; return fs.unlink(path + '.md'); }); }); - it('create() - follow the separator style in the scaffold', function(){ + it('create() - follow the separator style in the scaffold', function() { var scaffold = [ '---', 'title: {{ title }}', '---' ].join('\n'); - return hexo.scaffold.set('test', scaffold).then(function(){ + return hexo.scaffold.set('test', scaffold).then(function() { return post.create({ title: 'Hello World', layout: 'test' }); - }).then(function(post){ + }).then(function(post) { post.content.should.eql([ '---', 'title: Hello World', @@ -257,19 +257,19 @@ describe('Post', function(){ }); }); - it('create() - JSON front-matter', function(){ + it('create() - JSON front-matter', function() { var scaffold = [ '"title": {{ title }}', ';;;' ].join('\n'); - return hexo.scaffold.set('test', scaffold).then(function(){ + return hexo.scaffold.set('test', scaffold).then(function() { return post.create({ title: 'Hello World', layout: 'test', lang: 'en' }); - }).then(function(post){ + }).then(function(post) { post.content.should.eql([ '"title": "Hello World",', '"lang": "en"', @@ -284,21 +284,21 @@ describe('Post', function(){ }); // https://github.com/hexojs/hexo/issues/1100 - it('create() - non-string title', function(){ + it('create() - non-string title', function() { var path = pathFn.join(hexo.source_dir, '_posts', '12345.md'); return post.create({ title: 12345 - }).then(function(data){ + }).then(function(data) { data.path.should.eql(path); return fs.unlink(path); }); }); - it('create() - escape title', function(){ + it('create() - escape title', function() { return post.create({ title: 'Foo: Bar' - }).then(function(data){ + }).then(function(data) { data.content.should.eql([ // js-yaml use single-quotation for dumping since 3.3 'title: \'Foo: Bar\'', @@ -310,7 +310,7 @@ describe('Post', function(){ }); }); - it('create() - with content', function(){ + it('create() - with content', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -326,24 +326,20 @@ describe('Post', function(){ return post.create({ title: 'Hello World', content: 'Hello hexo' - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('create() - with callback', function(){ + it('create() - with callback', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); - var callback = sinon.spy(function(post) { - post.path.should.eql(path); - post.content.should.eql(content); - }); var content = [ 'title: Hello World', @@ -352,18 +348,23 @@ describe('Post', function(){ '---' ].join('\n') + '\n'; + var callback = sinon.spy(function(post) { + post.path.should.eql(path); + post.content.should.eql(content); + }); + return post.create({ title: 'Hello World' - }, callback).then(function(post){ + }, callback).then(function(post) { callback.calledOnce.should.be.true; return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('publish()', function(){ + it('publish()', function() { var draftPath = ''; var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -378,13 +379,13 @@ describe('Post', function(){ return post.create({ title: 'Hello World', layout: 'draft' - }).then(function(data){ + }).then(function(data) { draftPath = data.path; return post.publish({ slug: 'Hello-World' }); - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); @@ -392,7 +393,7 @@ describe('Post', function(){ fs.exists(draftPath), fs.readFile(path) ]); - }).spread(function(exist, data){ + }).spread(function(exist, data) { exist.should.be.false; data.should.eql(content); @@ -400,7 +401,7 @@ describe('Post', function(){ }); }); - it('publish() - layout', function(){ + it('publish() - layout', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); @@ -415,60 +416,60 @@ describe('Post', function(){ return post.create({ title: 'Hello World', layout: 'draft' - }).then(function(data){ + }).then(function(data) { return post.publish({ slug: 'Hello-World', layout: 'photo' }); - }).then(function(post){ + }).then(function(post) { post.path.should.eql(path); post.content.should.eql(content); return fs.readFile(path); - }).then(function(data){ + }).then(function(data) { data.should.eql(content); return fs.unlink(path); }); }); - it('publish() - rename if target existed', function(){ + it('publish() - rename if target existed', function() { var paths = [pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md')]; return Promise.all([ post.create({title: 'Hello World', layout: 'draft'}), post.create({title: 'Hello World'}) - ]).then(function(data){ + ]).then(function(data) { paths.push(data[1].path); return post.publish({ slug: 'Hello-World' }); - }).then(function(data){ + }).then(function(data) { data.path.should.eql(paths[0]); return paths; - }).map(function(item){ + }).map(function(item) { return fs.unlink(item); }); }); - it('publish() - replace existing files', function(){ + it('publish() - replace existing files', function() { var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); return Promise.all([ post.create({title: 'Hello World', layout: 'draft'}), post.create({title: 'Hello World'}) - ]).then(function(data){ + ]).then(function(data) { return post.publish({ slug: 'Hello-World' }, true); - }).then(function(data){ + }).then(function(data) { data.path.should.eql(path); return fs.unlink(path); }); }); - it('publish() - asset folder', function(){ + it('publish() - asset folder', function() { var assetDir = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World'); var newAssetDir = pathFn.join(hexo.source_dir, '_posts', 'Hello-World'); hexo.config.post_asset_folder = true; @@ -476,23 +477,23 @@ describe('Post', function(){ return post.create({ title: 'Hello World', layout: 'draft' - }).then(function(data){ + }).then(function(data) { // Put some files into the asset folder return Promise.all([ fs.writeFile(pathFn.join(assetDir, 'a.txt'), 'a'), fs.writeFile(pathFn.join(assetDir, 'b.txt'), 'b') ]); - }).then(function(){ + }).then(function() { return post.publish({ slug: 'Hello-World' }); - }).then(function(post){ + }).then(function(post) { return Promise.all([ fs.exists(assetDir), fs.listDir(newAssetDir), fs.unlink(post.path) ]); - }).spread(function(exist, files){ + }).spread(function(exist, files) { hexo.config.post_asset_folder = false; exist.should.be.false; files.should.have.members(['a.txt', 'b.txt']); @@ -501,30 +502,26 @@ describe('Post', function(){ }); // https://github.com/hexojs/hexo/issues/1100 - it('publish() - non-string title', function(){ + it('publish() - non-string title', function() { var path = pathFn.join(hexo.source_dir, '_posts', '12345.md'); return post.create({ title: 12345, layout: 'draft' - }).then(function(data){ + }).then(function(data) { return post.publish({ slug: 12345 }); - }).then(function(data){ + }).then(function(data) { data.path.should.eql(path); return fs.unlink(path); }); }); - it('publish() - with callback', function(){ + it('publish() - with callback', function() { var draftPath = ''; var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); var date = moment(now); - var callback = sinon.spy(function(post) { - post.path.should.eql(path); - post.content.should.eql(content); - }); var content = [ 'title: Hello World', @@ -533,23 +530,28 @@ describe('Post', function(){ '---' ].join('\n') + '\n'; + var callback = sinon.spy(function(post) { + post.path.should.eql(path); + post.content.should.eql(content); + }); + return post.create({ title: 'Hello World', layout: 'draft' - }).then(function(data){ + }).then(function(data) { draftPath = data.path; return post.publish({ slug: 'Hello-World' }, callback); - }).then(function(post){ + }).then(function(post) { callback.calledOnce.should.be.true; 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); @@ -558,23 +560,23 @@ describe('Post', function(){ }); // https://github.com/hexojs/hexo/issues/1139 - it('publish() - preserve non-null data in drafts', function(){ + it('publish() - preserve non-null data in drafts', function() { return post.create({ title: 'foo', layout: 'draft', tags: ['tag', 'test'] - }).then(function(data){ + }).then(function(data) { return post.publish({ slug: 'foo' }); - }).then(function(data){ + }).then(function(data) { var meta = frontMatter(data.content); meta.tags.should.eql(['tag', 'test']); return fs.unlink(data.path); }); }); - it('render()', function(){ + it('render()', function() { // TODO: validate data var beforeHook = sinon.spy(); var afterHook = sinon.spy(); @@ -585,37 +587,37 @@ describe('Post', function(){ return post.render(null, { content: fixture.content, engine: 'markdown' - }).then(function(data){ + }).then(function(data) { data.content.trim().should.eql(fixture.expected); beforeHook.calledOnce.should.be.true; afterHook.calledOnce.should.be.true; }); }); - it('render() - file', function(){ + it('render() - file', function() { var content = '**file test**'; var path = pathFn.join(hexo.base_dir, 'render_test.md'); - return fs.writeFile(path, content).then(function(){ + return fs.writeFile(path, content).then(function() { return post.render(path); - }).then(function(data){ + }).then(function(data) { data.content.trim().should.eql('

    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([ '

    quote content

    \n', '
    Hello World
    ' @@ -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('

    {{ test }}

    '); }); }); - it('render() - recover escaped swig blocks which is html escaped before post_render', function(){ + it('render() - recover escaped swig blocks which is html escaped before post_render', function() { var content = '`{% raw %}{{ test }}{% endraw %}`'; var filter = sinon.spy(function(result) { result.trim().should.eql('

    {{ test }}

    '); }); + hexo.extend.filter.register('after_render:html', filter); return post.render(null, { content: content, engine: 'markdown' - }).then(function(data){ + }).then(function(data) { filter.calledOnce.should.be.true; hexo.extend.filter.unregister('after_render:html', filter); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/render.js b/test/scripts/hexo/render.js index b9e37fea7f..68dd100bf5 100644 --- a/test/scripts/hexo/render.js +++ b/test/scripts/hexo/render.js @@ -2,11 +2,10 @@ var fs = require('hexo-fs'); var pathFn = require('path'); -var Promise = require('bluebird'); var yaml = require('js-yaml'); var sinon = require('sinon'); -describe('Render', function(){ +describe('Render', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(pathFn.join(__dirname, 'render_test')); @@ -25,17 +24,17 @@ describe('Render', function(){ var obj = yaml.load(body); var path = pathFn.join(hexo.base_dir, 'test.yml'); - before(function(){ - return fs.writeFile(path, body).then(function(){ + before(function() { + return fs.writeFile(path, body).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(hexo.base_dir); }); - it('isRenderable()', function(){ + it('isRenderable()', function() { hexo.render.isRenderable('test.txt').should.be.false; // html @@ -50,7 +49,7 @@ describe('Render', function(){ hexo.render.isRenderable('test.yaml').should.be.true; }); - it('isRenderableSync()', function(){ + it('isRenderableSync()', function() { hexo.render.isRenderableSync('test.txt').should.be.false; // html @@ -65,7 +64,7 @@ describe('Render', function(){ hexo.render.isRenderableSync('test.yaml').should.be.true; }); - it('getOutput()', function(){ + it('getOutput()', function() { hexo.render.getOutput('test.txt').should.not.ok; // html @@ -80,35 +79,35 @@ describe('Render', function(){ hexo.render.getOutput('test.yaml').should.eql('json'); }); - it('render() - path', function(){ - return hexo.render.render({path: path}).then(function(result){ + it('render() - path', function() { + return hexo.render.render({path: path}).then(function(result) { result.should.eql(obj); }); }); - it('render() - text (without engine)', function(){ - return hexo.render.render({text: body}).then(function(result){ + it('render() - text (without engine)', function() { + return hexo.render.render({text: body}).then(function(result) { result.should.eql(body); }); }); - it('render() - text (with engine)', function(){ - return hexo.render.render({text: body, engine: 'yaml'}).then(function(result){ + it('render() - text (with engine)', function() { + return hexo.render.render({text: body, engine: 'yaml'}).then(function(result) { result.should.eql(obj); }); }); - it('render() - no path and text', function(){ - var errorCallback = sinon.spy(function(err){ + it('render() - no path and text', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'No input file or string!'); - }) + }); return hexo.render.render().catch(errorCallback).finally(function() { errorCallback.calledOnce.should.be.true; }); }); - it('render() - options', function(){ + it('render() - options', function() { return hexo.render.render({ text: [ '{{ title }}', @@ -118,7 +117,7 @@ describe('Render', function(){ }, { title: 'Hello world', content: 'foobar' - }).then(function(result){ + }).then(function(result) { result.should.eql([ 'Hello world', 'foobar' @@ -126,35 +125,35 @@ describe('Render', function(){ }); }); - it('render() - toString', function(){ + it('render() - toString', function() { return hexo.render.render({ text: body, engine: 'yaml', toString: true - }).then(function(content){ + }).then(function(content) { content.should.eql(JSON.stringify(obj)); }); }); - it('render() - custom toString method', function(){ + it('render() - custom toString method', function() { return hexo.render.render({ text: body, engine: 'yaml', - toString: function(data){ + toString: function(data) { return JSON.stringify(data, null, ' '); } - }).then(function(content){ + }).then(function(content) { content.should.eql(JSON.stringify(obj, null, ' ')); }); }); - it('render() - after_render filter', function(){ + it('render() - after_render filter', function() { var data = { text: ' 123456 ', engine: 'swig' }; - var filter = sinon.spy(function(result, obj){ + var filter = sinon.spy(function(result, obj) { result.should.eql(data.text); obj.should.eql(data); return result.trim(); @@ -162,7 +161,7 @@ describe('Render', function(){ hexo.extend.filter.register('after_render:html', filter); - return hexo.render.render(data).then(function(result){ + return hexo.render.render(data).then(function(result) { filter.calledOnce.should.be.true; result.should.eql(data.text.trim()); @@ -170,7 +169,7 @@ describe('Render', function(){ }); }); - it('render() - after_render filter: use the given output extension if not found', function(){ + it('render() - after_render filter: use the given output extension if not found', function() { var data = { text: 'foo', engine: 'txt' @@ -179,7 +178,7 @@ describe('Render', function(){ var filter = sinon.spy(); hexo.extend.filter.register('after_render:txt', filter); - return hexo.render.render(data).then(function(result){ + return hexo.render.render(data).then(function(result) { filter.calledOnce.should.be.true; hexo.extend.filter.unregister('after_render:txt', filter); }); @@ -189,6 +188,7 @@ describe('Render', function(){ var onRenderEnd = sinon.spy(function(result) { return result + 'bar'; }); + var data = { text: 'foo', engine: 'txt', @@ -198,9 +198,10 @@ describe('Render', function(){ var filter = sinon.spy(function(result) { result.should.eql('foobar'); }); + hexo.extend.filter.register('after_render:txt', filter); - return hexo.render.render(data).then(function(result){ + return hexo.render.render(data).then(function(result) { onRenderEnd.calledOnce.should.be.true; filter.calledOnce.should.be.true; @@ -208,36 +209,36 @@ describe('Render', function(){ }); }); - it('renderSync() - path', function(){ + it('renderSync() - path', function() { var result = hexo.render.renderSync({path: path}); result.should.eql(obj); }); - it('renderSync() - text (without engine)', function(){ + it('renderSync() - text (without engine)', function() { var result = hexo.render.renderSync({text: body}); result.should.eql(body); }); - it('renderSync() - text (with engine)', function(){ + it('renderSync() - text (with engine)', function() { var result = hexo.render.renderSync({text: body, engine: 'yaml'}); result.should.eql(obj); }); - it('renderSync() - no path and text', function(){ + it('renderSync() - no path and text', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'No input file or string!'); }); try { hexo.render.renderSync(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('renderSync() - options', function(){ + it('renderSync() - options', function() { var result = hexo.render.renderSync({ text: [ '{{ title }}', @@ -255,7 +256,7 @@ describe('Render', function(){ ].join('\n')); }); - it('renderSync() - toString', function(){ + it('renderSync() - toString', function() { var result = hexo.render.renderSync({ text: body, engine: 'yaml', @@ -265,11 +266,11 @@ describe('Render', function(){ result.should.eql(JSON.stringify(obj)); }); - it('renderSync() - custom toString method', function(){ + it('renderSync() - custom toString method', function() { var result = hexo.render.renderSync({ text: body, engine: 'yaml', - toString: function(data){ + toString: function(data) { return JSON.stringify(data, null, ' '); } }); @@ -277,13 +278,13 @@ describe('Render', function(){ result.should.eql(JSON.stringify(obj, null, ' ')); }); - it('renderSync() - after_render filter', function(){ + it('renderSync() - after_render filter', function() { var data = { text: ' 123456 ', engine: 'swig' }; - var filter = sinon.spy(function(result, obj){ + var filter = sinon.spy(function(result, obj) { result.should.eql(data.text); obj.should.eql(data); return result.trim(); @@ -299,7 +300,7 @@ describe('Render', function(){ hexo.extend.filter.unregister('after_render:html', filter); }); - it('renderSync() - after_render filter: use the given output extension if not found', function(){ + it('renderSync() - after_render filter: use the given output extension if not found', function() { var data = { text: 'foo', engine: 'txt' @@ -308,13 +309,12 @@ describe('Render', function(){ var filter = sinon.spy(); hexo.extend.filter.register('after_render:txt', filter); - var result = hexo.render.renderSync(data); - + hexo.render.renderSync(data); filter.calledOnce.should.be.true; hexo.extend.filter.unregister('after_render:txt', filter); }); - it('renderSync() - onRenderEnd', function(){ + it('renderSync() - onRenderEnd', function() { var onRenderEnd = sinon.spy(function(result) { return result + 'bar'; }); @@ -327,13 +327,13 @@ describe('Render', function(){ var filter = sinon.spy(function(result) { result.should.eql('foobar'); }); - hexo.extend.filter.register('after_render:txt', filter); - var result = hexo.render.renderSync(data); + hexo.extend.filter.register('after_render:txt', filter); + hexo.render.renderSync(data); onRenderEnd.calledOnce.should.be.true; filter.calledOnce.should.be.true; hexo.extend.filter.unregister('after_render:txt', filter); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/router.js b/test/scripts/hexo/router.js index ea1d6bbc47..5bfa6e1c31 100644 --- a/test/scripts/hexo/router.js +++ b/test/scripts/hexo/router.js @@ -1,6 +1,6 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); var Readable = require('stream').Readable; var pathFn = require('path'); @@ -9,33 +9,33 @@ var fs = require('hexo-fs'); var sinon = require('sinon'); var testUtil = require('../../util'); -describe('Router', function(){ +describe('Router', function() { var Router = require('../../../lib/hexo/router'); var router = new Router(); - function checkStream(stream, expected){ - return testUtil.stream.read(stream).then(function(data){ + function checkStream(stream, expected) { + return testUtil.stream.read(stream).then(function(data) { data.should.eql(expected); }); } - function checksum(stream){ - return new Promise(function(resolve, reject){ + function checksum(stream) { + return new Promise(function(resolve, reject) { var hash = crypto.createHash('sha1'); - stream.on('readable', function(){ + stream.on('readable', function() { var chunk; - while ((chunk = stream.read()) !== null){ + while ((chunk = stream.read()) !== null) { hash.update(chunk); } - }).on('end', function(){ + }).on('end', function() { resolve(hash.digest('hex')); }).on('error', reject); }); } - it('format()', function(){ + it('format()', function() { router.format('foo').should.eql('foo'); // Remove prefixed slashes @@ -57,22 +57,22 @@ describe('Router', function(){ router.format('foo?a=1&b=2').should.eql('foo'); }); - it('format() - path must be a string', function(){ + it('format() - path must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'path must be a string!'); - }) + }); try { - router.format(function(){}); - } catch (err){ + router.format(function() {}); + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; - }) + }); - it('set() - string', function(){ - var listener = sinon.spy(function(path){ + it('set() - string', function() { + var listener = sinon.spy(function(path) { path.should.eql('test'); }); @@ -86,36 +86,36 @@ describe('Router', function(){ return checkStream(data, 'foo'); }); - it('set() - function', function(){ - router.set('test', function(){ + it('set() - function', function() { + router.set('test', function() { return 'foo'; }); return checkStream(router.get('test'), 'foo'); }); - it('set() - function (callback style)', function(){ - router.set('test', function(callback){ + it('set() - function (callback style)', function() { + router.set('test', function(callback) { callback(null, 'foo'); }); return checkStream(router.get('test'), 'foo'); }); - it('set() - readable stream', function(){ + it('set() - readable stream', function() { // Prepare a readable stream var stream = new Readable(); stream.push('foo'); stream.push(null); - router.set('test', function(){ + router.set('test', function() { return stream; }); return checkStream(router.get('test'), 'foo'); }); - it('set() - modified', function(){ + it('set() - modified', function() { router.set('test', { data: '', modified: false @@ -124,40 +124,40 @@ describe('Router', function(){ router.isModified('test').should.be.false; }); - it('set() - path must be a string', function(){ + it('set() - path must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'path must be a string!'); }); try { router.set(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('set() - data is required', function(){ + it('set() - data is required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'data is required!'); }); try { router.set('test'); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('get() - error handling', function(){ - router.set('test', function(){ + it('get() - error handling', function() { + router.set('test', function() { throw new Error('error test'); }); - var errorCallback = sinon.spy(function(err){ + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'error test'); }); @@ -166,65 +166,65 @@ describe('Router', function(){ }); }); - it('get() - no data', function(){ - router.set('test', function(){ + it('get() - no data', function() { + router.set('test', function() { return; }); return checkStream(router.get('test'), ''); }); - it('get() - empty readable stream', function(){ + it('get() - empty readable stream', function() { var stream = new Readable(); stream.push(null); - router.set('test', function(){ + router.set('test', function() { return stream; }); return checkStream(router.get('test'), ''); }); - it('get() - large readable stream (more than 65535 bits)', function(){ + it('get() - large readable stream (more than 65535 bits)', function() { var path = pathFn.join(__dirname, '../../fixtures/banner.jpg'); - router.set('test', function(){ + router.set('test', function() { return fs.createReadStream(path); }); return Promise.all([ checksum(router.get('test')), checksum(fs.createReadStream(path)) - ]).then(function(data){ + ]).then(function(data) { data[0].should.eql(data[1]); }); }); - it('get() - path must be a string', function(){ + it('get() - path must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'path must be a string!'); }); try { router.get(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('get() - export stringified JSON object', function(){ + it('get() - export stringified JSON object', function() { var obj = {foo: 1, bar: 2}; - router.set('test', function(){ + router.set('test', function() { return obj; }); return checkStream(router.get('test'), JSON.stringify(obj)); }); - it('list()', function(){ + it('list()', function() { var router = new Router(); router.set('foo', 'foo'); @@ -235,27 +235,27 @@ describe('Router', function(){ router.list().should.eql(['foo', 'baz']); }); - it('isModified()', function(){ + it('isModified()', function() { router.set('test', 'foo'); router.isModified('test').should.be.true; }); - it('isModified() - path must be a string', function(){ + it('isModified() - path must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'path must be a string!'); }); try { router.isModified(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); - it('remove()', function(){ - var listener = sinon.spy(function(path){ + it('remove()', function() { + var listener = sinon.spy(function(path) { path.should.eql('test'); }); @@ -267,17 +267,17 @@ describe('Router', function(){ listener.calledOnce.should.be.true; }); - it('remove() - path must be a string', function(){ + it('remove() - path must be a string', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'path must be a string!'); }); try { router.remove(); - } catch (err){ + } catch (err) { errorCallback(err); } errorCallback.calledOnce.should.be.true; }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/scaffold.js b/test/scripts/hexo/scaffold.js index 54408c4525..6d38961440 100644 --- a/test/scripts/hexo/scaffold.js +++ b/test/scripts/hexo/scaffold.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 Promise = require('bluebird'); var fs = require('hexo-fs'); -describe('Scaffold', function(){ +describe('Scaffold', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var scaffold = hexo.scaffold; @@ -19,70 +19,70 @@ describe('Scaffold', function(){ var testPath = pathFn.join(scaffoldDir, 'test.md'); - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return fs.writeFile(testPath, testContent); }); }); - after(function(){ + after(function() { return fs.rmdir(scaffoldDir); }); - it('get() - file exists', function(){ - return scaffold.get('test').then(function(data){ + it('get() - file exists', function() { + return scaffold.get('test').then(function(data) { data.should.eql(testContent); }); }); - it('get() - normal scaffold', function(){ - return scaffold.get('normal').then(function(data){ + it('get() - normal scaffold', function() { + return scaffold.get('normal').then(function(data) { data.should.eql(scaffold.defaults.normal); }); }); - it('set() - file exists', function(){ - return scaffold.set('test', 'foo').then(function(){ + it('set() - file exists', function() { + return scaffold.set('test', 'foo').then(function() { return Promise.all([ fs.readFile(testPath), scaffold.get('test') ]); - }).spread(function(file, data){ + }).spread(function(file, data) { file.should.eql('foo'); data.should.eql('foo'); return fs.writeFile(testPath, testContent); }); }); - it('set() - file does not exist', function(){ + it('set() - file does not exist', function() { var testPath = pathFn.join(scaffoldDir, 'foo.md'); - return scaffold.set('foo', 'bar').then(function(){ + return scaffold.set('foo', 'bar').then(function() { return Promise.all([ fs.readFile(testPath), scaffold.get('foo') ]); - }).spread(function(file, data){ + }).spread(function(file, data) { file.should.eql('bar'); data.should.eql('bar'); return fs.unlink(testPath); }); }); - it('remove() - file exist', function(){ - return scaffold.remove('test').then(function(){ + it('remove() - file exist', function() { + return scaffold.remove('test').then(function() { return Promise.all([ fs.exists(testPath), scaffold.get('test') ]); - }).spread(function(exist, data){ + }).spread(function(exist, data) { exist.should.be.false; should.not.exist(data); return fs.writeFile(testPath, testContent); }); }); - it('remove() - file does not exist', function(){ + it('remove() - file does not exist', function() { return scaffold.remove('foo'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/hexo/update_package.js b/test/scripts/hexo/update_package.js index 68f88acf62..487e0a4289 100644 --- a/test/scripts/hexo/update_package.js +++ b/test/scripts/hexo/update_package.js @@ -1,37 +1,37 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var pathFn = require('path'); var fs = require('hexo-fs'); -describe('Update package.json', function(){ +describe('Update package.json', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname, {silent: true}); var updatePkg = require('../../../lib/hexo/update_package'); var packagePath = pathFn.join(hexo.base_dir, 'package.json'); - beforeEach(function(){ + beforeEach(function() { hexo.env.init = false; - }) + }); - it('package.json does not exist', function(){ - return updatePkg(hexo).then(function(){ + it('package.json does not exist', function() { + return updatePkg(hexo).then(function() { hexo.env.init.should.be.false; }); }); - it('package.json exists, but the version doesn\'t match', function(){ + it('package.json exists, but the version doesn\'t match', function() { var pkg = { hexo: { version: '0.0.1' } }; - return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function(){ + return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function() { return updatePkg(hexo); - }).then(function(){ + }).then(function() { return fs.readFile(packagePath); - }).then(function(content){ + }).then(function(content) { JSON.parse(content).hexo.version.should.eql(hexo.version); hexo.env.init.should.be.true; @@ -39,17 +39,17 @@ describe('Update package.json', function(){ }); }); - it('package.json exists, but don\'t have hexo data', function(){ + it('package.json exists, but don\'t have hexo data', function() { var pkg = { name: 'hexo', version: '0.0.1' }; - return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function(){ + return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function() { return updatePkg(hexo); - }).then(function(){ + }).then(function() { return fs.readFile(packagePath); - }).then(function(content){ + }).then(function(content) { // Don't change the original package.json JSON.parse(content).should.eql(pkg); hexo.env.init.should.be.false; @@ -58,22 +58,22 @@ describe('Update package.json', function(){ }); }); - it('package.json exists and everything is ok', function(){ + it('package.json exists and everything is ok', function() { var pkg = { hexo: { version: hexo.version } }; - return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function(){ + return fs.writeFile(packagePath, JSON.stringify(pkg)).then(function() { return updatePkg(hexo); - }).then(function(){ + }).then(function() { return fs.readFile(packagePath); - }).then(function(content){ + }).then(function(content) { JSON.parse(content).should.eql(pkg); hexo.env.init.should.be.true; return fs.unlink(packagePath); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/asset.js b/test/scripts/models/asset.js index edbca65b75..b51cb8f25d 100644 --- a/test/scripts/models/asset.js +++ b/test/scripts/models/asset.js @@ -1,25 +1,25 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); -describe('Asset', function(){ +describe('Asset', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Asset = hexo.model('Asset'); - it('default values', function(){ + it('default values', function() { return Asset.insert({ _id: 'foo', path: 'bar' - }).then(function(data){ + }).then(function(data) { data.modified.should.be.true; return Asset.removeById(data._id); }); }); - it('_id - required', function(){ + it('_id - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'ID is not defined'); }); @@ -29,7 +29,7 @@ describe('Asset', function(){ }); }); - it('path - required', function(){ + it('path - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`path` is required!'); }); @@ -41,13 +41,13 @@ describe('Asset', function(){ }); }); - it('source - virtual', function(){ + it('source - virtual', function() { return Asset.insert({ _id: 'foo', path: 'bar' - }).then(function(data){ + }).then(function(data) { data.source.should.eql(pathFn.join(hexo.base_dir, data._id)); return Asset.removeById(data._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/cache.js b/test/scripts/models/cache.js index 1bff141236..0d1614e3d1 100644 --- a/test/scripts/models/cache.js +++ b/test/scripts/models/cache.js @@ -1,14 +1,14 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); -describe('Cache', function(){ +describe('Cache', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Cache = hexo.model('Cache'); - it('_id - required', function(){ + it('_id - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'ID is not defined'); }); @@ -17,4 +17,4 @@ describe('Cache', function(){ errorCallback.calledOnce.should.be.true; }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/cachestring.js b/test/scripts/models/cachestring.js index f69f33ae23..a249f7f80a 100644 --- a/test/scripts/models/cachestring.js +++ b/test/scripts/models/cachestring.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('SchemaTypeCacheString', function(){ +describe('SchemaTypeCacheString', function() { var SchemaTypeCacheString = require('../../../lib/models/types/cachestring'); var type = new SchemaTypeCacheString('test'); - it('value()', function(){ + it('value()', function() { should.not.exist(type.value('')); should.not.exist(type.value('foo')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/category.js b/test/scripts/models/category.js index c468b47ef5..57cdf3e795 100644 --- a/test/scripts/models/category.js +++ b/test/scripts/models/category.js @@ -1,21 +1,21 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var Promise = require('bluebird'); -describe('Category', function(){ +describe('Category', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Category = hexo.model('Category'); var Post = hexo.model('Post'); var PostCategory = hexo.model('PostCategory'); - before(function(){ + before(function() { return hexo.init(); }); - it('name - required', function(){ + it('name - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`name` is required!'); }); @@ -27,71 +27,71 @@ describe('Category', function(){ it.skip('parent - reference'); - it('slug - virtual', function(){ + it('slug - virtual', function() { return Category.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('foo'); return Category.removeById(data._id); }); }); - it('slug - category_map', function(){ + it('slug - category_map', function() { hexo.config.category_map = { test: 'wat' }; return Category.insert({ name: 'test' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('wat'); hexo.config.category_map = {}; return Category.removeById(data._id); }); }); - it('slug - filename_case: 0', function(){ + it('slug - filename_case: 0', function() { return Category.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('WahAHa'); return Category.removeById(data._id); }); }); - it('slug - filename_case: 1', function(){ + it('slug - filename_case: 1', function() { hexo.config.filename_case = 1; return Category.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('wahaha'); hexo.config.filename_case = 0; return Category.removeById(data._id); }); }); - it('slug - filename_case: 2', function(){ + it('slug - filename_case: 2', function() { hexo.config.filename_case = 2; return Category.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('WAHAHA'); hexo.config.filename_case = 0; return Category.removeById(data._id); }); }); - it('slug - parent', function(){ + it('slug - parent', function() { return Category.insert({ name: 'parent' - }).then(function(cat){ + }).then(function(cat) { return Category.insert({ name: 'child', parent: cat._id }); - }).then(function(cat){ + }).then(function(cat) { cat.slug.should.eql('parent/child'); return Promise.all([ @@ -101,35 +101,35 @@ describe('Category', function(){ }); }); - it('path - virtual', function(){ + it('path - virtual', function() { return Category.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.path.should.eql(hexo.config.category_dir + '/' + data.slug + '/'); return Category.removeById(data._id); }); }); - it('permalink - virtual', function(){ + it('permalink - virtual', function() { return Category.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.permalink.should.eql(hexo.config.url + '/' + data.path); return Category.removeById(data._id); }); }); - it('posts - virtual', function(){ + it('posts - virtual', function() { return Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'}, {source: 'baz.md', slug: 'baz'} - ]).each(function(post){ + ]).each(function(post) { return post.setCategories(['foo']); - }).then(function(posts){ + }).then(function(posts) { var cat = Category.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -138,22 +138,22 @@ describe('Category', function(){ cat.length.should.eql(posts.length); return cat.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('posts - draft', function(){ + it('posts - draft', function() { return Post.insert([ {source: 'foo.md', slug: 'foo', published: true}, {source: 'bar.md', slug: 'bar', published: false}, {source: 'baz.md', slug: 'baz', published: true} - ]).each(function(post){ + ]).each(function(post) { return post.setCategories(['foo']); - }).then(function(posts){ + }).then(function(posts) { var cat = Category.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -172,24 +172,24 @@ describe('Category', function(){ hexo.config.render_drafts = false; return cat.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('posts - future', function(){ + it('posts - future', function() { var now = Date.now(); return Post.insert([ {source: 'foo.md', slug: 'foo', date: now - 3600}, {source: 'bar.md', slug: 'bar', date: now + 3600}, {source: 'baz.md', slug: 'baz', date: now} - ]).each(function(post){ + ]).each(function(post) { return post.setCategories(['foo']); - }).then(function(posts){ + }).then(function(posts) { var cat = Category.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -208,21 +208,19 @@ describe('Category', function(){ cat.length.should.eql(2); return cat.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('check whether a category exists', function(){ - var errorCallback = sinon.spy(function(err){ + it('check whether a category exists', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Category `foo` has already existed!'); }); return Category.insert({ name: 'foo' - }).then(function(data){ - var errorCall - + }).then(function(data) { Category.insert({ name: 'foo' }).catch(errorCallback); @@ -233,15 +231,15 @@ describe('Category', function(){ }); }); - it('check whether a category exists (with parent)', function(){ + it('check whether a category exists (with parent)', function() { return Category.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { return Category.insert({ name: 'foo', parent: data._id }); - }).then(function(data){ + }).then(function(data) { return Promise.all([ Category.removeById(data._id), Category.removeById(data.parent) @@ -249,25 +247,25 @@ describe('Category', function(){ }); }); - it('remove PostCategory references when a category is removed', function(){ + it('remove PostCategory references when a category is removed', function() { var cat; return Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'}, {source: 'baz.md', slug: 'baz'} - ]).then(function(posts){ - return Promise.map(posts, function(post){ + ]).then(function(posts) { + return Promise.map(posts, function(post) { return post.setCategories(['foo']).thenReturn(post); }, {concurrency: 1}); // One item a time - }).then(function(posts){ + }).then(function(posts) { cat = Category.findOne({name: 'foo'}); return Category.removeById(cat._id).thenReturn(posts); - }).then(function(posts){ + }).then(function(posts) { PostCategory.find({category_id: cat._id}).length.should.eql(0); return posts; - }).map(function(post){ + }).map(function(post) { return Post.removeById(post._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/index.js b/test/scripts/models/index.js index 22b4641766..c577f23e52 100644 --- a/test/scripts/models/index.js +++ b/test/scripts/models/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Models', function(){ +describe('Models', function() { require('./asset'); require('./cache'); require('./cachestring'); @@ -10,4 +10,4 @@ describe('Models', function(){ require('./post'); require('./post_asset'); require('./tag'); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/moment.js b/test/scripts/models/moment.js index 992b09351e..b9df7a9c74 100644 --- a/test/scripts/models/moment.js +++ b/test/scripts/models/moment.js @@ -1,25 +1,25 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var moment = require('moment-timezone'); -describe('SchemaTypeMoment', function(){ +describe('SchemaTypeMoment', function() { var SchemaTypeMoment = require('../../../lib/models/types/moment'); var type = new SchemaTypeMoment('test'); - it('cast()', function(){ + it('cast()', function() { type.cast(1e8).should.eql(moment(1e8)); type.cast(new Date(2014, 1, 1)).should.eql(moment(new Date(2014, 1, 1))); type.cast('2014-11-03T07:45:41.237Z').should.eql(moment('2014-11-03T07:45:41.237Z')); type.cast(moment(1e8)).valueOf().should.eql(1e8); }); - it('cast() - default', function(){ + it('cast() - default', function() { var type = new SchemaTypeMoment('test', {default: moment}); moment.isMoment(type.cast()).should.be.true; }); - it('cast() - language', function(){ + it('cast() - language', function() { var lang = 'zh-tw'; var format = 'LLLL'; var type = new SchemaTypeMoment('test', {language: lang}); @@ -28,7 +28,7 @@ describe('SchemaTypeMoment', function(){ type.cast(now).format(format).should.eql(moment(now).locale(lang).format(format)); }); - it('cast() - timezone', function(){ + it('cast() - timezone', function() { var timezone = 'Etc/UTC'; var format = 'LLLL'; var type = new SchemaTypeMoment('test', {timezone: timezone}); @@ -37,27 +37,27 @@ describe('SchemaTypeMoment', function(){ type.cast(now).format(format).should.eql(moment(now).tz(timezone).format(format)); }); - function shouldThrowError(value){ + function shouldThrowError(value) { type.validate(value).should.have.property('message', '`' + value + '` is not a valid date!'); } - it('validate()', function(){ - type.validate(moment(1e8)).valueOf().should.eql(1e8) + it('validate()', function() { + type.validate(moment(1e8)).valueOf().should.eql(1e8); shouldThrowError(moment.invalid()); }); - it('validate() - required', function(){ + it('validate() - required', function() { var type = new SchemaTypeMoment('test', {required: true}); type.validate().should.have.property('message', '`test` is required!'); }); - it('match()', function(){ + it('match()', function() { type.match(moment(1e8), moment(1e8)).should.be.true; type.match(moment(1e8), moment(1e8 + 1)).should.be.false; type.match(undefined, moment()).should.be.false; }); - it('compare()', function(){ + it('compare()', function() { type.compare(moment([2014, 1, 3]), moment([2014, 1, 2])).should.gt(0); type.compare(moment([2014, 1, 1]), moment([2014, 1, 2])).should.lt(0); type.compare(moment([2014, 1, 2]), moment([2014, 1, 2])).should.eql(0); @@ -66,41 +66,41 @@ describe('SchemaTypeMoment', function(){ type.compare().should.eql(0); }); - it('parse()', function(){ + it('parse()', function() { type.parse('2014-11-03T07:45:41.237Z').should.eql(moment('2014-11-03T07:45:41.237Z')); should.not.exist(type.parse()); }); - it('value()', function(){ + it('value()', function() { type.value(moment('2014-11-03T07:45:41.237Z')).should.eql('2014-11-03T07:45:41.237Z'); should.not.exist(type.value()); }); - it('q$day()', function(){ + it('q$day()', function() { type.q$day(moment([2014, 1, 1]), 1).should.be.true; type.q$day(moment([2014, 1, 1]), 5).should.be.false; type.q$day(undefined, 1).should.be.false; }); - it('q$month()', function(){ + it('q$month()', function() { type.q$month(moment([2014, 1, 1]), 1).should.be.true; type.q$month(moment([2014, 1, 1]), 5).should.be.false; type.q$month(undefined, 1).should.be.false; }); - it('q$year()', function(){ + it('q$year()', function() { type.q$year(moment([2014, 1, 1]), 2014).should.be.true; type.q$year(moment([2014, 1, 1]), 1999).should.be.false; type.q$year(undefined, 1).should.be.false; }); - it('u$inc()', function(){ + it('u$inc()', function() { type.u$inc(moment(1e8), 1).valueOf().should.eql(1e8 + 1); should.not.exist(undefined, 1); }); - it('u$dec()', function(){ + it('u$dec()', function() { type.u$dec(moment(1e8), 1).valueOf().should.eql(1e8 - 1); should.not.exist(undefined, 1); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/page.js b/test/scripts/models/page.js index 1675c8642d..7022fcade9 100644 --- a/test/scripts/models/page.js +++ b/test/scripts/models/page.js @@ -1,21 +1,21 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); -describe('Page', function(){ +describe('Page', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Page = hexo.model('Page'); - it('default values', function(){ + it('default values', function() { var now = Date.now(); return Page.insert({ source: 'foo', path: 'bar' - }).then(function(data){ + }).then(function(data) { data.title.should.eql(''); data.date.valueOf().should.gte(now); data.updated.valueOf().should.gte(now); @@ -31,7 +31,7 @@ describe('Page', function(){ }); }); - it('source - required', function(){ + it('source - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`source` is required!'); }); @@ -41,7 +41,7 @@ describe('Page', function(){ }); }); - it('path - required', function(){ + it('path - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`path` is required!'); }); @@ -53,23 +53,23 @@ describe('Page', function(){ }); }); - it('permalink - virtual', function(){ + it('permalink - virtual', function() { return Page.insert({ source: 'foo', path: 'bar' - }).then(function(data){ + }).then(function(data) { data.permalink.should.eql(hexo.config.url + '/' + data.path); return Page.removeById(data._id); }); }); - it('full_source - virtual', function(){ + it('full_source - virtual', function() { return Page.insert({ source: 'foo', path: 'bar' - }).then(function(data){ + }).then(function(data) { data.full_source.should.eql(pathFn.join(hexo.source_dir, data.source)); return Page.removeById(data._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/post.js b/test/scripts/models/post.js index 525af4d6c4..7ae6277cef 100644 --- a/test/scripts/models/post.js +++ b/test/scripts/models/post.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var pathFn = require('path'); var Promise = require('bluebird'); -describe('Post', function(){ +describe('Post', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Post = hexo.model('Post'); @@ -15,18 +15,18 @@ describe('Post', function(){ var PostCategory = hexo.model('PostCategory'); var Asset = hexo.model('Asset'); - before(function(){ + before(function() { hexo.config.permalink = ':title'; return hexo.init(); }); - it('default values', function(){ + it('default values', function() { var now = Date.now(); return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(data){ + }).then(function(data) { data.title.should.eql(''); data.date.valueOf().should.gte(now); data.updated.valueOf().should.gte(now); @@ -44,8 +44,8 @@ describe('Post', function(){ }); }); - it('source - required', function(){ - var errorCallback = sinon.spy(function(err){ + it('source - required', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`source` is required!'); }); @@ -54,8 +54,8 @@ describe('Post', function(){ }); }); - it('slug - required', function(){ - var errorCallback = sinon.spy(function(err){ + it('slug - required', function() { + var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`slug` is required!'); }); @@ -66,55 +66,55 @@ describe('Post', function(){ }); }); - it('path - virtual', function(){ + it('path - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(data){ + }).then(function(data) { data.path.should.eql(data.slug); return Post.removeById(data._id); }); }); - it('permalink - virtual', function(){ + it('permalink - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(data){ + }).then(function(data) { data.permalink.should.eql(hexo.config.url + '/' + data.path); return Post.removeById(data._id); }); }); - it('full_source - virtual', function(){ + it('full_source - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(data){ + }).then(function(data) { data.full_source.should.eql(pathFn.join(hexo.source_dir, data.source)); return Post.removeById(data._id); }); }); - it('asset_dir - virtual', function(){ + it('asset_dir - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(data){ + }).then(function(data) { data.asset_dir.should.eql(pathFn.join(hexo.source_dir, 'foo') + pathFn.sep); return Post.removeById(data._id); }); }); - it('tags - virtual', function(){ + it('tags - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { return post.setTags(['foo', 'bar', 'baz']) .thenReturn(Post.findById(post._id)); - }).then(function(post){ - post.tags.map(function(tag){ + }).then(function(post) { + post.tags.map(function(tag) { return tag.name; }).should.eql(['bar', 'baz', 'foo']); @@ -122,20 +122,20 @@ describe('Post', function(){ }); }); - it('categories - virtual', function(){ + it('categories - virtual', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { return post.setCategories(['foo', 'bar', 'baz']) .thenReturn(Post.findById(post._id)); - }).then(function(post){ + }).then(function(post) { var cats = post.categories; // Make sure the order of categories is correct - cats.map(function(cat, i){ + cats.map(function(cat, i) { // Make sure the parent reference is correct - if (i){ + if (i) { cat.parent.should.eql(cats.eq(i - 1)._id); } else { should.not.exist(cat.parent); @@ -148,22 +148,22 @@ describe('Post', function(){ }); }); - it('setTags() - old tags should be removed', function(){ + it('setTags() - old tags should be removed', function() { var id; return Post.insert({ source: 'foo.md', slug: 'foo' - }).then(function(post){ + }).then(function(post) { id = post._id; return post.setTags(['foo', 'bar']); - }).then(function(){ + }).then(function() { var post = Post.findById(id); return post.setTags(['bar', 'baz']); - }).then(function(){ + }).then(function() { var post = Post.findById(id); - post.tags.map(function(tag){ + post.tags.map(function(tag) { return tag.name; }).should.eql(['bar', 'baz']); @@ -171,42 +171,42 @@ describe('Post', function(){ }); }); - it('setTags() - sync problem', function(){ + it('setTags() - sync problem', function() { return Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'} - ]).then(function(posts){ + ]).then(function(posts) { return Promise.all([ posts[0].setTags(['foo', 'bar']), posts[1].setTags(['bar', 'baz']) ]).thenReturn(posts); - }).then(function(posts){ - Tag.map(function(tag){ + }).then(function(posts) { + Tag.map(function(tag) { return tag.name; }).should.have.members(['foo', 'bar', 'baz']); return posts; - }).map(function(post){ + }).map(function(post) { return Post.removeById(post._id); }); }); - it('setCategories() - old categories should be removed', function(){ + it('setCategories() - old categories should be removed', function() { var id; return Post.insert({ source: 'foo.md', slug: 'foo' - }).then(function(post){ + }).then(function(post) { id = post._id; return post.setCategories(['foo', 'bar']); - }).then(function(){ + }).then(function() { var post = Post.findById(id); return post.setCategories(['foo', 'baz']); - }).then(function(){ + }).then(function() { var post = Post.findById(id); - post.categories.map(function(cat){ + post.categories.map(function(cat) { return cat.name; }).should.eql(['foo', 'baz']); @@ -214,30 +214,30 @@ describe('Post', function(){ }); }); - it('setCategories() - shared category should be same', function(){ + it('setCategories() - shared category should be same', function() { var postIdA, postIdB; return Post.insert({ source: 'foo.md', slug: 'foo' - }).then(function(post){ + }).then(function(post) { postIdA = post._id; return post.setCategories(['foo', 'bar']); - }).then(function(){ + }).then(function() { return Post.insert({ source: 'bar.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { postIdB = post._id; return post.setCategories(['foo', 'bar']); }); - }).then(function(){ + }).then(function() { var postA = Post.findById(postIdA); var postB = Post.findById(postIdB); - postA.categories.map(function(cat){ + postA.categories.map(function(cat) { return cat._id; - }).should.eql(postB.categories.map(function(cat){ + }).should.eql(postB.categories.map(function(cat) { return cat._id; })); @@ -248,30 +248,31 @@ describe('Post', function(){ }); }); - it('setCategories() - category not shared should be different', function(){ + it('setCategories() - category not shared should be different', function() { var postIdA, postIdB; return Post.insert({ source: 'foo.md', slug: 'foo' - }).then(function(post){ + }).then(function(post) { postIdA = post._id; return post.setCategories(['foo', 'bar']); - }).then(function(){ + }).then(function() { return Post.insert({ source: 'bar.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { postIdB = post._id; return post.setCategories(['baz', 'bar']); }); - }).then(function(){ + }).then(function() { var postA = Post.findById(postIdA); var postB = Post.findById(postIdB); var postCategoriesA = postA.categories.map(function(cat) { return cat._id; }); + var postCategoriesB = postB.categories.map(function(cat) { return cat._id; }); @@ -291,16 +292,16 @@ describe('Post', function(){ }); }); - it('remove PostTag references when a post is removed', function(){ + it('remove PostTag references when a post is removed', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { return post.setTags(['foo', 'bar', 'baz']) .thenReturn(Post.findById(post._id)); - }).then(function(post){ + }).then(function(post) { return Post.removeById(post._id); - }).then(function(post){ + }).then(function(post) { PostTag.find({post_id: post._id}).length.should.eql(0); Tag.findOne({name: 'foo'}).posts.length.should.eql(0); Tag.findOne({name: 'bar'}).posts.length.should.eql(0); @@ -308,16 +309,16 @@ describe('Post', function(){ }); }); - it('remove PostCategory references when a post is removed', function(){ + it('remove PostCategory references when a post is removed', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { return post.setCategories(['foo', 'bar', 'baz']) .thenReturn(Post.findById(post._id)); - }).then(function(post){ + }).then(function(post) { return Post.removeById(post._id); - }).then(function(post){ + }).then(function(post) { PostCategory.find({post_id: post._id}).length.should.eql(0); Category.findOne({name: 'foo'}).posts.length.should.eql(0); Category.findOne({name: 'bar'}).posts.length.should.eql(0); @@ -325,20 +326,20 @@ describe('Post', function(){ }); }); - it('remove related assets when a post is removed', function(){ + it('remove related assets when a post is removed', function() { return Post.insert({ source: 'foo.md', slug: 'bar' - }).then(function(post){ + }).then(function(post) { return Promise.all([ Asset.insert({_id: 'foo', path: 'foo'}), Asset.insert({_id: 'bar', path: 'bar'}), Asset.insert({_id: 'baz', path: 'bar'}) ]).thenReturn(post); - }).then(function(post){ + }).then(function(post) { return Post.removeById(post._id); - }).then(function(post){ + }).then(function(post) { Asset.find({post: post._id}).length.should.eql(0); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/post_asset.js b/test/scripts/models/post_asset.js index 1e2603eabe..01434e59b8 100644 --- a/test/scripts/models/post_asset.js +++ b/test/scripts/models/post_asset.js @@ -1,50 +1,50 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var url = require('url'); var pathFn = require('path'); -describe('PostAsset', function(){ +describe('PostAsset', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var PostAsset = hexo.model('PostAsset'); var Post = hexo.model('Post'); var post; - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return Post.insert({ source: 'foo.md', slug: 'bar' }); - }).then(function(post_){ + }).then(function(post_) { post = post_; }); }); - it('default values', function(){ + it('default values', function() { return PostAsset.insert({ _id: 'foo', slug: 'foo', post: post._id - }).then(function(data){ + }).then(function(data) { data.modified.should.be.true; return PostAsset.removeById(data._id); }); }); - it('_id - required', function(){ + it('_id - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'ID is not defined'); }); return PostAsset.insert({}).catch(errorCallback).finally(function() { errorCallback.calledOnce.should.be.true; - });; + }); }); - it('slug - required', function(){ + it('slug - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`slug` is required!'); }); @@ -53,28 +53,28 @@ describe('PostAsset', function(){ _id: 'foo' }).catch(errorCallback).finally(function() { errorCallback.calledOnce.should.be.true; - });; + }); }); - it('path - virtual', function(){ + it('path - virtual', function() { return PostAsset.insert({ _id: 'source/_posts/test/foo.jpg', slug: 'foo.jpg', post: post._id - }).then(function(data){ + }).then(function(data) { data.path.should.eql(url.resolve(post.path, data.slug)); return PostAsset.removeById(data._id); }); }); - it('source - virtual', function(){ + it('source - virtual', function() { return PostAsset.insert({ _id: 'source/_posts/test/foo.jpg', slug: 'foo.jpg', post: post._id - }).then(function(data){ + }).then(function(data) { data.source.should.eql(pathFn.join(hexo.base_dir, data._id)); return PostAsset.removeById(data._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/models/tag.js b/test/scripts/models/tag.js index 1a3a0de06e..007a39d752 100644 --- a/test/scripts/models/tag.js +++ b/test/scripts/models/tag.js @@ -1,22 +1,21 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var sinon = require('sinon'); var Promise = require('bluebird'); -var _ = require('lodash'); -describe('Tag', function(){ +describe('Tag', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(); var Tag = hexo.model('Tag'); var Post = hexo.model('Post'); var PostTag = hexo.model('PostTag'); - before(function(){ + before(function() { return hexo.init(); }); - it('name - required', function(){ + it('name - required', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', '`name` is required!'); }); @@ -26,23 +25,23 @@ describe('Tag', function(){ }); }); - it('slug - virtual', function(){ + it('slug - virtual', function() { return Tag.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('foo'); return Tag.removeById(data._id); }); }); - it('slug - tag_map', function(){ + it('slug - tag_map', function() { hexo.config.tag_map = { test: 'wat' }; return Tag.insert({ name: 'test' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('wat'); hexo.config.tag_map = {}; @@ -50,68 +49,68 @@ describe('Tag', function(){ }); }); - it('slug - filename_case: 0', function(){ + it('slug - filename_case: 0', function() { return Tag.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('WahAHa'); return Tag.removeById(data._id); }); }); - it('slug - filename_case: 1', function(){ + it('slug - filename_case: 1', function() { hexo.config.filename_case = 1; return Tag.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('wahaha'); hexo.config.filename_case = 0; return Tag.removeById(data._id); }); }); - it('slug - filename_case: 2', function(){ + it('slug - filename_case: 2', function() { hexo.config.filename_case = 2; return Tag.insert({ name: 'WahAHa' - }).then(function(data){ + }).then(function(data) { data.slug.should.eql('WAHAHA'); hexo.config.filename_case = 0; return Tag.removeById(data._id); }); }); - it('path - virtual', function(){ + it('path - virtual', function() { return Tag.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.path.should.eql(hexo.config.tag_dir + '/' + data.slug + '/'); return Tag.removeById(data._id); - }) + }); }); - it('permalink - virtual', function(){ + it('permalink - virtual', function() { return Tag.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { data.permalink.should.eql(hexo.config.url + '/' + data.path); return Tag.removeById(data._id); }); }); - it('posts - virtual', function(){ + it('posts - virtual', function() { return Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'}, {source: 'baz.md', slug: 'baz'} - ]).each(function(post){ + ]).each(function(post) { return post.setTags(['foo']); - }).then(function(posts){ + }).then(function(posts) { var tag = Tag.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -120,22 +119,22 @@ describe('Tag', function(){ tag.length.should.eql(posts.length); return tag.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('posts - draft', function(){ + it('posts - draft', function() { return Post.insert([ {source: 'foo.md', slug: 'foo', published: true}, {source: 'bar.md', slug: 'bar', published: false}, {source: 'baz.md', slug: 'baz', published: true} - ]).each(function(post){ + ]).each(function(post) { return post.setTags(['foo']); - }).then(function(posts){ + }).then(function(posts) { var tag = Tag.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -154,24 +153,24 @@ describe('Tag', function(){ hexo.config.render_drafts = false; return tag.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('posts - future', function(){ + it('posts - future', function() { var now = Date.now(); return Post.insert([ {source: 'foo.md', slug: 'foo', date: now - 3600}, {source: 'bar.md', slug: 'bar', date: now + 3600}, {source: 'baz.md', slug: 'baz', date: now} - ]).each(function(post){ + ]).each(function(post) { return post.setTags(['foo']); - }).then(function(posts){ + }).then(function(posts) { var tag = Tag.findOne({name: 'foo'}); - function mapper(post){ + function mapper(post) { return post._id; } @@ -190,19 +189,19 @@ describe('Tag', function(){ tag.length.should.eql(2); return tag.remove().thenReturn(posts); - }).map(function(post){ + }).map(function(post) { return post.remove(); }); }); - it('check whether a tag exists', function(){ + it('check whether a tag exists', function() { var errorCallback = sinon.spy(function(err) { err.should.have.property('message', 'Tag `foo` has already existed!'); }); return Tag.insert({ name: 'foo' - }).then(function(data){ + }).then(function(data) { Tag.insert({ name: 'foo' }).catch(errorCallback); @@ -213,25 +212,25 @@ describe('Tag', function(){ }); }); - it('remove PostTag references when a tag is removed', function(){ + it('remove PostTag references when a tag is removed', function() { var tag; return Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'}, {source: 'baz.md', slug: 'baz'} - ]).then(function(posts){ - return Promise.map(posts, function(post){ + ]).then(function(posts) { + return Promise.map(posts, function(post) { return post.setTags(['foo']).thenReturn(post); }, {concurrency: 1}); // One item a time - }).then(function(posts){ + }).then(function(posts) { tag = Tag.findOne({name: 'foo'}); return Tag.removeById(tag._id).thenReturn(posts); - }).then(function(posts){ + }).then(function(posts) { PostTag.find({tag_id: tag._id}).length.should.eql(0); return posts; - }).map(function(post){ + }).map(function(post) { return Post.removeById(post._id); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/processors/asset.js b/test/scripts/processors/asset.js index 6978ea3770..018132ccda 100644 --- a/test/scripts/processors/asset.js +++ b/test/scripts/processors/asset.js @@ -1,13 +1,13 @@ '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 dateFormat = 'YYYY-MM-DD HH:mm:ss'; -describe('asset', function(){ +describe('asset', function() { var Hexo = require('../../../lib/hexo'); var baseDir = pathFn.join(__dirname, 'asset_test'); var hexo = new Hexo(baseDir); @@ -18,28 +18,28 @@ describe('asset', function(){ var Asset = hexo.model('Asset'); var Page = hexo.model('Page'); - function newFile(options){ + function newFile(options) { options.source = pathFn.join(source.base, options.path); return new File(options); } - before(function(){ - return fs.mkdirs(baseDir).then(function(){ + before(function() { + return fs.mkdirs(baseDir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(baseDir); }); - it('asset - type: create', function(){ + it('asset - type: create', function() { var file = newFile({ path: 'foo.jpg', type: 'create' }); - return process(file).then(function(){ + return process(file).then(function() { var id = 'source/' + file.path; var asset = Asset.findById(id); @@ -51,7 +51,7 @@ describe('asset', function(){ }); }); - it('asset - type: update', function(){ + it('asset - type: update', function() { var file = newFile({ path: 'foo.jpg', type: 'update' @@ -63,9 +63,9 @@ describe('asset', function(){ _id: id, path: file.path, modified: false - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { var asset = Asset.findById(id); asset._id.should.eql(id); @@ -76,7 +76,7 @@ describe('asset', function(){ }); }); - it('asset - type: skip', function(){ + it('asset - type: skip', function() { var file = newFile({ path: 'foo.jpg', type: 'skip' @@ -88,9 +88,9 @@ describe('asset', function(){ _id: id, path: file.path, modified: false - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { var asset = Asset.findById(id); asset._id.should.eql(id); @@ -101,7 +101,7 @@ describe('asset', function(){ }); }); - it('asset - type: delete', function(){ + it('asset - type: delete', function() { var file = newFile({ path: 'foo.jpg', type: 'delete' @@ -112,14 +112,14 @@ describe('asset', function(){ return Asset.insert({ _id: id, path: file.path - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { should.not.exist(Asset.findById(id)); }); }); - it('page - type: create', function(){ + it('page - type: create', function() { var body = [ 'title: "Hello world"', 'date: 2006-01-02 15:04:05', @@ -134,9 +134,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.title.should.eql('Hello world'); @@ -155,7 +155,7 @@ describe('asset', function(){ }); }); - it('page - type: update', function(){ + it('page - type: update', function() { var body = [ 'title: "Hello world"', '---' @@ -172,10 +172,10 @@ describe('asset', function(){ return Promise.all([ Page.insert({source: file.path, path: 'hello.html'}), fs.writeFile(file.source, body) - ]).spread(function(doc){ + ]).spread(function(doc) { id = doc._id; return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page._id.should.eql(id); @@ -188,7 +188,7 @@ describe('asset', function(){ }); }); - it('page - type: delete', function(){ + it('page - type: delete', function() { var file = newFile({ path: 'hello.swig', type: 'delete' @@ -197,25 +197,25 @@ describe('asset', function(){ return Page.insert({ source: file.path, path: 'hello.html' - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { should.not.exist(Page.findOne({source: file.path})); }); }); - it('page - use the status of the source file if date not set', function(){ + it('page - use the status of the source file if date not set', function() { var file = newFile({ path: 'hello.swig', type: 'create' }); - return fs.writeFile(file.source, '').then(function(){ + return fs.writeFile(file.source, '').then(function() { return Promise.all([ fs.stat(file.source), process(file) ]); - }).spread(function(stats){ + }).spread(function(stats) { var page = Page.findOne({source: file.path}); page.date.toDate().should.eql(stats.ctime); @@ -228,7 +228,7 @@ describe('asset', function(){ }); }); - it('page - permalink', function(){ + it('page - permalink', function() { var body = [ 'title: "Hello world"', 'permalink: foo.html', @@ -241,9 +241,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.path.should.eql('foo.html'); @@ -255,7 +255,7 @@ describe('asset', function(){ }); }); - it('page - permalink (without extension name)', function(){ + it('page - permalink (without extension name)', function() { var body = [ 'title: "Hello world"', 'permalink: foo', @@ -268,9 +268,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.path.should.eql('foo.html'); @@ -282,7 +282,7 @@ describe('asset', function(){ }); }); - it('page - permalink (with trailing slash)', function(){ + it('page - permalink (with trailing slash)', function() { var body = [ 'title: "Hello world"', 'permalink: foo/', @@ -295,9 +295,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.path.should.eql('foo/index.html'); @@ -309,7 +309,7 @@ describe('asset', function(){ }); }); - it('page - set layout to false if output is not html', function(){ + it('page - set layout to false if output is not html', function() { var body = 'foo: 1'; var file = newFile({ @@ -318,9 +318,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.layout.should.eql('false'); @@ -332,7 +332,7 @@ describe('asset', function(){ }); }); - it('page - don\'t set layout to false if layout is set but output is not html', function(){ + it('page - don\'t set layout to false if layout is set but output is not html', function() { var body = [ 'layout: something', '---', @@ -345,9 +345,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.layout.should.eql('something'); @@ -359,7 +359,7 @@ describe('asset', function(){ }); }); - it('page - parse date', function(){ + it('page - parse date', function() { var body = [ 'title: "Hello world"', 'date: Apr 24 2014', @@ -373,9 +373,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.date.format(dateFormat).should.eql('2014-04-24 00:00:00'); @@ -388,7 +388,7 @@ describe('asset', function(){ }); }); - it('page - use file stats instead if date is invalid', function(){ + it('page - use file stats instead if date is invalid', function() { var body = [ 'title: "Hello world"', 'date: yomama', @@ -402,12 +402,12 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return Promise.all([ file.stat(), process(file) ]); - }).spread(function(stats){ + }).spread(function(stats) { var page = Page.findOne({source: file.path}); page.date.toDate().should.eql(stats.ctime); @@ -420,7 +420,7 @@ describe('asset', function(){ }); }); - it('page - don\'t remove extension name', function(){ + it('page - don\'t remove extension name', function() { var body = ''; var file = newFile({ @@ -429,9 +429,9 @@ describe('asset', function(){ content: new Buffer(body) }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.path.should.eql('test.min.js'); @@ -443,7 +443,7 @@ describe('asset', function(){ }); }); - it('page - timezone', function(){ + it('page - timezone', function() { var body = [ 'title: "Hello world"', 'date: Apr 24 2014', @@ -459,9 +459,9 @@ describe('asset', function(){ hexo.config.timezone = 'UTC'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var page = Page.findOne({source: file.path}); page.date.utc().format(dateFormat).should.eql('2014-04-24 00:00:00'); @@ -475,4 +475,4 @@ describe('asset', function(){ ]); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/processors/common.js b/test/scripts/processors/common.js index 9cf367be83..107942d886 100644 --- a/test/scripts/processors/common.js +++ b/test/scripts/processors/common.js @@ -1,24 +1,24 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var moment = require('moment'); -describe('common', function(){ +describe('common', function() { var common = require('../../../lib/plugins/processor/common'); - it('isTmpFile()', function(){ + it('isTmpFile()', function() { common.isTmpFile('foo').should.be.false; common.isTmpFile('foo%').should.be.true; common.isTmpFile('foo~').should.be.true; }); - it('isHiddenFile()', function(){ + it('isHiddenFile()', function() { common.isHiddenFile('foo').should.be.false; common.isHiddenFile('_foo').should.be.true; common.isHiddenFile('foo/_bar').should.be.true; }); - it('ignoreTmpAndHiddenFile()', function(){ + it('ignoreTmpAndHiddenFile()', function() { var pattern = common.ignoreTmpAndHiddenFile; pattern.match('foo').should.be.true; @@ -28,7 +28,7 @@ describe('common', function(){ pattern.match('foo/_bar').should.be.false; }); - it('toDate()', function(){ + it('toDate()', function() { var m = moment(); var d = new Date(); @@ -40,4 +40,4 @@ describe('common', function(){ common.toDate('Apr 24 2014').should.eql(new Date(2014, 3, 24)); should.not.exist(common.toDate('foo')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/processors/data.js b/test/scripts/processors/data.js index 8852a7abc3..8663b3e909 100644 --- a/test/scripts/processors/data.js +++ b/test/scripts/processors/data.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line var Promise = require('bluebird'); var fs = require('hexo-fs'); var pathFn = require('path'); -describe('data', function(){ +describe('data', function() { var Hexo = require('../../../lib/hexo'); var baseDir = pathFn.join(__dirname, 'data_test'); var hexo = new Hexo(baseDir); @@ -15,7 +15,7 @@ describe('data', function(){ var File = source.File; var Data = hexo.model('Data'); - function newFile(options){ + function newFile(options) { var path = options.path; options.params = { @@ -28,17 +28,17 @@ describe('data', function(){ return new File(options); } - before(function(){ - return fs.mkdirs(baseDir).then(function(){ + before(function() { + return fs.mkdirs(baseDir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(baseDir); }); - it('pattern', function(){ + it('pattern', function() { var pattern = processor.pattern; pattern.match('_data/users.json').should.be.ok; @@ -46,7 +46,7 @@ describe('data', function(){ should.not.exist(pattern.match('users.json')); }); - it('type: create - yaml', function(){ + it('type: create - yaml', function() { var body = 'foo: bar'; var file = newFile({ @@ -55,7 +55,7 @@ describe('data', function(){ content: new Buffer(body) }); - return process(file).then(function(){ + return process(file).then(function() { var data = Data.findById('users'); data.data.should.eql({foo: 'bar'}); @@ -64,7 +64,7 @@ describe('data', function(){ }); }); - it('type: create - json', function(){ + it('type: create - json', function() { var body = '{"foo": 1}'; var file = newFile({ @@ -73,7 +73,7 @@ describe('data', function(){ content: new Buffer(body) }); - return process(file).then(function(){ + return process(file).then(function() { var data = Data.findById('users'); data.data.should.eql({foo: 1}); @@ -82,19 +82,19 @@ describe('data', function(){ }); }); - it('type: create - others', function(){ + it('type: create - others', function() { var file = newFile({ path: 'users.txt', type: 'create', content: new Buffer('') }); - return process(file).then(function(){ + return process(file).then(function() { should.not.exist(Data.findById('users')); }); }); - it('type: update', function(){ + it('type: update', function() { var body = 'foo: bar'; var file = newFile({ @@ -106,9 +106,9 @@ describe('data', function(){ return Data.insert({ _id: 'users', data: {} - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { var data = Data.findById('users'); data.data.should.eql({foo: 'bar'}); @@ -117,7 +117,7 @@ describe('data', function(){ }); }); - it('type: delete', function(){ + it('type: delete', function() { var file = newFile({ path: 'users.yml', type: 'delete', @@ -127,10 +127,10 @@ describe('data', function(){ return Data.insert({ _id: 'users', data: {foo: 'bar'} - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { should.not.exist(Data.findById('users')); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/processors/index.js b/test/scripts/processors/index.js index e7034209ee..5ad257b80a 100644 --- a/test/scripts/processors/index.js +++ b/test/scripts/processors/index.js @@ -1,8 +1,8 @@ 'use strict'; -describe('Processors', function(){ +describe('Processors', function() { require('./asset'); require('./common'); require('./data'); require('./post'); -}); \ No newline at end of file +}); diff --git a/test/scripts/processors/post.js b/test/scripts/processors/post.js index 25b311a39d..1f839997e1 100644 --- a/test/scripts/processors/post.js +++ b/test/scripts/processors/post.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'); @@ -9,7 +9,7 @@ var defaultConfig = require('../../../lib/hexo/default_config'); var dateFormat = 'YYYY-MM-DD HH:mm:ss'; var newPostName = defaultConfig.new_post_name; -describe('post', function(){ +describe('post', function() { var Hexo = require('../../../lib/hexo'); var baseDir = pathFn.join(__dirname, 'post_test'); var hexo = new Hexo(baseDir); @@ -21,7 +21,7 @@ describe('post', function(){ var PostAsset = hexo.model('PostAsset'); var Post = hexo.model('Post'); - function newFile(options){ + function newFile(options) { var path = options.path; options.path = (options.published ? '_posts' : '_drafts') + '/' + path; @@ -35,17 +35,17 @@ describe('post', function(){ return new File(options); } - before(function(){ - return fs.mkdirs(baseDir).then(function(){ + before(function() { + return fs.mkdirs(baseDir).then(function() { return hexo.init(); }); }); - after(function(){ + after(function() { return fs.rmdir(baseDir); }); - it('pattern', function(){ + it('pattern', function() { pattern.match('_posts/foo.html').should.eql({ published: true, path: 'foo.html' @@ -63,7 +63,7 @@ describe('post', function(){ pattern.match('_foo/bar.html').should.be.false; }); - it('asset - post_asset_folder disabled', function(){ + it('asset - post_asset_folder disabled', function() { hexo.config.post_asset_folder = false; var file = newFile({ @@ -72,13 +72,13 @@ describe('post', function(){ type: 'create' }); - return process(file).then(function(){ + return process(file).then(function() { var id = 'source/' + file.path; should.not.exist(PostAsset.findById(id)); }); }); - it('asset - type: create', function(){ + it('asset - type: create', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -92,10 +92,10 @@ describe('post', function(){ return Post.insert({ source: '_posts/foo.html', slug: 'foo' - }).then(function(doc){ + }).then(function(doc) { postId = doc._id; return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; var id = 'source/' + file.path; @@ -109,7 +109,7 @@ describe('post', function(){ }); }); - it('asset - type: update', function(){ + it('asset - type: update', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -123,16 +123,16 @@ describe('post', function(){ return Post.insert({ source: '_posts/foo.html', slug: 'foo' - }).then(function(post){ + }).then(function(post) { return PostAsset.insert({ _id: id, slug: file.path, modified: false, post: post._id }); - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; var asset = PostAsset.findById(id); @@ -143,7 +143,7 @@ describe('post', function(){ }); }); - it('asset - type: skip', function(){ + it('asset - type: skip', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -157,27 +157,27 @@ describe('post', function(){ return Post.insert({ source: '_posts/foo.html', slug: 'foo' - }).then(function(post){ + }).then(function(post) { return PostAsset.insert({ _id: id, slug: file.path, modified: false, post: post._id }); - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; var asset = PostAsset.findById(id); asset.modified.should.be.false; - return Post.removeById(asset.post) + return Post.removeById(asset.post); }); }); - it('asset - type: delete', function(){ + it('asset - type: delete', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -192,7 +192,7 @@ describe('post', function(){ return Post.insert({ source: '_posts/foo.html', slug: 'foo' - }).then(function(post){ + }).then(function(post) { postId = post._id; return PostAsset.insert({ @@ -201,9 +201,9 @@ describe('post', function(){ modified: false, post: postId }); - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; should.not.exist(PostAsset.findById(id)); @@ -211,7 +211,7 @@ describe('post', function(){ }); }); - it('asset - skip if can\'t find a matching post', function(){ + it('asset - skip if can\'t find a matching post', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -222,13 +222,13 @@ describe('post', function(){ var id = 'source/' + file.path; - return process(file).then(function(){ + return process(file).then(function() { hexo.config.post_asset_folder = false; should.not.exist(PostAsset.findById(id)); }); }); - it('asset - the related post has been deleted', function(){ + it('asset - the related post has been deleted', function() { hexo.config.post_asset_folder = true; var file = newFile({ @@ -242,16 +242,16 @@ describe('post', function(){ return PostAsset.insert({ _id: id, slug: file.path - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; should.not.exist(PostAsset.findById(id)); }); }); - it('post - type: create', function(){ + it('post - type: create', function() { var body = [ 'title: "Hello world"', 'date: 2006-01-02 15:04:05', @@ -266,9 +266,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.title.should.eql('Hello world'); @@ -287,7 +287,7 @@ describe('post', function(){ }); }); - it('post - type: update', function(){ + it('post - type: update', function() { var body = [ 'title: "New world"', '---' @@ -304,10 +304,10 @@ describe('post', function(){ return Promise.all([ Post.insert({source: file.path, slug: 'foo'}), fs.writeFile(file.source, body) - ]).spread(function(doc){ + ]).spread(function(doc) { id = doc._id; return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post._id.should.eql(id); @@ -320,7 +320,7 @@ describe('post', function(){ }); }); - it('post - type: delete', function(){ + it('post - type: delete', function() { var file = newFile({ path: 'foo.html', published: true, @@ -330,14 +330,14 @@ describe('post', function(){ return Post.insert({ source: file.path, slug: 'foo' - }).then(function(){ + }).then(function() { return process(file); - }).then(function(){ + }).then(function() { should.not.exist(Post.findOne({source: file.path})); }); }); - it('post - parse file name', function(){ + it('post - parse file name', function() { var body = [ 'title: "Hello world"', '---' @@ -351,9 +351,9 @@ describe('post', function(){ hexo.config.new_post_name = ':year/:month/:day/:title'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.new_post_name = newPostName; var post = Post.findOne({source: file.path}); @@ -368,7 +368,7 @@ describe('post', function(){ }); }); - it('post - extra data in file name', function(){ + it('post - extra data in file name', function() { var body = [ 'title: "Hello world"', '---' @@ -382,9 +382,9 @@ describe('post', function(){ hexo.config.new_post_name = ':lang/:title'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.new_post_name = newPostName; var post = Post.findOne({source: file.path}); @@ -398,7 +398,7 @@ describe('post', function(){ }); }); - it('post - file name does not match to the config', function(){ + it('post - file name does not match to the config', function() { var body = [ 'title: "Hello world"', '---' @@ -412,9 +412,9 @@ describe('post', function(){ hexo.config.new_post_name = ':year/:month/:day/:title'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.new_post_name = newPostName; var post = Post.findOne({source: file.path}); @@ -428,7 +428,7 @@ describe('post', function(){ }); }); - it('post - published', function(){ + it('post - published', function() { var body = [ 'title: "Hello world"', 'published: false', @@ -441,9 +441,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.published.should.be.false; @@ -455,7 +455,7 @@ describe('post', function(){ }); }); - it('post - always set published: false for drafts', function(){ + it('post - always set published: false for drafts', function() { var body = [ 'title: "Hello world"', 'published: true', @@ -468,9 +468,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.published.should.be.false; @@ -482,7 +482,7 @@ describe('post', function(){ }); }); - it('post - use the status of the source file if date not set', function(){ + it('post - use the status of the source file if date not set', function() { var body = [ 'title: "Hello world"', '---' @@ -494,12 +494,12 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return Promise.all([ file.stat(), process(file) ]); - }).spread(function(stats){ + }).spread(function(stats) { var post = Post.findOne({source: file.path}); post.date.toDate().should.eql(stats.ctime); @@ -512,7 +512,7 @@ describe('post', function(){ }); }); - it('post - photo is an alias for photos', function(){ + it('post - photo is an alias for photos', function() { var body = [ 'title: "Hello world"', 'photo:', @@ -527,9 +527,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.photos.should.eql([ @@ -546,7 +546,7 @@ describe('post', function(){ }); }); - it('post - photos (not array)', function(){ + it('post - photos (not array)', function() { var body = [ 'title: "Hello world"', 'photos: http://hexo.io/foo.jpg', @@ -559,9 +559,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.photos.should.eql([ @@ -575,7 +575,7 @@ describe('post', function(){ }); }); - it('post - link without title', function(){ + it('post - link without title', function() { var body = [ 'link: http://hexo.io/', '---' @@ -587,9 +587,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.link.should.eql('http://hexo.io/'); @@ -602,7 +602,7 @@ describe('post', function(){ }); }); - it('post - category is an alias for categories', function(){ + it('post - category is an alias for categories', function() { var body = [ 'title: "Hello world"', 'category:', @@ -617,13 +617,13 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); should.not.exist(post.category); - post.categories.map(function(item){ + post.categories.map(function(item) { return item.name; }).should.eql(['foo', 'bar']); @@ -634,7 +634,7 @@ describe('post', function(){ }); }); - it('post - categories (not array)', function(){ + it('post - categories (not array)', function() { var body = [ 'title: "Hello world"', 'categories: foo', @@ -647,12 +647,12 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); - post.categories.map(function(item){ + post.categories.map(function(item) { return item.name; }).should.eql(['foo']); @@ -663,7 +663,7 @@ describe('post', function(){ }); }); - it('post - tag is an alias for tags', function(){ + it('post - tag is an alias for tags', function() { var body = [ 'title: "Hello world"', 'tags:', @@ -678,13 +678,13 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); should.not.exist(post.tag); - post.tags.map(function(item){ + post.tags.map(function(item) { return item.name; }).should.have.members(['foo', 'bar']); @@ -695,7 +695,7 @@ describe('post', function(){ }); }); - it('post - tags (not array)', function(){ + it('post - tags (not array)', function() { var body = [ 'title: "Hello world"', 'tags: foo', @@ -708,12 +708,12 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); - post.tags.map(function(item){ + post.tags.map(function(item) { return item.name; }).should.eql(['foo']); @@ -724,7 +724,7 @@ describe('post', function(){ }); }); - it('post - post_asset_folder enabled', function(){ + it('post - post_asset_folder enabled', function() { hexo.config.post_asset_folder = true; var body = [ @@ -744,9 +744,9 @@ describe('post', function(){ return Promise.all([ fs.writeFile(file.source, body), fs.writeFile(assetPath, '') - ]).then(function(){ + ]).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.post_asset_folder = false; var post = Post.findOne({source: file.path}); @@ -764,7 +764,7 @@ describe('post', function(){ }); }); - it('post - post_asset_folder disabled', function(){ + it('post - post_asset_folder disabled', function() { hexo.config.post_asset_folder = false; var file = newFile({ @@ -779,9 +779,9 @@ describe('post', function(){ return Promise.all([ fs.writeFile(file.source, ''), fs.writeFile(assetPath, '') - ]).then(function(){ + ]).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); should.not.exist(PostAsset.findById(assetId)); @@ -793,7 +793,7 @@ describe('post', function(){ }); }); - it('post - parse date', function(){ + it('post - parse date', function() { var body = [ 'title: "Hello world"', 'date: Apr 24 2014', @@ -807,9 +807,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.date.format(dateFormat).should.eql('2014-04-24 00:00:00'); @@ -822,7 +822,7 @@ describe('post', function(){ }); }); - it('post - use file stats instead if date is invalid', function(){ + it('post - use file stats instead if date is invalid', function() { var body = [ 'title: "Hello world"', 'date: yomama', @@ -836,12 +836,12 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return Promise.all([ file.stat(), process(file) ]); - }).spread(function(stats){ + }).spread(function(stats) { var post = Post.findOne({source: file.path}); post.date.toDate().should.eql(stats.ctime); @@ -854,7 +854,7 @@ describe('post', function(){ }); }); - it('post - timezone', function(){ + it('post - timezone', function() { var body = [ 'title: "Hello world"', 'date: 2014-04-24', @@ -870,9 +870,9 @@ describe('post', function(){ hexo.config.timezone = 'UTC'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.date.utc().format(dateFormat).should.eql('2014-04-24 00:00:00'); @@ -887,7 +887,7 @@ describe('post', function(){ }); }); - it('post - new_post_name timezone', function(){ + it('post - new_post_name timezone', function() { var body = [ 'title: "Hello world"', '---' @@ -902,9 +902,9 @@ describe('post', function(){ hexo.config.new_post_name = ':year/:month/:day/:title'; hexo.config.timezone = 'UTC'; - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { hexo.config.new_post_name = newPostName; hexo.config.timezone = ''; @@ -919,7 +919,7 @@ describe('post', function(){ }); }); - it('post - permalink', function(){ + it('post - permalink', function() { var body = [ 'title: "Hello world"', 'permalink: foooo', @@ -932,9 +932,9 @@ describe('post', function(){ type: 'create' }); - return fs.writeFile(file.source, body).then(function(){ + return fs.writeFile(file.source, body).then(function() { return process(file); - }).then(function(){ + }).then(function() { var post = Post.findOne({source: file.path}); post.slug.should.eql('foooo'); @@ -944,4 +944,4 @@ describe('post', function(){ ]); }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/renderers/index.js b/test/scripts/renderers/index.js index 26296a099d..47bafa9ed5 100644 --- a/test/scripts/renderers/index.js +++ b/test/scripts/renderers/index.js @@ -1,8 +1,8 @@ 'use strict'; -describe('Renderers', function(){ +describe('Renderers', function() { require('./json'); require('./plain'); require('./swig'); require('./yaml'); -}); \ No newline at end of file +}); diff --git a/test/scripts/renderers/json.js b/test/scripts/renderers/json.js index c693b1388a..1004193fff 100644 --- a/test/scripts/renderers/json.js +++ b/test/scripts/renderers/json.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('json', function(){ +describe('json', function() { var r = require('../../../lib/plugins/renderer/json'); - it('normal', function(){ + it('normal', function() { var data = { foo: 1, bar: { @@ -15,4 +15,4 @@ describe('json', function(){ r({text: JSON.stringify(data)}).should.eql(data); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/renderers/plain.js b/test/scripts/renderers/plain.js index bbba34c8a8..a0a410c18e 100644 --- a/test/scripts/renderers/plain.js +++ b/test/scripts/renderers/plain.js @@ -1,11 +1,11 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('plain', function(){ +describe('plain', function() { var r = require('../../../lib/plugins/renderer/plain'); - it('normal', function(){ + it('normal', function() { r({text: '123'}).should.eql('123'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/renderers/swig.js b/test/scripts/renderers/swig.js index ced3c73c79..ead120a0c1 100644 --- a/test/scripts/renderers/swig.js +++ b/test/scripts/renderers/swig.js @@ -1,12 +1,11 @@ 'use strict'; -var should = require('chai').should(); -var fs = require('hexo-fs'); +var should = require('chai').should(); // eslint-disable-line -describe('swig', function(){ +describe('swig', function() { var r = require('../../../lib/plugins/renderer/swig'); - it('normal', function(){ + it('normal', function() { var body = [ 'Hello {{ name }}!' ].join('\n'); @@ -16,7 +15,7 @@ describe('swig', function(){ }).should.eql('Hello world!'); }); - it('override "for" tag', function(){ + it('override "for" tag', function() { var body = [ '{% for x in arr %}', '{{ x }}', @@ -25,7 +24,7 @@ describe('swig', function(){ var data = { arr: { - toArray: function(){ + toArray: function() { return [1, 2, 3]; } } @@ -33,4 +32,4 @@ describe('swig', function(){ r({text: body}, data).should.eql('123'); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/renderers/yaml.js b/test/scripts/renderers/yaml.js index 3a1be2d221..01e2d39934 100644 --- a/test/scripts/renderers/yaml.js +++ b/test/scripts/renderers/yaml.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('yaml', function(){ +describe('yaml', function() { var r = require('../../../lib/plugins/renderer/yaml'); - it('normal', function(){ + it('normal', function() { r({text: 'foo: 1'}).should.eql({foo: 1}); }); - it('escape', function(){ + it('escape', function() { var body = [ 'foo: 1', 'bar:', @@ -23,4 +23,4 @@ describe('yaml', function(){ } }); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/asset_img.js b/test/scripts/tags/asset_img.js index 872d390103..f4cc0f6197 100644 --- a/test/scripts/tags/asset_img.js +++ b/test/scripts/tags/asset_img.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('asset_img', function(){ +describe('asset_img', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var assetImgTag = require('../../../lib/plugins/tag/asset_img')(hexo); @@ -12,17 +12,17 @@ describe('asset_img', function(){ hexo.config.permalink = ':title/'; - function assetImg(args){ + function assetImg(args) { return assetImgTag.call(post, args.split(' ')); } - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return Post.insert({ source: 'foo.md', slug: 'foo' }); - }).then(function(post_){ + }).then(function(post_) { post = post_; return PostAsset.insert({ @@ -33,19 +33,19 @@ describe('asset_img', function(){ }); }); - it('default', function(){ + it('default', function() { assetImg('bar').should.eql('bar'); }); - it('default', function(){ + it('default', function() { assetImg('bar title').should.eql('title'); }); - it('no slug', function(){ + it('no slug', function() { should.not.exist(assetImg('')); }); - it('asset not found', function(){ + it('asset not found', function() { should.not.exist(assetImg('boo')); }); }); diff --git a/test/scripts/tags/asset_link.js b/test/scripts/tags/asset_link.js index 5864668dcf..1a21f6c742 100644 --- a/test/scripts/tags/asset_link.js +++ b/test/scripts/tags/asset_link.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('asset_link', function(){ +describe('asset_link', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var assetLinkTag = require('../../../lib/plugins/tag/asset_link')(hexo); @@ -12,17 +12,17 @@ describe('asset_link', function(){ hexo.config.permalink = ':title/'; - function assetLink(args){ + function assetLink(args) { return assetLinkTag.call(post, args.split(' ')); } - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return Post.insert({ source: 'foo.md', slug: 'foo' }); - }).then(function(post_){ + }).then(function(post_) { post = post_; return PostAsset.insert({ @@ -33,19 +33,19 @@ describe('asset_link', function(){ }); }); - it('default', function(){ + it('default', function() { assetLink('bar').should.eql('bar'); }); - it('title', function(){ + it('title', function() { assetLink('bar Hello world').should.eql('Hello world'); }); - it('no slug', function(){ + it('no slug', function() { should.not.exist(assetLink('')); }); - it('asset not found', function(){ + it('asset not found', function() { should.not.exist(assetLink('boo')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/asset_path.js b/test/scripts/tags/asset_path.js index 097002ee5c..ee1a642a38 100644 --- a/test/scripts/tags/asset_path.js +++ b/test/scripts/tags/asset_path.js @@ -1,8 +1,8 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('asset_path', function(){ +describe('asset_path', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var assetPathTag = require('../../../lib/plugins/tag/asset_path')(hexo); @@ -12,17 +12,17 @@ describe('asset_path', function(){ hexo.config.permalink = ':title/'; - function assetPath(args){ + function assetPath(args) { return assetPathTag.call(post, args.split(' ')); } - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return Post.insert({ source: 'foo.md', slug: 'foo' }); - }).then(function(post_){ + }).then(function(post_) { post = post_; return PostAsset.insert({ @@ -33,15 +33,15 @@ describe('asset_path', function(){ }); }); - it('default', function(){ + it('default', function() { assetPath('bar').should.eql('/foo/bar'); }); - it('no slug', function(){ + it('no slug', function() { should.not.exist(assetPath('')); }); - it('asset not found', function(){ + it('asset not found', function() { should.not.exist(assetPath('boo')); }); -}); \ No newline at end of file +}); diff --git a/test/scripts/tags/blockquote.js b/test/scripts/tags/blockquote.js index 58acef45cd..216e49c1f9 100644 --- a/test/scripts/tags/blockquote.js +++ b/test/scripts/tags/blockquote.js @@ -1,48 +1,48 @@ 'use strict'; -var should = require('chai').should(); +var should = require('chai').should(); // eslint-disable-line -describe('blockquote', function(){ +describe('blockquote', function() { var Hexo = require('../../../lib/hexo'); var hexo = new Hexo(__dirname); var blockquote = require('../../../lib/plugins/tag/blockquote')(hexo); - before(function(){ - return hexo.init().then(function(){ + before(function() { + return hexo.init().then(function() { return hexo.loadPlugin(require.resolve('hexo-renderer-marked')); }); }); - var bq = function(args, content){ + var bq = function(args, content) { return blockquote(args.split(' '), content || ''); }; - it('default', function(){ + it('default', function() { var result = bq('', '123456 **bold** and *italic*'); result.should.eql('

    123456 bold and italic

    \n
    '); }); - it('author', function(){ + it('author', function() { var result = bq('John Doe', ''); result.should.eql('
    John Doe
    '); }); - it('source', function(){ + it('source', function() { var result = bq('Jane Austen, Pride and Prejudice'); result.should.eql('
    Jane AustenPride and Prejudice
    '); }); - 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('
    ' + 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('

    123456 bold and italic

    \n
    '); }); - 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;