From cee0fa74d3b8e8b9315e4b78753353bb2f65c69b Mon Sep 17 00:00:00 2001 From: levym Date: Sat, 1 Oct 2016 15:40:16 +0100 Subject: [PATCH] Refactor compilation * Uplift npm packages * Remove temp files * Code cleanup * Fix image npm module versions --- .editorconfig | 13 ++ .eslintrc.json | 41 ++++ .gitignore | 9 +- .jshintrc | 53 ----- .travis.yml | 4 +- CHANGELOG.md | 16 ++ TODO.md | 5 - gulp/lib/compile-dates.js | 289 ++++++++++++------------- gulp/lib/compile-home.js | 270 ++++++++++++------------ gulp/lib/compile-options.js | 5 +- gulp/lib/compile-pages.js | 194 ++++++++--------- gulp/lib/compile-rss.js | 114 +++++----- gulp/lib/compile-tags.js | 287 ++++++++++++------------- gulp/lib/dates.js | 3 +- gulp/lib/downzero.js | 47 +++-- gulp/lib/drafts.js | 1 - gulp/lib/paths.js | 10 +- gulp/lib/tags.js | 2 +- gulp/tasks/compile.js | 21 +- gulp/tasks/content.js | 5 +- gulp/tests/compile-dates.spec.js | 242 ++++++++++----------- gulp/tests/compile-home.spec.js | 256 +++++++++++----------- gulp/tests/compile-options.spec.js | 154 +++++++------- gulp/tests/compile-pages.spec.js | 293 +++++++++++++------------- gulp/tests/compile-rss.spec.js | 132 ++++++------ gulp/tests/compile-tags.spec.js | 212 ++++++++++--------- gulp/tests/dates.spec.js | 3 - gulp/tests/downzero.spec.js | 32 ++- gulp/tests/drafts.spec.js | 4 - gulp/tests/paths.spec.js | 2 - gulp/tests/remove-dir.spec.js | 59 +++--- gulp/tests/tags.spec.js | 3 - gulpfile.js | 12 +- install.js | 1 - install/content/index.md | 6 - install/files.json | 4 - install/tests/version-compare.spec.js | 2 - package.json | 112 +++++----- update.js | 1 - 39 files changed, 1468 insertions(+), 1451 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.json delete mode 100644 .jshintrc delete mode 100644 TODO.md delete mode 100644 install/content/index.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2ac1735 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf + +[*.md] +indent_style = tab + +[*.yml] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d1aa833 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,41 @@ +{ + "env": { + "node": true + }, + "extends": "eslint:recommended", + "rules": { + "indent": [ + "error", + 4, + { + "SwitchCase": 1 + } + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "no-console": [ + "error", { + "allow": ["info", "warn", "error"] + } + ] + }, + "globals": { + "process": false, + "it": false, + "afterEach": false, + "beforeEach": false, + "after": false, + "describe": false, + "before": false + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index decd7ce..8cffa6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -node_modules -coverage +node_modules/ +coverage/ npm-debug.log -.vscode/ \ No newline at end of file +debug.log +.vscode/ +.idea/ +.tmp/ \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index a82c9d6..0000000 --- a/.jshintrc +++ /dev/null @@ -1,53 +0,0 @@ -{ - "bitwise": false, - "camelcase": false, - "curly": false, - "eqeqeq": true, - "immed": false, - "indent": false, - "latedef": "nofunc", - "newcap": true, - "noarg": true, - "noempty": true, - "quotmark": false, - "unused": false, - "undef": true, - "strict": true, - "trailing": true, - "maxdepth": 6, - "maxlen": false, - "browser": true, - "sub": true, - "devel": true, - "nomen": false, - "white": false, - "jquery": true, - "laxbreak": true, - "eqnull": true, - "validthis": true, - "globalstrict": true, - "loopfunc": true, - "predef": [ - "angular", - "$script", - "snomedTestData", - "describe", - "ddescribe", - "xdescribe", - "beforeEach", - "before", - "afterEach", - "after", - "module", - "inject", - "jasmine", - "it", - "xit", - "iit", - "expect", - "spyOn", - "setFixtures", - "require", - "process" - ] -} diff --git a/.travis.yml b/.travis.yml index a24721f..4b14f10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "4.1" - - "0.12" + - "6.9" + - "4.7" before_script: - npm install -g gulp script: gulp test-ci \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fd0e022..fa9bc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Change log +## v0.2.0 (2017-01-11) + +**Features** + +* Refactor compilation +* Uplift npm packages +* Remove temp files +* Code cleanup +* Fix image npm module versions + +## v0.1.29 (2017-01-11) + +**Features** + +* Add cssIgnore configuration option + ## v0.1.28 (2016-11-11) **Fixes** diff --git a/TODO.md b/TODO.md deleted file mode 100644 index a216581..0000000 --- a/TODO.md +++ /dev/null @@ -1,5 +0,0 @@ -# TODO - -* Sitemap task -* Yeoman generator -* Related posts diff --git a/gulp/lib/compile-dates.js b/gulp/lib/compile-dates.js index bc2d4d1..92444e3 100644 --- a/gulp/lib/compile-dates.js +++ b/gulp/lib/compile-dates.js @@ -5,7 +5,6 @@ var gulp = require("gulp"), compileHandlebars = require("gulp-compile-handlebars"), rename = require("gulp-rename"), fs = require("fs"), - path = require("path"), glob = require("glob"), moment = require("moment"), _ = require("lodash"), @@ -16,163 +15,165 @@ var gulp = require("gulp"), compileDrafts = require("../lib/drafts"), promiseList = require("../lib/promises"); -module.exports.run = function (rootPath, done, error) { - var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); - var gulpVersion = require("gulp/package").version; - var compileOptionsObj = compileOptions(rootPath); - - glob(rootPath + "/build/content/**/*.json", { - cwd: rootPath - }, function (err, files) { - if (err) { - error(err); - } else { - var datePosts = {}, - posts = [], - allPosts = []; - - files.forEach(function (file) { - var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - - if (fileData.status && fileData.status === "draft" && !compileDrafts()) { - return; - } +module.exports = function (rootPath) { + return new Promise(function(resolve, reject) { + var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); + var gulpVersion = require("gulp/package").version; + var compileOptionsObj = compileOptions(rootPath); + + glob(rootPath + "/build/content/**/*.json", { + cwd: "." + }, function (err, files) { + if (err) { + reject(err); + } else { + var datePosts = {}, + posts = [], + allPosts = []; - if (!fileData.date || !fileData.template) { - return; - } + files.forEach(function (file) { + var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - // check and fill-in missing file meta data - fileData = compileOptionsObj.checkContent(fileData); - - var metaData = { - title: fileData.title, - description: resolvePaths.resolve(fileData.body, "../.."), - url: "../../" + fileData.slug + "/", - tagStr: fileData.tags, - tags: (fileData.tags ? tags.getTagsAsLinks("../..", fileData.tags) : undefined), - date: fileData.date, - post_class: "post" + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), - meta: fileData - }; - - if (fileData.date && fileData.template === "post.hbs") { - posts.push(metaData); - } + if (fileData.status && fileData.status === "draft" && !compileDrafts()) { + return; + } - if (fileData.date) { - var dateMonth = fileData.date.substr(0, 7); //2014-12 - if (datePosts[dateMonth]) { - datePosts[dateMonth].push(metaData); - } else { - datePosts[dateMonth] = [metaData]; + if (!fileData.date || !fileData.template) { + return; } - } - }); - - if (_.size(datePosts)) { - var promises = []; - posts.sort(dates.sortFunc); - allPosts = _.cloneDeep(posts); - - for (var dateMonth in datePosts) { - // sort the dateMonth posts - datePosts[dateMonth].sort(dates.sortFunc); - - var templateData = { - date: moment().format("YYYY-MM-DD"), - resourcePath: "../..", - generator: "Gulp " + gulpVersion, - meta_title: siteData.title, - url: "../..", - site: siteData, - posts: datePosts[dateMonth], - body_class: "home-template", - rss: "../.." + siteData.rss, - dateStr: moment(dateMonth, "YYYY-MM").format("MMMM YYYY") + + // check and fill-in missing file meta data + fileData = compileOptionsObj.checkContent(fileData); + + var metaData = { + title: fileData.title, + description: resolvePaths.resolve(fileData.body, "../.."), + url: "../../" + fileData.slug + "/", + tagStr: fileData.tags, + tags: (fileData.tags ? tags.getTagsAsLinks("../..", fileData.tags) : undefined), + date: fileData.date, + post_class: "post" + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), + meta: fileData }; - if (siteData.maxItems && datePosts[dateMonth].length > siteData.maxItems) { - // how many pages do we need to create? - var totalPages = Math.ceil(datePosts[dateMonth].length / siteData.maxItems); - - // shorten posts - var paginatedPosts = datePosts[dateMonth].splice(siteData.maxItems); - - for (var i = 1; i < totalPages; i++) { - var pageNumber = i + 1; - var nextPosts = paginatedPosts.splice(0, siteData.maxItems); - - // update the resource paths - nextPosts.forEach(function (post) { - post.description = resolvePaths.resolve(post.meta.body, "../../../.."); - post.url = "../../../../" + post.meta.slug; - }); - - // create custom template data for this paginated page - var pageTemplateData = _.cloneDeep(templateData); - _.extend(pageTemplateData, { - posts: nextPosts, - resourcePath: "../../../..", - url: "../../../..", - rss: "../../../.." + siteData.rss, - allDates: dates.getAllDatesAsLinks("../../../..", allPosts), - allTags: tags.getAllTagsAsLinks("../../../..", allPosts) - }); - delete pageTemplateData.pages; - - // add pagination data - if (pageNumber === 2) { - pageTemplateData.prevUrl = "../../"; - } else { - pageTemplateData.prevUrl = "../" + (pageNumber - 1); - } + if (fileData.date && fileData.template === "post.hbs") { + posts.push(metaData); + } - if (pageNumber < totalPages) { - pageTemplateData.nextUrl = "../" + (pageNumber + 1); + if (fileData.date) { + var dateMonth = fileData.date.substr(0, 7); //2014-12 + if (datePosts[dateMonth]) { + datePosts[dateMonth].push(metaData); + } else { + datePosts[dateMonth] = [metaData]; + } + } + }); + + if (_.size(datePosts)) { + var promises = []; + posts.sort(dates.sortFunc); + allPosts = _.cloneDeep(posts); + + for (var dateMonth in datePosts) { + // sort the dateMonth posts + datePosts[dateMonth].sort(dates.sortFunc); + + var templateData = { + date: moment().format("YYYY-MM-DD"), + resourcePath: "../..", + generator: "Gulp " + gulpVersion, + meta_title: siteData.title, + url: "../..", + site: siteData, + posts: datePosts[dateMonth], + body_class: "home-template", + rss: "../.." + siteData.rss, + dateStr: moment(dateMonth, "YYYY-MM").format("MMMM YYYY") + }; + + if (siteData.maxItems && datePosts[dateMonth].length > siteData.maxItems) { + // how many pages do we need to create? + var totalPages = Math.ceil(datePosts[dateMonth].length / siteData.maxItems); + + // shorten posts + var paginatedPosts = datePosts[dateMonth].splice(siteData.maxItems); + + for (var i = 1; i < totalPages; i++) { + var pageNumber = i + 1; + var nextPosts = paginatedPosts.splice(0, siteData.maxItems); + + // update the resource paths + nextPosts.forEach(function (post) { + post.description = resolvePaths.resolve(post.meta.body, "../../../.."); + post.url = "../../../../" + post.meta.slug; + }); + + // create custom template data for this paginated page + var pageTemplateData = _.cloneDeep(templateData); + _.extend(pageTemplateData, { + posts: nextPosts, + resourcePath: "../../../..", + url: "../../../..", + rss: "../../../.." + siteData.rss, + allDates: dates.getAllDatesAsLinks("../../../..", allPosts), + allTags: tags.getAllTagsAsLinks("../../../..", allPosts) + }); + delete pageTemplateData.pages; + + // add pagination data + if (pageNumber === 2) { + pageTemplateData.prevUrl = "../../"; + } else { + pageTemplateData.prevUrl = "../" + (pageNumber - 1); + } + + if (pageNumber < totalPages) { + pageTemplateData.nextUrl = "../" + (pageNumber + 1); + } + + pageTemplateData.totalPages = totalPages; + + promises.push(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build/date/" + dateMonth + "/page/" + pageNumber)) + .on("error", reject) + .on("end", resolve); + })); } - pageTemplateData.totalPages = totalPages; - - promises.push(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build/date/" + dateMonth + "/page/" + pageNumber)) - .on("error", reject) - .on("end", resolve); - })); + templateData.nextUrl = "../../date/" + dateMonth + "/page/2"; + templateData.totalPages = totalPages; } - templateData.nextUrl = "../../date/" + dateMonth + "/page/2"; - templateData.totalPages = totalPages; + // update template + _.extend(templateData, { + allDates: dates.getAllDatesAsLinks("../..", allPosts), + allTags: tags.getAllTagsAsLinks("../..", allPosts) + }); + + promises.unshift(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(templateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build/date/" + dateMonth)) + .on("error", reject) + .on("end", resolve); + })); } - // update template - _.extend(templateData, { - allDates: dates.getAllDatesAsLinks("../..", allPosts), - allTags: tags.getAllTagsAsLinks("../..", allPosts) - }); - - promises.unshift(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(templateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build/date/" + dateMonth)) - .on("error", reject) - .on("end", resolve); - })); + Promise.all(promiseList.filter(promises)) + .then(function () { + resolve(); + }, function (err) { + reject(err); + }); + } else { + resolve(); } - - Promise.all(promiseList.filter(promises)) - .then(function () { - done(); - }, function (err) { - error(err); - }); - } else { - done(); } - } + }); }); }; diff --git a/gulp/lib/compile-home.js b/gulp/lib/compile-home.js index c072ed8..1a98d47 100644 --- a/gulp/lib/compile-home.js +++ b/gulp/lib/compile-home.js @@ -5,7 +5,6 @@ var gulp = require("gulp"), compileHandlebars = require("gulp-compile-handlebars"), rename = require("gulp-rename"), fs = require("fs"), - path = require("path"), glob = require("glob"), moment = require("moment"), _ = require("lodash"), @@ -16,147 +15,150 @@ var gulp = require("gulp"), compileDrafts = require("../lib/drafts"), promiseList = require("../lib/promises"); -module.exports.run = function (rootPath, done, error) { - var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); - var gulpVersion = require("gulp/package").version; - var compileOptionsObj = compileOptions(rootPath); - - glob(rootPath + "/build/content/**/*.json", { - cwd: rootPath - }, function (err, files) { - if (err) { - error(err); - } else { - var posts = [], - allPosts = [], - pages = []; - - files.forEach(function (file) { - var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - - if (fileData.status && fileData.status === "draft" && !compileDrafts()) { - return; - } - - // check and fill-in missing file meta data - fileData = compileOptionsObj.checkContent(fileData); - - var metaData = { - title: fileData.title, - description: resolvePaths.resolve(fileData.body, "."), - url: "./" + fileData.slug + "/", - tagStr: fileData.tags, - tags: (fileData.tags ? tags.getTagsAsLinks(".", fileData.tags) : undefined), - date: fileData.date, - post_class: "post " + (fileData.template === "page.hbs" ? "page " : "") + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), - meta: fileData - }; - - if (fileData.date && fileData.template === "post.hbs") { - posts.push(metaData); - } else { - pages.push(metaData); - } - }); - - if (posts.length || pages.length) { - posts.sort(dates.sortFunc); - allPosts = _.cloneDeep(posts); - - var templateData = { - date: moment().format("YYYY-MM-DD"), - resourcePath: ".", - generator: "Gulp " + gulpVersion, - meta_title: siteData.title, - url: ".", - site: siteData, - posts: posts, - pages: pages, - body_class: "home-template", - rss: "." + siteData.rss, - allDates: dates.getAllDatesAsLinks(".", allPosts), - allTags: tags.getAllTagsAsLinks(".", allPosts) - }; - - var promises = []; - - if (siteData.maxItems && posts.length > siteData.maxItems) { - // how many pages do we need to create? - var totalPages = Math.ceil(posts.length / siteData.maxItems); - - // shorten posts - var paginatedPosts = posts.splice(siteData.maxItems); - - for (var i = 1; i < totalPages; i++) { - var pageNumber = i + 1; - var nextPosts = paginatedPosts.splice(0, siteData.maxItems); - - // update the resource paths - nextPosts.forEach(function (post) { - post.description = resolvePaths.resolve(post.meta.body, "../.."); - post.url = "../../" + post.meta.slug; - }); +module.exports = function (rootPath) { + return new Promise(function(resolve, reject) { + var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); + var gulpVersion = require("gulp/package").version; + var compileOptionsObj = compileOptions(rootPath); + + glob(rootPath + "/build/content/**/*.json", { + cwd: "." + }, function (err, files) { + if (err) { + reject(err); + } else { + var posts = [], + allPosts = [], + pages = []; - // create custom template data for this paginated page - var pageTemplateData = _.cloneDeep(templateData); - _.extend(pageTemplateData, { - posts: nextPosts, - resourcePath: "../..", - url: "../..", - rss: "../.." + siteData.rss, - allDates: dates.getAllDatesAsLinks("../..", allPosts), - allTags: tags.getAllTagsAsLinks("../..", allPosts) - }); - delete pageTemplateData.pages; + files.forEach(function (file) { + var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - // add pagination data - if (pageNumber === 2) { - pageTemplateData.prevUrl = "../../"; - } else { - pageTemplateData.prevUrl = "../" + (pageNumber - 1); - } + if (fileData.status && fileData.status === "draft" && !compileDrafts()) { + return; + } - if (pageNumber < totalPages) { - pageTemplateData.nextUrl = "../" + (pageNumber + 1); + // check and fill-in missing file meta data + fileData = compileOptionsObj.checkContent(fileData); + + var metaData = { + title: fileData.title, + description: resolvePaths.resolve(fileData.body, ""), + url: fileData.slug + "/", + tagStr: fileData.tags, + tags: (fileData.tags ? tags.getTagsAsLinks("", fileData.tags) : undefined), + date: fileData.date, + post_class: "post " + (fileData.template === "page.hbs" ? "page " : "") + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), + meta: fileData + }; + + if (fileData.date && fileData.template === "post.hbs") { + posts.push(metaData); + } else { + pages.push(metaData); + } + }); + + if (posts.length || pages.length) { + posts.sort(dates.sortFunc); + allPosts = _.cloneDeep(posts); + + var templateData = { + date: moment().format("YYYY-MM-DD"), + resourcePath: "", + generator: "Gulp " + gulpVersion, + meta_title: siteData.title, + url: "", + site: siteData, + posts: posts, + pages: pages, + body_class: "home-template", + rss: siteData.rss, + allDates: dates.getAllDatesAsLinks("", allPosts), + allTags: tags.getAllTagsAsLinks("", allPosts) + }; + + var promises = []; + + if (siteData.maxItems && posts.length > siteData.maxItems) { + // how many pages do we need to create? + var totalPages = Math.ceil(posts.length / siteData.maxItems); + + // shorten posts + var paginatedPosts = posts.splice(siteData.maxItems); + + for (var i = 1; i < totalPages; i++) { + var pageNumber = i + 1; + var nextPosts = paginatedPosts.splice(0, siteData.maxItems); + + // update the resource paths + nextPosts.forEach(function (post) { + post.description = resolvePaths.resolve(post.meta.body, "../.."); + post.url = "../../" + post.meta.slug; + }); + + // create custom template data for this paginated page + + var pageTemplateData = _.cloneDeep(templateData); + _.extend(pageTemplateData, { + posts: nextPosts, + resourcePath: "../..", + url: "../..", + rss: "../.." + siteData.rss, + allDates: dates.getAllDatesAsLinks("../..", allPosts), + allTags: tags.getAllTagsAsLinks("../..", allPosts) + }); + delete pageTemplateData.pages; + + // add pagination data + if (pageNumber === 2) { + pageTemplateData.prevUrl = "../../"; + } else { + pageTemplateData.prevUrl = "../" + (pageNumber - 1); + } + + if (pageNumber < totalPages) { + pageTemplateData.nextUrl = "../" + (pageNumber + 1); + } + + pageTemplateData.totalPages = totalPages; + + promises.push(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build/page/" + pageNumber)) + .on("error", reject) + .on("end", function () { + resolve(); + }); + })); } - pageTemplateData.totalPages = totalPages; - - promises.push(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build/page/" + pageNumber)) - .on("error", reject) - .on("end", function () { - resolve(); - }); - })); + // update template + templateData.nextUrl = "page/2"; + templateData.totalPages = totalPages; } - // update template - templateData.nextUrl = "./page/2"; - templateData.totalPages = totalPages; + promises.unshift(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(templateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build")) + .on("error", reject) + .on("end", resolve); + })); + + Promise.all(promiseList.filter(promises)) + .then(function () { + resolve(); + }, function (err) { + reject(err); + }); + } else { + resolve(); } - - promises.unshift(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(templateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build")) - .on("error", reject) - .on("end", resolve); - })); - - Promise.all(promiseList.filter(promises)) - .then(function () { - done(); - }, function (err) { - error(err); - }); - } else { - done(); } - } + }); }); }; diff --git a/gulp/lib/compile-options.js b/gulp/lib/compile-options.js index ebb455f..d9a4d79 100644 --- a/gulp/lib/compile-options.js +++ b/gulp/lib/compile-options.js @@ -91,7 +91,10 @@ module.exports = function (rootPath) { if (path && this.resourcePath && this.resourcePath !== "") { return this.resourcePath + path; } - return "." + path; + if (/^\//.test(path)) { + path = path.substring(1); + } + return "" + path; }, or: function (v1, v2) { return v1 || v2; diff --git a/gulp/lib/compile-pages.js b/gulp/lib/compile-pages.js index a691a3e..c66c6fb 100644 --- a/gulp/lib/compile-pages.js +++ b/gulp/lib/compile-pages.js @@ -16,109 +16,111 @@ var gulp = require("gulp"), compileDrafts = require("../lib/drafts"), promiseList = require("../lib/promises"); -module.exports.run = function (rootPath, done, error) { - var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); - var gulpVersion = require("gulp/package").version; - var compileOptionsObj = compileOptions(rootPath); - - glob(rootPath + "/build/content/**/*.json", { - cwd: rootPath - }, function (err, files) { - if (err) { - error(err); - } else { - var templatesToCreate = [], - posts = []; - - files.forEach(function (file) { - var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - - if (fileData.status && fileData.status === "draft" && !compileDrafts()) { - return; - } - - // check and fill-in missing file meta data - fileData = compileOptionsObj.checkContent(fileData); - - var tagClasses = tags.getTagClasses(fileData.tags); - - var metaData = { - title: fileData.title, - body: resolvePaths.resolve(fileData.body, ".."), - url: "../" + fileData.slug + "/", - tagStr: fileData.tags, - tags: (fileData.tags ? tags.getTagsAsLinks("..", fileData.tags) : undefined), - date: fileData.date, - post_class: "post " + (fileData.template === "page.hbs" ? "page " : "") + (fileData.tags ? tagClasses : fileData.slug), - author: (fileData.author ? siteData.authors[fileData.author] : ""), - meta: fileData - }; - - if (fileData.date && fileData.template === "post.hbs") { - posts.push(metaData); - } - - // post class - var bodyClass = "post-template"; - if (fileData.template === "page.hbs") { - bodyClass += " page-template page"; - } - - // tags - if (fileData.tags) { - bodyClass += tagClasses; - } - - var templateData = { - date: moment().format("YYYY-MM-DD"), - resourcePath: "..", - generator: "Gulp " + gulpVersion, - meta_title: fileData.title, - url: "..", - site: siteData, - post: metaData, - body_class: bodyClass, - rss: ".." + siteData.rss - }; - - var outDir = rootPath + "/build/" + path.basename(file).replace(/\.[^/.]+$/, ""); - - templatesToCreate.push({ - outDir: outDir, - templateSrc: rootPath + "/src/templates/" + fileData.template, - templateData: templateData - }); +module.exports = function (rootPath) { + return new Promise(function(resolve, reject) { + var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); + var gulpVersion = require("gulp/package").version; + var compileOptionsObj = compileOptions(rootPath); + + glob(rootPath + "/build/content/**/*.json", { + cwd: "." + }, function (err, files) { + if (err) { + reject(err); + } else { + var templatesToCreate = [], + posts = []; + + files.forEach(function (file) { + var fileData = JSON.parse(fs.readFileSync(file, "utf8")); + + if (fileData.status && fileData.status === "draft" && !compileDrafts()) { + return; + } + + // check and fill-in missing file meta data + fileData = compileOptionsObj.checkContent(fileData); + + var tagClasses = tags.getTagClasses(fileData.tags); + + var metaData = { + title: fileData.title, + body: resolvePaths.resolve(fileData.body, ".."), + url: "../" + fileData.slug + "/", + tagStr: fileData.tags, + tags: (fileData.tags ? tags.getTagsAsLinks("..", fileData.tags) : undefined), + date: fileData.date, + post_class: "post " + (fileData.template === "page.hbs" ? "page " : "") + (fileData.tags ? tagClasses : fileData.slug), + author: (fileData.author ? siteData.authors[fileData.author] : ""), + meta: fileData + }; + + if (fileData.date && fileData.template === "post.hbs") { + posts.push(metaData); + } + + // post class + var bodyClass = "post-template"; + if (fileData.template === "page.hbs") { + bodyClass += " page-template page"; + } + + // tags + if (fileData.tags) { + bodyClass += tagClasses; + } + + var templateData = { + date: moment().format("YYYY-MM-DD"), + resourcePath: "..", + generator: "Gulp " + gulpVersion, + meta_title: fileData.title, + url: "..", + site: siteData, + post: metaData, + body_class: bodyClass, + rss: ".." + siteData.rss + }; - }); + var outDir = rootPath + "/build/" + path.basename(file).replace(/\.[^/.]+$/, ""); - if (templatesToCreate.length) { - var promises = []; - templatesToCreate.forEach(function (templateToCreate) { - _.extend(templateToCreate.templateData.post, { - site: siteData, - allDates: dates.getAllDatesAsLinks("..", posts), - allTags: tags.getAllTagsAsLinks("..", posts) + templatesToCreate.push({ + outDir: outDir, + templateSrc: rootPath + "/src/templates/" + fileData.template, + templateData: templateData }); - promises.push(new Promise(function (resolve, reject) { - gulp.src(templateToCreate.templateSrc) - .pipe(compileHandlebars(templateToCreate.templateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(templateToCreate.outDir)) - .on("error", reject) - .on("end", resolve); - })); }); - Promise.all(promiseList.filter(promises)) - .then(function () { - done(); - }, function (err) { - error(err); + if (templatesToCreate.length) { + var promises = []; + templatesToCreate.forEach(function (templateToCreate) { + _.extend(templateToCreate.templateData.post, { + site: siteData, + allDates: dates.getAllDatesAsLinks("..", posts), + allTags: tags.getAllTagsAsLinks("..", posts) + }); + + promises.push(new Promise(function (resolve, reject) { + gulp.src(templateToCreate.templateSrc) + .pipe(compileHandlebars(templateToCreate.templateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(templateToCreate.outDir)) + .on("error", reject) + .on("end", resolve); + })); }); - } else { - done(); + + Promise.all(promiseList.filter(promises)) + .then(function () { + resolve(); + }, function (err) { + reject(err); + }); + } else { + resolve(); + } } - } + }); }); }; diff --git a/gulp/lib/compile-rss.js b/gulp/lib/compile-rss.js index dc4a6c5..95b77d4 100644 --- a/gulp/lib/compile-rss.js +++ b/gulp/lib/compile-rss.js @@ -1,7 +1,7 @@ "use strict"; var fs = require("fs"), - path = require("path"), + Promise = require("bluebird"), glob = require("glob"), moment = require("moment"), RSS = require("rss"), @@ -9,73 +9,75 @@ var fs = require("fs"), resolvePaths = require("../lib/paths"), compileDrafts = require("../lib/drafts"); -module.exports.run = function (rootPath, done, error) { - var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); - var gulpVersion = require("gulp/package").version; +module.exports = function (rootPath) { + return new Promise(function(resolve, reject) { + var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); + var gulpVersion = require("gulp/package").version; - glob(rootPath + "/build/content/posts/*.json", { - cwd: rootPath - }, function (err, files) { - if (err) { - error(err); - } else { - var posts = []; + glob(rootPath + "/build/content/posts/*.json", { + cwd: "." + }, function (err, files) { + if (err) { + reject(err); + } else { + var posts = []; - files.forEach(function (file) { - var fileData = JSON.parse(fs.readFileSync(file, "utf8")); + files.forEach(function (file) { + var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - if (fileData.status && fileData.status === "draft" && !compileDrafts()) { - return; - } + if (fileData.status && fileData.status === "draft" && !compileDrafts()) { + return; + } - var metaData = { - title: fileData.title, - description: resolvePaths.resolve(fileData.body, siteData.url), - url: siteData.url + "/" + fileData.slug + "/", - tags: (fileData.tags ? (fileData.tags.split ? fileData.tags.split(" ") : fileData.tags) : undefined), // tags can be either string or array - date: fileData.date - }; + var metaData = { + title: fileData.title, + description: resolvePaths.resolve(fileData.body, siteData.url), + url: siteData.url + "/" + fileData.slug + "/", + tags: (fileData.tags ? (fileData.tags.split ? fileData.tags.split(" ") : fileData.tags) : undefined), // tags can be either string or array + date: fileData.date + }; - posts.push(metaData); - }); + posts.push(metaData); + }); - if (posts.length) { + if (posts.length) { - var feed = new RSS({ - title: siteData.title, - description: siteData.description, - generator: "Gulp " + gulpVersion, - site_url: siteData.url, - feed_url: siteData.url + "/rss.xml", - ttl: 60 - }); + var feed = new RSS({ + title: siteData.title, + description: siteData.description, + generator: "Gulp " + gulpVersion, + site_url: siteData.url, + feed_url: siteData.url + "/rss.xml", + ttl: 60 + }); - posts.sort(dates.sortFunc); + posts.sort(dates.sortFunc); - posts.forEach(function (item) { - feed.item({ - title: item.title, - description: item.description, - url: item.url, - guid: item.url, - categories: item.tags, - date: moment(item.date, "YYYY-MM-DD").toDate() + posts.forEach(function (item) { + feed.item({ + title: item.title, + description: item.description, + url: item.url, + guid: item.url, + categories: item.tags, + date: moment(item.date, "YYYY-MM-DD").toDate() + }); }); - }); - var xml = feed.xml(); + var xml = feed.xml(); - fs.writeFile(rootPath + "/build/rss.xml", xml, { - encoding: "utf8" - }, function (err) { - if (err) { - error(err); - } - done(); - }); - } else { - done(); + fs.writeFile(rootPath + "/build/rss.xml", xml, { + encoding: "utf8" + }, function (err) { + if (err) { + reject(err); + } + resolve(); + }); + } else { + resolve(); + } } - } + }); }); }; diff --git a/gulp/lib/compile-tags.js b/gulp/lib/compile-tags.js index 2ae732b..240c6f6 100644 --- a/gulp/lib/compile-tags.js +++ b/gulp/lib/compile-tags.js @@ -5,7 +5,6 @@ var gulp = require("gulp"), compileHandlebars = require("gulp-compile-handlebars"), rename = require("gulp-rename"), fs = require("fs"), - path = require("path"), glob = require("glob"), moment = require("moment"), _ = require("lodash"), @@ -16,162 +15,164 @@ var gulp = require("gulp"), compileDrafts = require("../lib/drafts"), promiseList = require("../lib/promises"); -module.exports.run = function (rootPath, done, error) { - var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); - var gulpVersion = require("gulp/package").version; - var compileOptionsObj = compileOptions(rootPath); - - glob(rootPath + "/build/content/**/*.json", { - cwd: rootPath - }, function (err, files) { - if (err) { - error(err); - } else { - var tagPosts = {}, - posts = [], - allPosts = []; - - files.forEach(function (file) { - var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - - if (fileData.status && fileData.status === "draft" && !compileDrafts()) { - return; - } +module.exports = function (rootPath) { + return new Promise(function(resolve, reject) { + var siteData = JSON.parse(fs.readFileSync(rootPath + "/site.json", "utf8")); + var gulpVersion = require("gulp/package").version; + var compileOptionsObj = compileOptions(rootPath); + + glob(rootPath + "/build/content/**/*.json", { + cwd: "." + }, function (err, files) { + if (err) { + reject(err); + } else { + var tagPosts = {}, + posts = [], + allPosts = []; - if (!fileData.tags || !fileData.date || !fileData.template) { - return; - } + files.forEach(function (file) { + var fileData = JSON.parse(fs.readFileSync(file, "utf8")); - // check and fill-in missing file meta data - fileData = compileOptionsObj.checkContent(fileData); - - var metaData = { - title: fileData.title, - description: resolvePaths.resolve(fileData.body, "../.."), - url: "../../" + fileData.slug + "/", - tagStr: fileData.tags, - tags: (fileData.tags ? tags.getTagsAsLinks("../..", fileData.tags) : undefined), - date: fileData.date, - post_class: "post" + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), - meta: fileData - }; - - if (fileData.date && fileData.template === "post.hbs") { - posts.push(metaData); - } + if (fileData.status && fileData.status === "draft" && !compileDrafts()) { + return; + } - if (fileData.tags) { - var tagList = fileData.tags.split(" "); - tagList.forEach(function (tag) { - if (tagPosts[tag]) { - tagPosts[tag].push(metaData); - } else { - tagPosts[tag] = [metaData]; - } - }); - } - }); - - if (_.size(tagPosts)) { - var promises = []; - posts.sort(dates.sortFunc); - allPosts = _.cloneDeep(posts); - - for (var tag in tagPosts) { - // sort the tag posts - tagPosts[tag].sort(dates.sortFunc); - - var templateData = { - date: moment().format("YYYY-MM-DD"), - resourcePath: "../..", - generator: "Gulp " + gulpVersion, - meta_title: siteData.title, - url: "../..", - site: siteData, - posts: tagPosts[tag], - body_class: "home-template", - rss: "../.." + siteData.rss, - tag: tag, - allDates: dates.getAllDatesAsLinks("../..", allPosts), - allTags: tags.getAllTagsAsLinks("../..", allPosts) + if (!fileData.tags || !fileData.date || !fileData.template) { + return; + } + + // check and fill-in missing file meta data + fileData = compileOptionsObj.checkContent(fileData); + + var metaData = { + title: fileData.title, + description: resolvePaths.resolve(fileData.body, "../.."), + url: "../../" + fileData.slug + "/", + tagStr: fileData.tags, + tags: (fileData.tags ? tags.getTagsAsLinks("../..", fileData.tags) : undefined), + date: fileData.date, + post_class: "post" + (fileData.tags ? tags.getTagClasses(fileData.tags) : fileData.slug), + meta: fileData }; - if (siteData.maxItems && tagPosts[tag].length > siteData.maxItems) { - // how many pages do we need to create? - var totalPages = Math.ceil(tagPosts[tag].length / siteData.maxItems); - - // shorten posts - var paginatedPosts = tagPosts[tag].splice(siteData.maxItems); - - for (var i = 1; i < totalPages; i++) { - var pageNumber = i + 1; - var nextPosts = paginatedPosts.splice(0, siteData.maxItems); - - // update the resource paths - nextPosts.forEach(function (post) { - post.description = resolvePaths.resolve(post.meta.body, "../../../.."); - post.url = "../../../../" + post.meta.slug; - }); - - // create custom template data for this paginated page - var pageTemplateData = _.cloneDeep(templateData); - _.extend(pageTemplateData, { - posts: nextPosts, - resourcePath: "../../../..", - url: "../../../..", - rss: "../../../.." + siteData.rss, - allDates: dates.getAllDatesAsLinks("../../../..", allPosts), - allTags: tags.getAllTagsAsLinks("../../../..", allPosts) - }); - delete pageTemplateData.pages; - - // add pagination data - if (pageNumber === 2) { - pageTemplateData.prevUrl = "../../"; + if (fileData.date && fileData.template === "post.hbs") { + posts.push(metaData); + } + + if (fileData.tags) { + var tagList = fileData.tags.split(" "); + tagList.forEach(function (tag) { + if (tagPosts[tag]) { + tagPosts[tag].push(metaData); } else { - pageTemplateData.prevUrl = "../" + (pageNumber - 1); + tagPosts[tag] = [metaData]; } - - if (pageNumber < totalPages) { - pageTemplateData.nextUrl = "../" + (pageNumber + 1); + }); + } + }); + + if (_.size(tagPosts)) { + var promises = []; + posts.sort(dates.sortFunc); + allPosts = _.cloneDeep(posts); + + for (var tag in tagPosts) { + // sort the tag posts + tagPosts[tag].sort(dates.sortFunc); + + var templateData = { + date: moment().format("YYYY-MM-DD"), + resourcePath: "../..", + generator: "Gulp " + gulpVersion, + meta_title: siteData.title, + url: "../..", + site: siteData, + posts: tagPosts[tag], + body_class: "home-template", + rss: "../.." + siteData.rss, + tag: tag, + allDates: dates.getAllDatesAsLinks("../..", allPosts), + allTags: tags.getAllTagsAsLinks("../..", allPosts) + }; + + if (siteData.maxItems && tagPosts[tag].length > siteData.maxItems) { + // how many pages do we need to create? + var totalPages = Math.ceil(tagPosts[tag].length / siteData.maxItems); + + // shorten posts + var paginatedPosts = tagPosts[tag].splice(siteData.maxItems); + + for (var i = 1; i < totalPages; i++) { + var pageNumber = i + 1; + var nextPosts = paginatedPosts.splice(0, siteData.maxItems); + + // update the resource paths + nextPosts.forEach(function (post) { + post.description = resolvePaths.resolve(post.meta.body, "../../../.."); + post.url = "../../../../" + post.meta.slug; + }); + + // create custom template data for this paginated page + var pageTemplateData = _.cloneDeep(templateData); + _.extend(pageTemplateData, { + posts: nextPosts, + resourcePath: "../../../..", + url: "../../../..", + rss: "../../../.." + siteData.rss, + allDates: dates.getAllDatesAsLinks("../../../..", allPosts), + allTags: tags.getAllTagsAsLinks("../../../..", allPosts) + }); + delete pageTemplateData.pages; + + // add pagination data + if (pageNumber === 2) { + pageTemplateData.prevUrl = "../../"; + } else { + pageTemplateData.prevUrl = "../" + (pageNumber - 1); + } + + if (pageNumber < totalPages) { + pageTemplateData.nextUrl = "../" + (pageNumber + 1); + } + + pageTemplateData.totalPages = totalPages; + + promises.push(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build/tag/" + tag + "/page/" + pageNumber)) + .on("error", reject) + .on("end", resolve); + })); } - pageTemplateData.totalPages = totalPages; - - promises.push(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(pageTemplateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build/tag/" + tag + "/page/" + pageNumber)) - .on("error", reject) - .on("end", resolve); - })); + // update template + templateData.nextUrl = "../../tag/" + tag + "/page/2"; + templateData.totalPages = totalPages; } - // update template - templateData.nextUrl = "../../tag/" + tag + "/page/2"; - templateData.totalPages = totalPages; + promises.push(new Promise(function (resolve, reject) { + gulp.src(rootPath + "/src/templates/index.hbs") + .pipe(compileHandlebars(templateData, compileOptionsObj)) + .pipe(rename("index.html")) + .pipe(gulp.dest(rootPath + "/build/tag/" + tag)) + .on("error", reject) + .on("end", resolve); + })); } - promises.push(new Promise(function (resolve, reject) { - gulp.src(rootPath + "/src/templates/index.hbs") - .pipe(compileHandlebars(templateData, compileOptionsObj)) - .pipe(rename("index.html")) - .pipe(gulp.dest(rootPath + "/build/tag/" + tag)) - .on("error", reject) - .on("end", resolve); - })); + Promise.all(promiseList.filter(promises)) + .then(function () { + resolve(); + }, function (err) { + reject(err); + }); + } else { + resolve(); } - - Promise.all(promiseList.filter(promises)) - .then(function () { - done(); - }, function (err) { - error(err); - }); - } else { - done(); } - } + }); }); }; diff --git a/gulp/lib/dates.js b/gulp/lib/dates.js index 069aee6..357f2e5 100644 --- a/gulp/lib/dates.js +++ b/gulp/lib/dates.js @@ -11,8 +11,7 @@ module.exports = { }, getAllDatesAsLinks: function (path, posts) { var allDates = {}, - allDatesArray = [], - self = this; + allDatesArray = []; posts.forEach(function (post) { var dateMonth = post.date.substr(0, 7); //2014-12 if (!allDates[dateMonth]) { diff --git a/gulp/lib/downzero.js b/gulp/lib/downzero.js index 783a6d8..3fa5420 100644 --- a/gulp/lib/downzero.js +++ b/gulp/lib/downzero.js @@ -1,27 +1,34 @@ "use strict"; -// Functions to imitate the behavior of Downsize@0.0.5 with 'words: "0"' (heavily based on Downsize) +// Functions to imitate the behavior of Downsize@0.0.5 with "words: "0"" (heavily based on Downsize) // This is used to extract the first image from the post content which is used as a header var stack, tagName, tagBuffer, truncatedText, parseState, pointer, - states = {unitialized: 0, tag_commenced: 1, tag_string: -1, tag_string_single: -2, comment: -3}, - voidElements = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', - 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']; + states = { + unitialized: 0, + tag_commenced: 1, + tag_string: -1, + tag_string_single: -2, + comment: -3 + }, + voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", + "keygen", "link", "meta", "param", "source", "track", "wbr" + ]; function getTagName(tag) { - var tagName = (tag || '').match(/<\/*([a-z0-9\:\-\_]+)/i); + var tagName = (tag || "").match(/<\/*([a-z0-9\:\-\_]+)/i); return tagName ? tagName[1] : null; } function closeTag(openingTag) { - var tagName = (getTagName(openingTag)) ? '' : ''; + var tagName = (getTagName(openingTag)) ? "" : ""; return tagName; } function downzero(text) { stack = []; - tagName = ''; - tagBuffer = ''; - truncatedText = ''; + tagName = ""; + tagBuffer = ""; + truncatedText = ""; parseState = 0; pointer = 0; @@ -31,20 +38,20 @@ function downzero(text) { } switch (text[pointer]) { - case '<': + case "<": if (parseState === states.unitialized && text[pointer + 1].match(/[a-z0-9\-\_\/\!]/)) { parseState = states.tag_commenced; tagBuffer += text[pointer]; } break; - case '!': - if (parseState === states.tag_commenced && text[pointer - 1] === '<') { + case "!": + if (parseState === states.tag_commenced && text[pointer - 1] === "<") { parseState = states.comment; } break; - case '\"': + case "\"": if (parseState === states.tag_string) { parseState = states.tag_commenced; } else if (parseState === states.tag_string_single) { @@ -55,7 +62,7 @@ function downzero(text) { } break; - case '\'': + case "'": if (parseState === states.tag_string_single) { parseState = states.tag_commenced; } else if (parseState === states.tag_string) { @@ -65,7 +72,7 @@ function downzero(text) { } break; - case '>': + case ">": if (parseState === states.tag_commenced) { parseState = states.unitialized; truncatedText += tagBuffer; @@ -76,21 +83,21 @@ function downzero(text) { } else if (voidElements.indexOf(tagName) < 0 && !tagBuffer.match(/\/\s*>$/)) { stack.push(tagBuffer); } - tagBuffer = ''; + tagBuffer = ""; continue; } - if (parseState === states.comment && text.substring(pointer - 2, pointer) === '--') { + if (parseState === states.comment && text.substring(pointer - 2, pointer) === "--") { parseState = states.unitialized; truncatedText += tagBuffer; - tagBuffer = ''; + tagBuffer = ""; continue; } break; - case '-': + case "-": break; } @@ -108,4 +115,4 @@ function downzero(text) { return truncatedText; } -module.exports = downzero; +module.exports = downzero; \ No newline at end of file diff --git a/gulp/lib/drafts.js b/gulp/lib/drafts.js index aba0a1a..74fc223 100644 --- a/gulp/lib/drafts.js +++ b/gulp/lib/drafts.js @@ -1,4 +1,3 @@ -/* global process */ "use strict"; var minimist = require("minimist"); diff --git a/gulp/lib/paths.js b/gulp/lib/paths.js index 161dd3a..8a65276 100644 --- a/gulp/lib/paths.js +++ b/gulp/lib/paths.js @@ -1,13 +1,19 @@ "use strict"; module.exports = { + /** + * Method to update all image and hyperlink URLs to paths relative to the site root + * @param {String} html The HTML containing images and hyperlinks + * @param {String} path The path to the site root + * @returns {String} The HTML with images and hyperlinks updated + */ resolve: function (html, path) { // images html = html.replace(//gim, function (match, p1, p2, p3, offset, s) { var imagePath = p2; if (/^\//.test(imagePath)) { - imagePath = path + p2; + imagePath = path + (path === "" ? p2.substring(1) : p2); } return ""; }); @@ -16,7 +22,7 @@ module.exports = { html = html.replace(//gim, function (match, p1, p2, p3, offset, s) { var linkPath = p2; if (/^\//.test(linkPath)) { - linkPath = path + p2; + linkPath = path + (path === "" ? p2.substring(1) : p2); } return ""; }); diff --git a/gulp/lib/tags.js b/gulp/lib/tags.js index 9c74db5..39ac1b5 100644 --- a/gulp/lib/tags.js +++ b/gulp/lib/tags.js @@ -42,7 +42,7 @@ module.exports = { return "" + tag + ""; }, getAllTagsAsLinks: function (path, posts) { - var allTags = {}, allTagsArray = [], self = this; + var allTags = {}, allTagsArray = []; posts.forEach(function (post) { if (post.tagStr) { var tagList = tagObjToArray(post.tagStr); diff --git a/gulp/tasks/compile.js b/gulp/tasks/compile.js index 1dea437..9213292 100644 --- a/gulp/tasks/compile.js +++ b/gulp/tasks/compile.js @@ -10,32 +10,23 @@ var gulp = require("gulp"), removeDir = require("../lib/remove-dir"); gulp.task("compile", ["content"], function (done) { + var rootPath = "."; var compilePromises = []; // pages - compilePromises.push(new Promise(function (resolve, reject) { - compilePages.run(".", resolve, reject); - })); + compilePromises.push(compilePages(rootPath)); // tags - compilePromises.push(new Promise(function (resolve, reject) { - compileTags.run(".", resolve, reject); - })); + compilePromises.push(compileTags(rootPath)); // dates - compilePromises.push(new Promise(function (resolve, reject) { - compileDates.run(".", resolve, reject); - })); + compilePromises.push(compileDates(rootPath)); // rss feed compilation - compilePromises.push(new Promise(function (resolve, reject) { - compileRss.run(".", resolve, reject); - })); + compilePromises.push(compileRss(rootPath)); // index page generation - compilePromises.push(new Promise(function (resolve, reject) { - compileHome.run(".", resolve, reject); - })); + compilePromises.push(compileHome(rootPath)); Promise.all(compilePromises) .then(function () { diff --git a/gulp/tasks/content.js b/gulp/tasks/content.js index acf3584..ce0f126 100644 --- a/gulp/tasks/content.js +++ b/gulp/tasks/content.js @@ -1,12 +1,13 @@ "use strict"; var gulp = require("gulp"), - markdown = require("gulp-markdown-to-json"), + markdownToJson = require("gulp-markdown-to-json"), + marked = require("marked"), replace = require("gulp-replace"); gulp.task("content", ["copy-assets"], function () { return gulp.src("./src/content/**/*.md") .pipe(replace(/(^(?!---\n).)/, "---\n$1")) - .pipe(markdown()) + .pipe(markdownToJson(marked)) .pipe(gulp.dest("./build/content")); }); diff --git a/gulp/tests/compile-dates.spec.js b/gulp/tests/compile-dates.spec.js index a48c664..ea6a9a0 100644 --- a/gulp/tests/compile-dates.spec.js +++ b/gulp/tests/compile-dates.spec.js @@ -1,18 +1,15 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ -'use strict'; - -var compileDates = require('../lib/compile-dates'), - removeDir = require('../lib/remove-dir'), - expect = require('chai').expect, - mockery = require('mockery'), - Promise = require('bluebird'), - sinon = require('sinon'), - fs = require('fs'); - -describe('When compiling date pages', function () { - var rootPath = '/tmp/compile-dates'; +"use strict"; + +var compileDates = require("../lib/compile-dates"), + removeDir = require("../lib/remove-dir"), + expect = require("chai").expect, + mockery = require("mockery"), + Promise = require("bluebird"), + sinon = require("sinon"), + fs = require("fs"); + +describe("When compiling date pages", function () { + var rootPath = ".tmp/compile-dates"; var doneStub, errorStub; before(function () { @@ -20,21 +17,26 @@ describe('When compiling date pages', function () { errorStub = sinon.stub(); // create the root path - if (!fs.existsSync(rootPath)) { - fs.mkdirSync(rootPath); - } + [ + ".tmp", + ".tmp/compile-dates" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); // set-up folders: [ - '/src', - '/src/templates', - '/src/templates/partials', - '/build', - '/build/date', - '/build/date/page', - '/build/content', - '/build/content/pages', - '/build/content/posts' + "/src", + "/src/templates", + "/src/templates/partials", + "/build", + "/build/date", + "/build/date/page", + "/build/content", + "/build/content/pages", + "/build/content/posts" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); @@ -42,51 +44,51 @@ describe('When compiling date pages', function () { }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/loop.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/pagination.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/index.hbs', '
Posts dated: {{dateStr}}{{> loop}}{{> pagination}}
', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}"); + fs.writeFileSync(rootPath + "/src/templates/partials/loop.hbs", ""); + fs.writeFileSync(rootPath + "/src/templates/partials/pagination.hbs", ""); + fs.writeFileSync(rootPath + "/src/templates/index.hbs", "
Posts dated: {{dateStr}}{{> loop}}{{> pagination}}
"); }); after(function () { removeDir(rootPath); }); - describe('When compiling date pages', function () { + describe("When compiling date pages", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-06-11","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","tags":"mocha coke","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - compileDates.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-06-11\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"tags\":\"mocha coke\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + compileDates(rootPath).then(done, errorStub); }); - it('Should create the June 2014 date page', function () { - expect(fs.existsSync(rootPath + '/build/date/2014-06/index.html')).to.be.true; + it("Should create the June 2014 date page", function () { + expect(fs.existsSync(rootPath + "/build/date/2014-06/index.html")).to.be.true; }); - it('Should create the December 2014 date page', function () { - expect(fs.existsSync(rootPath + '/build/date/2014-12/index.html')).to.be.true; + it("Should create the December 2014 date page", function () { + expect(fs.existsSync(rootPath + "/build/date/2014-12/index.html")).to.be.true; }); - it('Should have the correct date page content for June 2014', function () { - var expectedHtml = '
' + - 'Posts dated: June 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-06/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct date page content for June 2014", function () { + var expectedHtml = "
" + + "Posts dated: June 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-06/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should have the correct date page content for December 2014', function () { - var expectedHtml = '
' + - 'Posts dated: December 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-12/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct date page content for December 2014", function () { + var expectedHtml = "
" + + "Posts dated: December 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-12/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When an error occurs with the promises', function () { + describe("When an error occurs with the promises", function () { var promisesListStub, newCompileDates; beforeEach(function (done) { @@ -102,15 +104,15 @@ describe('When compiling date pages', function () { promisesListStub = { filter: function () { - return [Promise.reject('An error occurred')]; + return [Promise.reject("An error occurred")]; } }; - mockery.registerMock('../lib/promises', promisesListStub); + mockery.registerMock("../lib/promises", promisesListStub); - newCompileDates = require('../lib/compile-dates'); + newCompileDates = require("../lib/compile-dates"); - newCompileDates.run(rootPath, function () { + newCompileDates(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -119,88 +121,88 @@ describe('When compiling date pages', function () { }); - it('Should call the error function', function () { + it("Should call the error function", function () { expect(errorStub.called).to.be.true; }); afterEach(function () { - mockery.deregisterMock('../lib/promises'); + mockery.deregisterMock("../lib/promises"); mockery.disable(); }); }); - describe('When compiling date pages and excluding draft templates', function () { + describe("When compiling date pages and excluding draft templates", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-06-11","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","status":"draft","tags":"mocha coke","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - compileDates.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-06-11\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"status\":\"draft\",\"tags\":\"mocha coke\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + compileDates(rootPath).then(done, errorStub); }); - it('Should have the correct date page content for June 2014', function () { - var expectedHtml = '
' + - 'Posts dated: June 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-06/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct date page content for June 2014", function () { + var expectedHtml = "
" + + "Posts dated: June 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-06/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When compiling date posts with pagination', function () { + describe("When compiling date posts with pagination", function () { before(function (done) { - fs.writeFileSync(rootPath + '/site.json', '{ "title": "Test site", "maxItems": "2" }', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post3.json', '{"slug":"test-post3","title":"Test post 3","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post4.json', '{"slug":"test-post4","title":"Test post 4","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post5.json', '{"slug":"test-post5","title":"Test post 5","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post6.json', '{"slug":"test-post6","title":"Test post 6","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post7.json', '{"slug":"test-post7","title":"Test post 7","tags":"mocha","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - compileDates.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/site.json", "{ \"title\": \"Test site\", \"maxItems\": \"2\" }"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post3.json", "{\"slug\":\"test-post3\",\"title\":\"Test post 3\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post4.json", "{\"slug\":\"test-post4\",\"title\":\"Test post 4\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post5.json", "{\"slug\":\"test-post5\",\"title\":\"Test post 5\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post6.json", "{\"slug\":\"test-post6\",\"title\":\"Test post 6\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + fs.writeFileSync(rootPath + "/build/content/posts/test-post7.json", "{\"slug\":\"test-post7\",\"title\":\"Test post 7\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}"); + compileDates(rootPath).then(done, errorStub); }); - it('Should have the correct date page content for December 2014', function () { - var expectedHtml = '
' + - 'Posts dated: December 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-12/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct date page content for December 2014", function () { + var expectedHtml = "
" + + "Posts dated: December 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-12/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should create the second paginated date page for December 2014', function () { - expect(fs.existsSync(rootPath + '/build/date/2014-12/page/2/index.html')).to.be.true; + it("Should create the second paginated date page for December 2014", function () { + expect(fs.existsSync(rootPath + "/build/date/2014-12/page/2/index.html")).to.be.true; }); - it('Should create the third paginated date page for December 2014', function () { - expect(fs.existsSync(rootPath + '/build/date/2014-12/page/3/index.html')).to.be.true; + it("Should create the third paginated date page for December 2014", function () { + expect(fs.existsSync(rootPath + "/build/date/2014-12/page/3/index.html")).to.be.true; }); - it('Should have the correct content for the second paginated page', function () { - var expectedHtml = '
' + - 'Posts dated: December 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-12/page/2/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct content for the second paginated page", function () { + var expectedHtml = "
" + + "Posts dated: December 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-12/page/2/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should have the correct content for the third paginated page', function () { - var expectedHtml = '
' + - 'Posts dated: December 2014' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/date/2014-12/page/3/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct content for the third paginated page", function () { + var expectedHtml = "
" + + "Posts dated: December 2014" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/date/2014-12/page/3/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When there are no posts for the date pages', function () { + describe("When there are no posts for the date pages", function () { beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - compileDates.run(rootPath, function () { + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}"); + compileDates(rootPath).then(function () { doneStub(); done(); }, function () { @@ -209,18 +211,18 @@ describe('When compiling date pages', function () { }); }); - it('Should call done', function () { + it("Should call done", function () { expect(doneStub.called).to.be.true; }); }); - describe('When a glob error occurs', function () { + describe("When a glob error occurs", function () { var globStub, newCompileDates; beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}"); mockery.enable({ warnOnReplace: false, @@ -232,15 +234,15 @@ describe('When compiling date pages', function () { globStub = function (paths, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); }; - mockery.registerMock('glob', globStub); + mockery.registerMock("glob", globStub); - newCompileDates = require('../lib/compile-dates'); + newCompileDates = require("../lib/compile-dates"); - newCompileDates.run(rootPath, function () { + newCompileDates(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -248,16 +250,16 @@ describe('When compiling date pages', function () { }); }); - it('Should throw a glob error', function () { + it("Should throw a glob error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { - expect(errorStub.calledWith({ message: 'I threw an error' })).to.be.true; + it("Should throw a specific error", function () { + expect(errorStub.calledWith({ message: "I threw an error" })).to.be.true; }); afterEach(function () { - mockery.deregisterMock('glob'); + mockery.deregisterMock("glob"); mockery.disable(); }); }); diff --git a/gulp/tests/compile-home.spec.js b/gulp/tests/compile-home.spec.js index ce2f2e0..8766994 100644 --- a/gulp/tests/compile-home.spec.js +++ b/gulp/tests/compile-home.spec.js @@ -1,18 +1,15 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ -'use strict'; - -var compileHome = require('../lib/compile-home'), - removeDir = require('../lib/remove-dir'), - expect = require('chai').expect, - mockery = require('mockery'), - sinon = require('sinon'), - Promise = require('bluebird'), - fs = require('fs'); - -describe('Given the home page', function () { - var rootPath = '/tmp/compile-home'; +"use strict"; + +var compileHome = require("../lib/compile-home"), + removeDir = require("../lib/remove-dir"), + expect = require("chai").expect, + mockery = require("mockery"), + sinon = require("sinon"), + Promise = require("bluebird"), + fs = require("fs"); + +describe("Given the home page", function () { + var rootPath = ".tmp/compile-home"; var doneStub, errorStub; before(function () { @@ -20,20 +17,25 @@ describe('Given the home page', function () { errorStub = sinon.stub(); // create the root path - if (!fs.existsSync(rootPath)) { - fs.mkdirSync(rootPath); - } + [ + ".tmp", + ".tmp/compile-home" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); // set-up folders: [ - '/src', - '/src/templates', - '/src/templates/partials', - '/build', - '/build/page', - '/build/content', - '/build/content/pages', - '/build/content/posts' + "/src", + "/src/templates", + "/src/templates/partials", + "/build", + "/build/page", + "/build/content", + "/build/content/pages", + "/build/content/posts" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); @@ -41,40 +43,44 @@ describe('Given the home page', function () { }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/loop.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/pagination.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/index.hbs', '
{{> loop}}{{> pagination}}
', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/partials/loop.hbs", "", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/partials/pagination.hbs", "", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/index.hbs", "
{{> loop}}{{> pagination}}
", { encoding: "utf8" }); }); - describe('When compiling the home page', function () { + after(function () { + removeDir(rootPath); + }); + + describe("When compiling the home page", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/pages/test-page.json', '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

Test page content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post.json', '{"slug":"test-post","title":"Test post","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - compileHome.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/pages/test-page.json", "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

Test page content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post.json", "{\"slug\":\"test-post\",\"title\":\"Test post\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + compileHome(rootPath).then(done, errorStub); }); - it('Should create the static home page', function () { - expect(fs.existsSync(rootPath + '/build/index.html')).to.be.true; + it("Should create the static home page", function () { + expect(fs.existsSync(rootPath + "/build/index.html")).to.be.true; }); - it('Should have the correct home page content', function () { - var expectedHtml = '
' + - '' + - '' + - '
'; - expect(fs.readFileSync(rootPath + '/build/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct home page content", function () { + var expectedHtml = "
" + + "" + + "" + + "
"; + expect(fs.readFileSync(rootPath + "/build/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When an error occurs with the promises', function () { + describe("When an error occurs with the promises", function () { var promisesListStub, newCompileHome; beforeEach(function (done) { @@ -88,15 +94,15 @@ describe('Given the home page', function () { promisesListStub = { filter: function () { - return [Promise.reject('An error occurred')]; + return [Promise.reject("An error occurred")]; } }; - mockery.registerMock('../lib/promises', promisesListStub); + mockery.registerMock("../lib/promises", promisesListStub); - newCompileHome = require('../lib/compile-home'); + newCompileHome = require("../lib/compile-home"); - newCompileHome.run(rootPath, function () { + newCompileHome(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -105,111 +111,111 @@ describe('Given the home page', function () { }); - it('Should call the error function', function () { + it("Should call the error function", function () { expect(errorStub.called).to.be.true; }); afterEach(function () { - mockery.deregisterMock('../lib/promises'); + mockery.deregisterMock("../lib/promises"); mockery.disable(); }); }); - describe('When compiling the home page excluding draft templates', function () { + describe("When compiling the home page excluding draft templates", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/pages/test-page.json', '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

Test page content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post.json', '{"slug":"test-post","title":"Test post","template":"post.hbs","status":"draft","body":"

Test post content

"}', { encoding: 'utf8' }); - compileHome.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/pages/test-page.json", "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

Test page content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post.json", "{\"slug\":\"test-post\",\"title\":\"Test post\",\"template\":\"post.hbs\",\"status\":\"draft\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + compileHome(rootPath).then(done, errorStub); }); - it('Should have the correct home page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct home page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When compiling the home page with pagination', function () { + describe("When compiling the home page with pagination", function () { before(function (done) { - fs.writeFileSync(rootPath + '/site.json', '{ "title": "Test site", "maxItems": "2" }', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/pages/test-page.json', '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

Test page content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post3.json', '{"slug":"test-post3","title":"Test post 3","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post4.json', '{"slug":"test-post4","title":"Test post 4","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post5.json', '{"slug":"test-post5","title":"Test post 5","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post6.json', '{"slug":"test-post6","title":"Test post 6","date":"2015-02-20","template":"post.hbs","body":"

Test post content

"}', { encoding: 'utf8' }); - compileHome.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/site.json", "{ \"title\": \"Test site\", \"maxItems\": \"2\" }", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/pages/test-page.json", "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

Test page content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post3.json", "{\"slug\":\"test-post3\",\"title\":\"Test post 3\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post4.json", "{\"slug\":\"test-post4\",\"title\":\"Test post 4\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post5.json", "{\"slug\":\"test-post5\",\"title\":\"Test post 5\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post6.json", "{\"slug\":\"test-post6\",\"title\":\"Test post 6\",\"date\":\"2015-02-20\",\"template\":\"post.hbs\",\"body\":\"

Test post content

\"}", { encoding: "utf8" }); + compileHome(rootPath).then(done, errorStub); }); - it('Should have the correct home page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct home page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should create the second paginated home page', function () { - expect(fs.existsSync(rootPath + '/build/page/2/index.html')).to.be.true; + it("Should create the second paginated home page", function () { + expect(fs.existsSync(rootPath + "/build/page/2/index.html")).to.be.true; }); - it('Should create the third paginated home page', function () { - expect(fs.existsSync(rootPath + '/build/page/3/index.html')).to.be.true; + it("Should create the third paginated home page", function () { + expect(fs.existsSync(rootPath + "/build/page/3/index.html")).to.be.true; }); - it('Should have the correct home page content for the second paginated page', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/page/2/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct home page content for the second paginated page", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/page/2/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should have the correct home page content for the third paginated page', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/page/3/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct home page content for the third paginated page", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/page/3/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When compiling the home page content with no front matter', function () { + describe("When compiling the home page content with no front matter", function () { before(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{ "title": "Test site" }', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{ \"title\": \"Test site\" }", { encoding: "utf8" }); [ - '/src', - '/src/templates', - '/src/templates/partials', - '/build', - '/build/content' + "/src", + "/src/templates", + "/src/templates/partials", + "/build", + "/build/content" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); } }); - fs.writeFileSync(rootPath + '/src/templates/partials/loop.hbs', '{{#each pages}}
  • {{title}}
  • {{/each}}{{#each posts}}
  • {{title}}
  • {{/each}}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/index.hbs', '
      {{> loop}}
    ', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/test-page.json', '{"body":"

    Test page content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/test-post1.json', '{"template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileHome.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/src/templates/partials/loop.hbs", "{{#each pages}}
  • {{title}}
  • {{/each}}{{#each posts}}
  • {{title}}
  • {{/each}}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/index.hbs", "
      {{> loop}}
    ", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/test-page.json", "{\"body\":\"

    Test page content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/test-post1.json", "{\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileHome(rootPath).then(done, errorStub); }); - it('Should have the correct home page content', function () { - expect(fs.readFileSync(rootPath + '/build/index.html', 'utf8')).to.equal(''); + it("Should have the correct home page content", function () { + expect(fs.readFileSync(rootPath + "/build/index.html", "utf8")).to.equal(""); }); }); - describe('When there are no posts or pages for the home page', function () { + describe("When there are no posts or pages for the home page", function () { beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - compileHome.run(rootPath, function () { + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); + compileHome(rootPath).then(function () { doneStub(); done(); }, function () { @@ -218,18 +224,18 @@ describe('Given the home page', function () { }); }); - it('Should call done', function () { + it("Should call done", function () { expect(doneStub.called).to.be.true; }); }); - describe('When a glob error occurs', function () { + describe("When a glob error occurs", function () { var globStub, newCompileHome; beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); mockery.enable({ warnOnReplace: false, @@ -241,15 +247,15 @@ describe('Given the home page', function () { globStub = function (paths, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); }; - mockery.registerMock('glob', globStub); + mockery.registerMock("glob", globStub); - newCompileHome = require('../lib/compile-home'); + newCompileHome = require("../lib/compile-home"); - newCompileHome.run(rootPath, function () { + newCompileHome(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -257,21 +263,17 @@ describe('Given the home page', function () { }); }); - it('Should throw a glob error', function () { + it("Should throw a glob error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { - expect(errorStub.calledWith({ message: 'I threw an error' })).to.be.true; + it("Should throw a specific error", function () { + expect(errorStub.calledWith({ message: "I threw an error" })).to.be.true; }); afterEach(function () { - mockery.deregisterMock('glob'); + mockery.deregisterMock("glob"); mockery.disable(); }); }); - - after(function () { - removeDir(rootPath); - }); }); diff --git a/gulp/tests/compile-options.spec.js b/gulp/tests/compile-options.spec.js index 4e7c3c3..3b9db61 100644 --- a/gulp/tests/compile-options.spec.js +++ b/gulp/tests/compile-options.spec.js @@ -1,207 +1,205 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W079 */ -'use strict'; +"use strict"; -var compileOptions = require('../lib/compile-options'), - Handlebars = require('handlebars'), - expect = require('chai').expect; +var compileOptions = require("../lib/compile-options"), + Handlebars = require("handlebars"), + expect = require("chai").expect; -describe('Given the compile options', function () { - describe('When using the date helper', function () { +describe("Given the compile options", function () { + describe("When using the date helper", function () { beforeEach(function () { - Handlebars.registerHelper('date', compileOptions('.').helpers.date); - this.html = "{{date format='MMM Do, YYYY'}}"; + Handlebars.registerHelper("date", compileOptions(".").helpers.date); + this.html = "{{date format=\"MMM Do, YYYY\"}}"; }); - it('Should format the date as MMM Do, YYYY', function () { + it("Should format the date as MMM Do, YYYY", function () { var template = Handlebars.compile(this.html); var result = template({ - date: '2015-10-15' + date: "2015-10-15" }); - expect(result).to.equal('Oct 15th, 2015'); + expect(result).to.equal("Oct 15th, 2015"); }); }); - describe('When using the excerpt helper', function () { - describe('When using the excerpt helper with characters', function () { + describe("When using the excerpt helper", function () { + describe("When using the excerpt helper with characters", function () { beforeEach(function () { - Handlebars.registerHelper('excerpt', compileOptions('.').helpers.excerpt); + Handlebars.registerHelper("excerpt", compileOptions(".").helpers.excerpt); this.html = "

    {{{excerpt characters=100}}}...

    "; }); - it('Should return an excerpt of the given text', function () { + it("Should return an excerpt of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: 'Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.' + description: "Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut." }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake po...

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake po...

    "); }); }); - describe('When using the excerpt helper with words', function () { + describe("When using the excerpt helper with words", function () { beforeEach(function () { - Handlebars.registerHelper('excerpt', compileOptions('.').helpers.excerpt); + Handlebars.registerHelper("excerpt", compileOptions(".").helpers.excerpt); this.html = "

    {{{excerpt words=20}}}...

    "; }); - it('Should return an excerpt of the given text', function () { + it("Should return an excerpt of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: 'Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.' + description: "Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut." }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw...

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw...

    "); }); }); - describe('When using the excerpt helper without words or characters', function () { + describe("When using the excerpt helper without words or characters", function () { beforeEach(function () { - Handlebars.registerHelper('excerpt', compileOptions('.').helpers.excerpt); + Handlebars.registerHelper("excerpt", compileOptions(".").helpers.excerpt); this.html = "

    {{{excerpt}}}...

    "; }); - it('Should return an excerpt of the given text', function () { + it("Should return an excerpt of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: 'Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.' + description: "Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut." }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut....

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut....

    "); }); }); }); - describe('When using the content helper', function () { - describe('When using the content helper with characters', function () { + describe("When using the content helper", function () { + describe("When using the content helper with characters", function () { beforeEach(function () { - Handlebars.registerHelper('content', compileOptions('.').helpers.content); + Handlebars.registerHelper("content", compileOptions(".").helpers.content); this.html = "{{{content characters=100}}}"; }); - it('Should return an content of the given text', function () { + it("Should return an content of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: '

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    ' + description: "

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    " }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake po

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake po

    "); }); }); - describe('When using the content helper with words', function () { + describe("When using the content helper with words", function () { beforeEach(function () { - Handlebars.registerHelper('content', compileOptions('.').helpers.content); + Handlebars.registerHelper("content", compileOptions(".").helpers.content); this.html = "{{{content words=20}}}"; }); - it('Should return an content of the given text', function () { + it("Should return an content of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: '

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    ' + description: "

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    " }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw

    "); }); }); - describe('When using the content helper without words or characters', function () { + describe("When using the content helper without words or characters", function () { beforeEach(function () { - Handlebars.registerHelper('content', compileOptions('.').helpers.content); + Handlebars.registerHelper("content", compileOptions(".").helpers.content); this.html = "{{{content}}}"; }); - it('Should return an content of the given text', function () { + it("Should return an content of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: '

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    ' + description: "

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    " }); - expect(result).to.equal('

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    '); + expect(result).to.equal("

    Gingerbread marshmallow fruitcake topping jelly-o halvah. Dragée icing cheesecake. Apple pie cake powder biscuit gingerbread tart gingerbread bonbon. Bear claw danish cake pie gummi bears macaroon tart jujubes toffee Candy canes brownie oat cake gummi bears cupcake powder donut.

    "); }); }); - describe('When using the content helper with no words', function () { + describe("When using the content helper with no words", function () { beforeEach(function () { - Handlebars.registerHelper('content', compileOptions('.').helpers.content); + Handlebars.registerHelper("content", compileOptions(".").helpers.content); this.html = "{{{content words=0}}}"; }); - it('Should return an content of the given text', function () { + it("Should return an content of the given text", function () { var template = Handlebars.compile(this.html); var result = template({ - description: '

    Image

    ' + description: "

    \"\"Image

    " }); - expect(result).to.equal('

    '); + expect(result).to.equal("

    \"\"

    "); }); }); }); - describe('When using the resolve helper', function () { + describe("When using the resolve helper", function () { beforeEach(function () { - Handlebars.registerHelper('resolve', compileOptions('.').helpers.resolve); - this.html = ''; + Handlebars.registerHelper("resolve", compileOptions(".").helpers.resolve); + this.html = ""; }); - it('Should return a resolved path', function () { + it("Should return a resolved path", function () { var template = Handlebars.compile(this.html); var result = template({ - resourcePath: '..' + resourcePath: ".." }); - expect(result).to.equal(''); + expect(result).to.equal(""); }); - it('Should return a resolved path if no resourcePath is set', function () { + it("Should return a resolved path if no resourcePath is set", function () { var template = Handlebars.compile(this.html); var result = template({}); - expect(result).to.equal(''); + expect(result).to.equal(""); }); }); - describe('When using the checkContent function', function () { - it('Should check the content and add missing page meta data', function () { + describe("When using the checkContent function", function () { + it("Should check the content and add missing page meta data", function () { var fileData = { body: "

    Test page content.

    Blah blah blah

    " }; fileData = compileOptions().checkContent(fileData); expect(fileData).to.deep.equal({ - slug: 'test-page-content-blah-blah-blah', - template: 'page.hbs', - title: 'Test page content. Blah blah blah', - body: '

    Test page content.

    Blah blah blah

    ' + slug: "test-page-content-blah-blah-blah", + template: "page.hbs", + title: "Test page content. Blah blah blah", + body: "

    Test page content.

    Blah blah blah

    " }); }); - it('Should check the content and add missing post meta data', function () { + it("Should check the content and add missing post meta data", function () { var fileData = { - date: '2015-02-23', + date: "2015-02-23", body: "

    Test post content.

    Blah blah blah

    " }; fileData = compileOptions().checkContent(fileData); expect(fileData).to.deep.equal({ - slug: 'test-post-content-blah-blah-blah', - template: 'post.hbs', - title: 'Test post content. Blah blah blah', - date: '2015-02-23', - body: '

    Test post content.

    Blah blah blah

    ' + slug: "test-post-content-blah-blah-blah", + template: "post.hbs", + title: "Test post content. Blah blah blah", + date: "2015-02-23", + body: "

    Test post content.

    Blah blah blah

    " }); }); }); - describe('When using the or helper', function () { + describe("When using the or helper", function () { beforeEach(function () { - Handlebars.registerHelper('or', compileOptions('.').helpers.or); + Handlebars.registerHelper("or", compileOptions(".").helpers.or); this.html = "
    {{#if (or val1 val2)}}Values matched{{else}}Values not matched{{/if}}
    "; }); - it('Should output the correct html when the values exist', function () { + it("Should output the correct html when the values exist", function () { var template = Handlebars.compile(this.html); var result = template({ - val1: 'Test' + val1: "Test" }); - expect(result).to.equal('
    Values matched
    '); + expect(result).to.equal("
    Values matched
    "); }); - it('Should output the correct html when the values do not exist', function () { + it("Should output the correct html when the values do not exist", function () { var template = Handlebars.compile(this.html); var result = template({}); - expect(result).to.equal('
    Values not matched
    '); + expect(result).to.equal("
    Values not matched
    "); }); }); }); diff --git a/gulp/tests/compile-pages.spec.js b/gulp/tests/compile-pages.spec.js index 9dc85e8..62022cd 100644 --- a/gulp/tests/compile-pages.spec.js +++ b/gulp/tests/compile-pages.spec.js @@ -1,18 +1,15 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ -'use strict'; - -var compilePages = require('../lib/compile-pages'), - removeDir = require('../lib/remove-dir'), - expect = require('chai').expect, - mockery = require('mockery'), - Promise = require('bluebird'), - sinon = require('sinon'), - fs = require('fs'); - -describe('Given pages and posts', function () { - var rootPath = '/tmp/compile-pages'; +"use strict"; + +var compilePages = require("../lib/compile-pages"), + removeDir = require("../lib/remove-dir"), + expect = require("chai").expect, + mockery = require("mockery"), + Promise = require("bluebird"), + sinon = require("sinon"), + fs = require("fs"); + +describe("Given pages and posts", function () { + var rootPath = ".tmp/compile-pages"; var doneStub, errorStub; before(function () { @@ -20,19 +17,24 @@ describe('Given pages and posts', function () { errorStub = sinon.stub(); // create the root path - if (!fs.existsSync(rootPath)) { - fs.mkdirSync(rootPath); - } + [ + ".tmp", + ".tmp/compile-pages" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); // set-up folders: [ - '/src', - '/src/templates', - '/src/templates/partials', - '/build', - '/build/content', - '/build/content/pages', - '/build/content/posts' + "/src", + "/src/templates", + "/src/templates/partials", + "/build", + "/build/content", + "/build/content/pages", + "/build/content/posts" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); @@ -40,19 +42,19 @@ describe('Given pages and posts', function () { }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', - '{"title":"Test site","testSiteVar":"my test value"}', { - encoding: 'utf8' + fs.writeFileSync(rootPath + "/site.json", + "{\"title\":\"Test site\",\"testSiteVar\":\"my test value\"}", { + encoding: "utf8" }); fs.writeFileSync(rootPath + - '/src/templates/page.hbs', - '

    {{post.title}}

    {{{post.body}}}

    {{site.testSiteVar}}

    {{post.site.testSiteVar}}

    ', { - encoding: 'utf8' + "/src/templates/page.hbs", + "

    {{post.title}}

    {{{post.body}}}

    {{site.testSiteVar}}

    {{post.site.testSiteVar}}

    ", { + encoding: "utf8" }); fs.writeFileSync(rootPath + - '/src/templates/post.hbs', - '

    {{post.title}}

    {{{post.body}}}

    {{site.testSiteVar}}

    {{post.site.testSiteVar}}

    ', { - encoding: 'utf8' + "/src/templates/post.hbs", + "

    {{post.title}}

    {{{post.body}}}

    {{site.testSiteVar}}

    {{post.site.testSiteVar}}

    ", { + encoding: "utf8" }); }); @@ -60,122 +62,122 @@ describe('Given pages and posts', function () { removeDir(rootPath); }); - describe('When compiling a page', function () { + describe("When compiling a page", function () { before(function (done) { fs.writeFileSync(rootPath + - '/build/content/pages/test-page.json', - '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

    Test page content

    "}', { - encoding: 'utf8' + "/build/content/pages/test-page.json", + "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

    Test page content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should create the static page', function () { + it("Should create the static page", function () { expect(fs.existsSync(rootPath + - '/build/test-page/index.html' - )).to.be.true; + "/build/test-page/index.html" + )).to.be.true; }); - it('Should have the correct page content', + it("Should have the correct page content", function () { expect(fs.readFileSync(rootPath + - '/build/test-page/index.html', - 'utf8')).to.equal( - '

    Test page

    Test page content

    my test value

    my test value

    ' - ); + "/build/test-page/index.html", + "utf8")).to.equal( + "

    Test page

    Test page content

    my test value

    my test value

    " + ); }); }); - describe('When compiling a page with no slug', function () { + describe("When compiling a page with no slug", function () { before(function (done) { fs.writeFileSync(rootPath + - '/build/content/pages/test-page-no-slug.json', - '{"title":"Test page no slug","template":"page.hbs","body":"

    Test page content

    "}', { - encoding: 'utf8' + "/build/content/pages/test-page-no-slug.json", + "{\"title\":\"Test page no slug\",\"template\":\"page.hbs\",\"body\":\"

    Test page content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should create the static page', function () { + it("Should create the static page", function () { expect(fs.existsSync(rootPath + - '/build/test-page-no-slug/index.html' - )).to.be.true; + "/build/test-page-no-slug/index.html" + )).to.be.true; }); - it('Should have the correct page content', + it("Should have the correct page content", function () { expect(fs.readFileSync(rootPath + - '/build/test-page-no-slug/index.html', - 'utf8')).to.equal( - '

    Test page no slug

    Test page content

    my test value

    my test value

    ' - ); + "/build/test-page-no-slug/index.html", + "utf8")).to.equal( + "

    Test page no slug

    Test page content

    my test value

    my test value

    " + ); }); }); - describe('When compiling a post', function () { + describe("When compiling a post", function () { before(function (done) { fs.writeFileSync(rootPath + - '/build/content/posts/test-post.json', - '{"slug":"test-post","title":"Test post","date":"2014-06-11","template":"post.hbs","body":"

    Test post content

    "}', { - encoding: 'utf8' + "/build/content/posts/test-post.json", + "{\"slug\":\"test-post\",\"title\":\"Test post\",\"date\":\"2014-06-11\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should create the static post', function () { + it("Should create the static post", function () { expect(fs.existsSync(rootPath + - '/build/test-post/index.html' - )).to.be.true; + "/build/test-post/index.html" + )).to.be.true; }); - it('Should have the correct post content', + it("Should have the correct post content", function () { expect(fs.readFileSync(rootPath + - '/build/test-post/index.html', - 'utf8')).to.equal( - '

    Test post

    Test post content

    my test value

    my test value

    ' - ); + "/build/test-post/index.html", + "utf8")).to.equal( + "

    Test post

    Test post content

    my test value

    my test value

    " + ); }); }); - describe('When compiling a post with no slug', function () { + describe("When compiling a post with no slug", function () { before(function (done) { fs.writeFileSync(rootPath + - '/build/content/posts/test-post-no-slug.json', - '{"title":"Test post no slug","date":"2014-06-11","template":"post.hbs","body":"

    Test post content

    "}', { - encoding: 'utf8' + "/build/content/posts/test-post-no-slug.json", + "{\"title\":\"Test post no slug\",\"date\":\"2014-06-11\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should create the static post', function () { + it("Should create the static post", function () { expect(fs.existsSync(rootPath + - '/build/test-post-no-slug/index.html' - )).to.be.true; + "/build/test-post-no-slug/index.html" + )).to.be.true; }); - it('Should have the correct post content', + it("Should have the correct post content", function () { expect(fs.readFileSync(rootPath + - '/build/test-post-no-slug/index.html', - 'utf8')).to.equal( - '

    Test post no slug

    Test post content

    my test value

    my test value

    ' - ); + "/build/test-post-no-slug/index.html", + "utf8")).to.equal( + "

    Test post no slug

    Test post content

    my test value

    my test value

    " + ); }); }); - describe('When an error occurs with the promises', function () { + describe("When an error occurs with the promises", function () { var promisesListStub, newCompilePages; beforeEach(function (done) { fs.writeFileSync(rootPath + - '/build/content/pages/test-page.json', - '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

    Test page content

    "}', { - encoding: 'utf8' + "/build/content/pages/test-page.json", + "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

    Test page content

    \"}", { + encoding: "utf8" }); mockery.enable({ @@ -189,99 +191,97 @@ describe('Given pages and posts', function () { promisesListStub = { filter: function () { return [Promise.reject( - 'An error occurred' - )]; + "An error occurred" + )]; } }; mockery.registerMock( - '../lib/promises', + "../lib/promises", promisesListStub); newCompilePages = require( - '../lib/compile-pages'); + "../lib/compile-pages"); - newCompilePages.run(rootPath, - function () { + newCompilePages(rootPath).then(function () { done(); }, function (err) { errorStub(err); done(); }); - }); - it('Should call the error function', function () { + it("Should call the error function", function () { expect(errorStub.called).to.be.true; }); afterEach(function () { mockery.deregisterMock( - '../lib/promises'); + "../lib/promises"); mockery.disable(); }); }); describe( - 'When compiling posts and excluding draft templates', + "When compiling posts and excluding draft templates", function () { before(function (done) { fs.writeFileSync(rootPath + - '/build/content/posts/test-draft-post.json', - '{"slug":"test-draft-post","title":"Test draft post","date":"2014-06-11","template":"post.hbs","status":"draft","body":"

    Test draft post content

    "}', { - encoding: 'utf8' + "/build/content/posts/test-draft-post.json", + "{\"slug\":\"test-draft-post\",\"title\":\"Test draft post\",\"date\":\"2014-06-11\",\"template\":\"post.hbs\",\"status\":\"draft\",\"body\":\"

    Test draft post content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should not create the static post', + it("Should not create the static post", function () { expect(fs.existsSync(rootPath + - '/build/test-draft-post/index.html' - )).to.be.false; + "/build/test-draft-post/index.html" + )).to.be.false; }); }); - describe('When compiling posts and including tags', + describe("When compiling posts and including tags", function () { before(function (done) { fs.writeFileSync(rootPath + - '/src/templates/post.hbs', - '

    {{post.title}}

    {{{post.body}}}
    ', { - encoding: 'utf8' + "/src/templates/post.hbs", + "

    {{post.title}}

    {{{post.body}}}
    ", { + encoding: "utf8" }); fs.writeFileSync(rootPath + - '/build/content/posts/test-tagged-post.json', - '{"slug":"test-tagged-post","title":"Test tagged post","date":"2014-06-11","template":"post.hbs","tags":"tag1 tag2","body":"

    Test tagged post content

    "}', { - encoding: 'utf8' + "/build/content/posts/test-tagged-post.json", + "{\"slug\":\"test-tagged-post\",\"title\":\"Test tagged post\",\"date\":\"2014-06-11\",\"template\":\"post.hbs\",\"tags\":\"tag1 tag2\",\"body\":\"

    Test tagged post content

    \"}", { + encoding: "utf8" }); - compilePages.run(rootPath, done, + compilePages(rootPath).then(done, errorStub); }); - it('Should have the correct post content', + it("Should have the correct post content", function () { expect(fs.readFileSync(rootPath + - '/build/test-tagged-post/index.html', - 'utf8')).to.equal( - '

    Test tagged post

    Test tagged post content

    ' - ); + "/build/test-tagged-post/index.html", + "utf8")).to.equal( + "

    Test tagged post

    Test tagged post content

    " + ); }); }); - describe('When there are no posts or pages to compile', + describe("When there are no posts or pages to compile", function () { beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); fs.writeFileSync(rootPath + - '/site.json', - '{"title":"Test site"}', { - encoding: 'utf8' + "/site.json", + "{\"title\":\"Test site\"}", { + encoding: "utf8" }); - compilePages.run(rootPath, function () { + compilePages(rootPath).then(function () { doneStub(); done(); }, function () { @@ -290,21 +290,21 @@ describe('Given pages and posts', function () { }); }); - it('Should call done', function () { + it("Should call done", function () { expect(doneStub.called).to.be.true; }); }); - describe('When a glob error occurs', function () { + describe("When a glob error occurs", function () { var globStub, newCompilePages; beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); fs.writeFileSync(rootPath + - '/site.json', - '{"title":"Test site"}', { - encoding: 'utf8' + "/site.json", + "{\"title\":\"Test site\"}", { + encoding: "utf8" }); mockery.enable({ @@ -318,39 +318,38 @@ describe('Given pages and posts', function () { globStub = function (paths, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); }; - mockery.registerMock('glob', + mockery.registerMock("glob", globStub); newCompilePages = require( - '../lib/compile-pages'); - - newCompilePages.run(rootPath, - function () { - done(); - }, - function (err) { - errorStub(err); - done(); - }); + "../lib/compile-pages"); + + newCompilePages(rootPath).then(function () { + done(); + }, + function (err) { + errorStub(err); + done(); + }); }); - it('Should throw a glob error', function () { + it("Should throw a glob error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { + it("Should throw a specific error", function () { expect(errorStub.calledWith({ - message: 'I threw an error' + message: "I threw an error" })).to.be.true; }); afterEach(function () { - mockery.deregisterMock('glob'); + mockery.deregisterMock("glob"); mockery.disable(); }); }); -}); +}); \ No newline at end of file diff --git a/gulp/tests/compile-rss.spec.js b/gulp/tests/compile-rss.spec.js index a631d6b..81c60bd 100644 --- a/gulp/tests/compile-rss.spec.js +++ b/gulp/tests/compile-rss.spec.js @@ -1,17 +1,14 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ -'use strict'; - -var compileRss = require('../lib/compile-rss'), - removeDir = require('../lib/remove-dir'), - expect = require('chai').expect, - mockery = require('mockery'), - sinon = require('sinon'), - fs = require('fs'); - -describe('Given the RSS feed', function () { - var rootPath = '/tmp/compile-rss'; +"use strict"; + +var compileRss = require("../lib/compile-rss"), + removeDir = require("../lib/remove-dir"), + expect = require("chai").expect, + mockery = require("mockery"), + sinon = require("sinon"), + fs = require("fs"); + +describe("Given the RSS feed", function () { + var rootPath = ".tmp/compile-rss"; var doneStub, errorStub; before(function () { @@ -19,16 +16,21 @@ describe('Given the RSS feed', function () { errorStub = sinon.stub(); // create the root path - if (!fs.existsSync(rootPath)) { - fs.mkdirSync(rootPath); - } + [ + ".tmp", + ".tmp/compile-rss" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); // set-up folders: [ - '/build', - '/build/content', - '/build/content/pages', - '/build/content/posts' + "/build", + "/build/content", + "/build/content/pages", + "/build/content/posts" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); @@ -36,45 +38,45 @@ describe('Given the RSS feed', function () { }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); }); - describe('When compiling the rss feed', function () { + describe("When compiling the rss feed", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/pages/test-page.json', '{"slug":"test-page","title":"Test page","template":"page.hbs","body":"

    Test page content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","template":"post.hbs","date":"2015-01-10","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","template":"post.hbs","date":"2015-01-20","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileRss.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/pages/test-page.json", "{\"slug\":\"test-page\",\"title\":\"Test page\",\"template\":\"page.hbs\",\"body\":\"

    Test page content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"template\":\"post.hbs\",\"date\":\"2015-01-10\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"template\":\"post.hbs\",\"date\":\"2015-01-20\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileRss(rootPath).then(done, errorStub); }); - it('Should create the static RSS xml file', function () { - expect(fs.existsSync(rootPath + '/build/rss.xml')).to.be.true; + it("Should create the static RSS xml file", function () { + expect(fs.existsSync(rootPath + "/build/rss.xml")).to.be.true; }); - it('Should have the correct RSS content', function () { - expect(fs.readFileSync(rootPath + '/build/rss.xml', 'utf8')).to.match(/Test post 2/); + it("Should have the correct RSS content", function () { + expect(fs.readFileSync(rootPath + "/build/rss.xml", "utf8")).to.match(/Test post 2/); }); }); - describe('When compiling the RSS feed excluding draft posts', function () { + describe("When compiling the RSS feed excluding draft posts", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","template":"post.hbs","date":"2015-01-10","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","template":"post.hbs","date":"2015-01-20","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post3.json', '{"slug":"test-post3","title":"Test post 3","template":"post.hbs","date":"2015-01-30","status":"draft","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileRss.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"template\":\"post.hbs\",\"date\":\"2015-01-10\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"template\":\"post.hbs\",\"date\":\"2015-01-20\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post3.json", "{\"slug\":\"test-post3\",\"title\":\"Test post 3\",\"template\":\"post.hbs\",\"date\":\"2015-01-30\",\"status\":\"draft\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileRss(rootPath).then(done, errorStub); }); - it('Should have the correct RSS content', function () { - expect(fs.readFileSync(rootPath + '/build/rss.xml', 'utf8')).to.not.match(/Test post 3/); + it("Should have the correct RSS content", function () { + expect(fs.readFileSync(rootPath + "/build/rss.xml", "utf8")).to.not.match(/Test post 3/); }); }); - describe('When there are no posts for the RSS feed', function () { + describe("When there are no posts for the RSS feed", function () { beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - compileRss.run(rootPath, function () { + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); + compileRss(rootPath).then(function () { doneStub(); done(); }, function () { @@ -83,18 +85,18 @@ describe('Given the RSS feed', function () { }); }); - it('Should call done', function () { + it("Should call done", function () { expect(doneStub.called).to.be.true; }); }); - describe('When a fs writeFile error occurs', function () { + describe("When a fs writeFile error occurs", function () { var fsStub, globStub, newCompileRss; before(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); mockery.enable({ warnOnReplace: false, @@ -103,29 +105,29 @@ describe('Given the RSS feed', function () { }); globStub = function (paths, options, callback) { - callback(null, ['./file1', './file2', '/file3']); + callback(null, ["./file1", "./file2", "/file3"]); }; fsStub = { readdir: function (path, callback) { - callback(null, ['./file1', './file2', '/file3']); + callback(null, ["./file1", "./file2", "/file3"]); }, - readFileSync: function (file, encoding) { - return '{"slug":"test-post1","title":"Test post 1","template":"post.hbs","date":"2015-01-10","body":"

    Test post content

    "}'; + readFileSync: function () { + return "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"template\":\"post.hbs\",\"date\":\"2015-01-10\",\"body\":\"

    Test post content

    \"}"; }, writeFile: function (path, content, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); } }; - mockery.registerMock('fs', fsStub); - mockery.registerMock('glob', globStub); + mockery.registerMock("fs", fsStub); + mockery.registerMock("glob", globStub); - newCompileRss = require('../lib/compile-rss'); + newCompileRss = require("../lib/compile-rss"); - newCompileRss.run(rootPath, function () { + newCompileRss(rootPath).then(function () { //done(); }, function (err) { errorStub(err); @@ -133,12 +135,12 @@ describe('Given the RSS feed', function () { }); }); - it('Should throw the writeFile error', function () { + it("Should throw the writeFile error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { - expect(errorStub.calledWith({ message: 'I threw an error' })).to.be.true; + it("Should throw a specific error", function () { + expect(errorStub.calledWith({ message: "I threw an error" })).to.be.true; }); after(function () { @@ -146,13 +148,13 @@ describe('Given the RSS feed', function () { }); }); - describe('When a glob error occurs', function () { + describe("When a glob error occurs", function () { var globStub, newCompileRss; before(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); mockery.enable({ warnOnReplace: false, @@ -162,15 +164,15 @@ describe('Given the RSS feed', function () { globStub = function (paths, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); }; - mockery.registerMock('glob', globStub); + mockery.registerMock("glob", globStub); - newCompileRss = require('../lib/compile-rss'); + newCompileRss = require("../lib/compile-rss"); - newCompileRss.run(rootPath, function () { + newCompileRss(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -178,12 +180,12 @@ describe('Given the RSS feed', function () { }); }); - it('Should throw a glob error', function () { + it("Should throw a glob error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { - expect(errorStub.calledWith({ message: 'I threw an error' })).to.be.true; + it("Should throw a specific error", function () { + expect(errorStub.calledWith({ message: "I threw an error" })).to.be.true; }); after(function () { diff --git a/gulp/tests/compile-tags.spec.js b/gulp/tests/compile-tags.spec.js index 4b88881..e7f9db6 100644 --- a/gulp/tests/compile-tags.spec.js +++ b/gulp/tests/compile-tags.spec.js @@ -1,18 +1,15 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ -'use strict'; - -var compileTags = require('../lib/compile-tags'), - removeDir = require('../lib/remove-dir'), - expect = require('chai').expect, - mockery = require('mockery'), - Promise = require('bluebird'), - sinon = require('sinon'), - fs = require('fs'); - -describe('When compiling tag pages', function () { - var rootPath = '/tmp/compile-tags'; +"use strict"; + +var compileTags = require("../lib/compile-tags"), + removeDir = require("../lib/remove-dir"), + expect = require("chai").expect, + mockery = require("mockery"), + Promise = require("bluebird"), + sinon = require("sinon"), + fs = require("fs"); + +describe("When compiling tag pages", function () { + var rootPath = ".tmp/compile-tags"; var doneStub, errorStub; before(function () { @@ -20,21 +17,26 @@ describe('When compiling tag pages', function () { errorStub = sinon.stub(); // create the root path - if (!fs.existsSync(rootPath)) { - fs.mkdirSync(rootPath); - } + [ + ".tmp", + ".tmp/compile-tags" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); // set-up folders: [ - '/src', - '/src/templates', - '/src/templates/partials', - '/build', - '/build/tag', - '/build/tag/page', - '/build/content', - '/build/content/pages', - '/build/content/posts' + "/src", + "/src/templates", + "/src/templates/partials", + "/build", + "/build/tag", + "/build/tag/page", + "/build/content", + "/build/content/pages", + "/build/content/posts" ].forEach(function (dir) { if (!fs.existsSync(rootPath + dir)) { fs.mkdirSync(rootPath + dir); @@ -42,43 +44,43 @@ describe('When compiling tag pages', function () { }); // set-up files: - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/loop.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/partials/pagination.hbs', '', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/src/templates/index.hbs', '
    {{> loop}}{{> pagination}}
    ', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/partials/loop.hbs", "", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/partials/pagination.hbs", "", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/src/templates/index.hbs", "
    {{> loop}}{{> pagination}}
    ", { encoding: "utf8" }); }); after(function () { removeDir(rootPath); }); - describe('When compiling tag pages', function () { + describe("When compiling tag pages", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-06-11","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","tags":"mocha coke","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileTags.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-06-11\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"tags\":\"mocha coke\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileTags(rootPath).then(done, errorStub); }); - it('Should create the mocha tag page', function () { - expect(fs.existsSync(rootPath + '/build/tag/mocha/index.html')).to.be.true; + it("Should create the mocha tag page", function () { + expect(fs.existsSync(rootPath + "/build/tag/mocha/index.html")).to.be.true; }); - it('Should create the coke tag page', function () { - expect(fs.existsSync(rootPath + '/build/tag/coke/index.html')).to.be.true; + it("Should create the coke tag page", function () { + expect(fs.existsSync(rootPath + "/build/tag/coke/index.html")).to.be.true; }); - it('Should have the correct mocha tag page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/mocha/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct mocha tag page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/mocha/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should have the correct coke tag page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/coke/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct coke tag page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/coke/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When an error occurs with the promises', function () { + describe("When an error occurs with the promises", function () { var promisesListStub, newCompileTags; beforeEach(function (done) { @@ -94,15 +96,15 @@ describe('When compiling tag pages', function () { promisesListStub = { filter: function () { - return [Promise.reject('An error occurred')]; + return [Promise.reject("An error occurred")]; } }; - mockery.registerMock('../lib/promises', promisesListStub); + mockery.registerMock("../lib/promises", promisesListStub); - newCompileTags = require('../lib/compile-tags'); + newCompileTags = require("../lib/compile-tags"); - newCompileTags.run(rootPath, function () { + newCompileTags(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -111,81 +113,81 @@ describe('When compiling tag pages', function () { }); - it('Should call the error function', function () { + it("Should call the error function", function () { expect(errorStub.called).to.be.true; }); afterEach(function () { - mockery.deregisterMock('../lib/promises'); + mockery.deregisterMock("../lib/promises"); mockery.disable(); }); }); - describe('When compiling tag pages and excluding draft templates', function () { + describe("When compiling tag pages and excluding draft templates", function () { before(function (done) { - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-06-11","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","status":"draft","tags":"mocha coke","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileTags.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-06-11\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"status\":\"draft\",\"tags\":\"mocha coke\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileTags(rootPath).then(done, errorStub); }); - it('Should have the correct mocha tag page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/mocha/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct mocha tag page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/mocha/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When compiling tag posts with pagination', function () { + describe("When compiling tag posts with pagination", function () { before(function (done) { - fs.writeFileSync(rootPath + '/site.json', '{ "title": "Test site", "maxItems": "2" }', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post1.json', '{"slug":"test-post1","title":"Test post 1","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post2.json', '{"slug":"test-post2","title":"Test post 2","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post3.json', '{"slug":"test-post3","title":"Test post 3","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post4.json', '{"slug":"test-post4","title":"Test post 4","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post5.json', '{"slug":"test-post5","title":"Test post 5","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post6.json', '{"slug":"test-post6","title":"Test post 6","date":"2014-12-05","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - fs.writeFileSync(rootPath + '/build/content/posts/test-post7.json', '{"slug":"test-post7","title":"Test post 7","tags":"mocha","template":"post.hbs","body":"

    Test post content

    "}', { encoding: 'utf8' }); - compileTags.run(rootPath, done, errorStub); + fs.writeFileSync(rootPath + "/site.json", "{ \"title\": \"Test site\", \"maxItems\": \"2\" }", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post1.json", "{\"slug\":\"test-post1\",\"title\":\"Test post 1\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post2.json", "{\"slug\":\"test-post2\",\"title\":\"Test post 2\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post3.json", "{\"slug\":\"test-post3\",\"title\":\"Test post 3\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post4.json", "{\"slug\":\"test-post4\",\"title\":\"Test post 4\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post5.json", "{\"slug\":\"test-post5\",\"title\":\"Test post 5\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post6.json", "{\"slug\":\"test-post6\",\"title\":\"Test post 6\",\"date\":\"2014-12-05\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + fs.writeFileSync(rootPath + "/build/content/posts/test-post7.json", "{\"slug\":\"test-post7\",\"title\":\"Test post 7\",\"tags\":\"mocha\",\"template\":\"post.hbs\",\"body\":\"

    Test post content

    \"}", { encoding: "utf8" }); + compileTags(rootPath).then(done, errorStub); }); - it('Should have the correct mocha tag page content', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/mocha/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct mocha tag page content", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/mocha/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should create the second paginated mocha tag page', function () { - expect(fs.existsSync(rootPath + '/build/tag/mocha/page/2/index.html')).to.be.true; + it("Should create the second paginated mocha tag page", function () { + expect(fs.existsSync(rootPath + "/build/tag/mocha/page/2/index.html")).to.be.true; }); - it('Should create the third paginated mocha tag page', function () { - expect(fs.existsSync(rootPath + '/build/tag/mocha/page/3/index.html')).to.be.true; + it("Should create the third paginated mocha tag page", function () { + expect(fs.existsSync(rootPath + "/build/tag/mocha/page/3/index.html")).to.be.true; }); - it('Should have the correct content for the second paginated page', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/mocha/page/2/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct content for the second paginated page", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/mocha/page/2/index.html", "utf8")).to.equal(expectedHtml); }); - it('Should have the correct content for the third paginated page', function () { - var expectedHtml = ''; - expect(fs.readFileSync(rootPath + '/build/tag/mocha/page/3/index.html', 'utf8')).to.equal(expectedHtml); + it("Should have the correct content for the third paginated page", function () { + var expectedHtml = ""; + expect(fs.readFileSync(rootPath + "/build/tag/mocha/page/3/index.html", "utf8")).to.equal(expectedHtml); }); }); - describe('When there are no posts for the tag pages', function () { + describe("When there are no posts for the tag pages", function () { beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); - compileTags.run(rootPath, function () { + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); + compileTags(rootPath).then(function () { doneStub(); done(); }, function () { @@ -194,18 +196,18 @@ describe('When compiling tag pages', function () { }); }); - it('Should call done', function () { + it("Should call done", function () { expect(doneStub.called).to.be.true; }); }); - describe('When a glob error occurs', function () { + describe("When a glob error occurs", function () { var globStub, newCompileTags; beforeEach(function (done) { removeDir(rootPath); fs.mkdirSync(rootPath); - fs.writeFileSync(rootPath + '/site.json', '{"title":"Test site"}', { encoding: 'utf8' }); + fs.writeFileSync(rootPath + "/site.json", "{\"title\":\"Test site\"}", { encoding: "utf8" }); mockery.enable({ warnOnReplace: false, @@ -217,15 +219,15 @@ describe('When compiling tag pages', function () { globStub = function (paths, options, callback) { callback({ - message: 'I threw an error' + message: "I threw an error" }, null); }; - mockery.registerMock('glob', globStub); + mockery.registerMock("glob", globStub); - newCompileTags = require('../lib/compile-tags'); + newCompileTags = require("../lib/compile-tags"); - newCompileTags.run(rootPath, function () { + newCompileTags(rootPath).then(function () { done(); }, function (err) { errorStub(err); @@ -233,16 +235,16 @@ describe('When compiling tag pages', function () { }); }); - it('Should throw a glob error', function () { + it("Should throw a glob error", function () { expect(errorStub.called).to.be.true; }); - it('Should throw a specific error', function () { - expect(errorStub.calledWith({ message: 'I threw an error' })).to.be.true; + it("Should throw a specific error", function () { + expect(errorStub.calledWith({ message: "I threw an error" })).to.be.true; }); afterEach(function () { - mockery.deregisterMock('glob'); + mockery.deregisterMock("glob"); mockery.disable(); }); }); diff --git a/gulp/tests/dates.spec.js b/gulp/tests/dates.spec.js index c08dc5b..c4efc79 100644 --- a/gulp/tests/dates.spec.js +++ b/gulp/tests/dates.spec.js @@ -1,6 +1,3 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ "use strict"; var dates = require("../lib/dates"), diff --git a/gulp/tests/downzero.spec.js b/gulp/tests/downzero.spec.js index 4a270af..5018359 100644 --- a/gulp/tests/downzero.spec.js +++ b/gulp/tests/downzero.spec.js @@ -1,36 +1,34 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W079 */ -'use strict'; +"use strict"; -var downzero = require('../lib/downzero'), - expect = require('chai').expect; +var downzero = require("../lib/downzero"), + expect = require("chai").expect; -describe('When extracting html tags with double quotes', function () { +describe("When extracting html tags with double quotes", function () { beforeEach(function () { - this.html = '

    This is the first paragraph.

    '; + this.html = "

    This is the first paragraph.

    "; }); - it('Should strip just the first tag from the html', function () { - expect(downzero(this.html)).to.equal('

    '); + it("Should strip just the first tag from the html", function () { + expect(downzero(this.html)).to.equal("

    "); }); }); -describe('When extracting html tags with single quotes', function () { +describe("When extracting html tags with single quotes", function () { beforeEach(function () { - this.html = '

    This is the "first paragraph".

    '; + this.html = "

    This is the \"first paragraph\".

    "; }); - it('Should strip just the first tag from the html', function () { - expect(downzero(this.html)).to.equal('

    '); + it("Should strip just the first tag from the html", function () { + expect(downzero(this.html)).to.equal("

    "); }); }); -describe('When extracting html tags with comments', function () { +describe("When extracting html tags with comments", function () { beforeEach(function () { - this.html = '

    This is the first paragraph.

    '; + this.html = "

    This is the first paragraph.

    "; }); - it('Should strip just the first tag from the html', function () { - expect(downzero(this.html)).to.equal('

    '); + it("Should strip just the first tag from the html", function () { + expect(downzero(this.html)).to.equal("

    "); }); }); diff --git a/gulp/tests/drafts.spec.js b/gulp/tests/drafts.spec.js index a623f37..d031847 100644 --- a/gulp/tests/drafts.spec.js +++ b/gulp/tests/drafts.spec.js @@ -1,10 +1,6 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ "use strict"; var compileDrafts, - sinon = require("sinon"), mockery = require("mockery"), expect = require("chai").expect; diff --git a/gulp/tests/paths.spec.js b/gulp/tests/paths.spec.js index 76dccd2..7c93b96 100644 --- a/gulp/tests/paths.spec.js +++ b/gulp/tests/paths.spec.js @@ -1,5 +1,3 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W079 */ "use strict"; var paths = require("../lib/paths"), diff --git a/gulp/tests/remove-dir.spec.js b/gulp/tests/remove-dir.spec.js index 45596b6..9f3f3f4 100644 --- a/gulp/tests/remove-dir.spec.js +++ b/gulp/tests/remove-dir.spec.js @@ -1,6 +1,3 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ "use strict"; var removeDir = require("../lib/remove-dir"), @@ -10,16 +7,22 @@ var removeDir = require("../lib/remove-dir"), describe("When removing directories", function () { beforeEach(function () { + // create the root path + [ + ".tmp", + ".tmp/remove-dir-test" + ].forEach(function (dir) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + }); + var files = { - "/tmp/remove-dir-test/file1": "This is test content", - "/tmp/remove-dir-test/file2": "This is test content", - "/tmp/remove-dir-test/file3": "This is test content" + ".tmp/remove-dir-test/file1": "This is test content", + ".tmp/remove-dir-test/file2": "This is test content", + ".tmp/remove-dir-test/file3": "This is test content" }; - if (!fs.existsSync("/tmp/remove-dir-test")) { - fs.mkdirSync("/tmp/remove-dir-test"); - } - for (var file in files) { if (files.hasOwnProperty(file)) { fs.writeFileSync(file, files[file], { encoding: "utf8" }); @@ -27,59 +30,63 @@ describe("When removing directories", function () { } }); + after(function() { + removeDir(".tmp/remove-dir-test"); + }); + describe("When the temp directory structure is created", function () { it("Should have a temp directory structure", function () { - expect(fs.existsSync("/tmp/remove-dir-test")).to.be.true; + expect(fs.existsSync(".tmp/remove-dir-test")).to.be.true; }); it("Should have a temp file in the directory", function () { - expect(fs.existsSync("/tmp/remove-dir-test/file1")).to.be.true; + expect(fs.existsSync(".tmp/remove-dir-test/file1")).to.be.true; }); }); describe("When removing the temp directory", function () { beforeEach(function () { - removeDir("/tmp/remove-dir-test"); + removeDir(".tmp/remove-dir-test"); }); it("Should remove the temp directory structure", function () { - expect(fs.existsSync("/tmp/remove-dir-test")).to.be.false; + expect(fs.existsSync(".tmp/remove-dir-test")).to.be.false; }); }); describe("When removing the contents of the temp directory", function () { beforeEach(function () { - removeDir("/tmp/remove-dir-test", false); + removeDir(".tmp/remove-dir-test", false); }); it("Should not remove the temp directory structure", function () { - expect(fs.existsSync("/tmp/remove-dir-test")).to.be.true; + expect(fs.existsSync(".tmp/remove-dir-test")).to.be.true; }); it("Should remove the temp file in the directory", function () { - expect(fs.existsSync("/tmp/remove-dir-test/file1")).to.be.false; + expect(fs.existsSync(".tmp/remove-dir-test/file1")).to.be.false; }); }); describe("When a nested directory of files exists", function () { beforeEach(function () { - if (!fs.existsSync("/tmp/remove-dir-test/nested-dir")) { - fs.mkdirSync("/tmp/remove-dir-test/nested-dir"); + if (!fs.existsSync(".tmp/remove-dir-test/nested-dir")) { + fs.mkdirSync(".tmp/remove-dir-test/nested-dir"); } - fs.writeFileSync("/tmp/remove-dir-test/nested-dir/file1", "This is test content", { encoding: "utf8" }); + fs.writeFileSync(".tmp/remove-dir-test/nested-dir/file1", "This is test content", { encoding: "utf8" }); }); it("Should have a nested directory structure", function () { - expect(fs.existsSync("/tmp/remove-dir-test/nested-dir/file1")).to.be.true; + expect(fs.existsSync(".tmp/remove-dir-test/nested-dir/file1")).to.be.true; }); describe("When the nested directory is removed", function () { beforeEach(function () { - removeDir("/tmp/remove-dir-test"); + removeDir(".tmp/remove-dir-test"); }); it("Should remove the temp directory structure", function () { - expect(fs.existsSync("/tmp/remove-dir-test")).to.be.false; + expect(fs.existsSync(".tmp/remove-dir-test")).to.be.false; }); }); }); @@ -88,7 +95,7 @@ describe("When removing directories", function () { var fsStub, newRemoveDir, error; before(function () { - removeDir("/tmp/remove-dir-test"); + removeDir(".tmp/remove-dir-test"); mockery.enable({ warnOnReplace: false, @@ -97,7 +104,7 @@ describe("When removing directories", function () { }); fsStub = { - readdirSync: function (path) { + readdirSync: function () { throw new Error("readdirSync error!"); } }; @@ -106,7 +113,7 @@ describe("When removing directories", function () { newRemoveDir = require("../lib/remove-dir"); - error = newRemoveDir("/tmp/remove-dir-test"); + error = newRemoveDir(".tmp/remove-dir-test"); }); it("Should throw an error", function () { diff --git a/gulp/tests/tags.spec.js b/gulp/tests/tags.spec.js index f46399b..5d158c2 100644 --- a/gulp/tests/tags.spec.js +++ b/gulp/tests/tags.spec.js @@ -1,6 +1,3 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W030 */ -/* jshint -W079 */ "use strict"; var tags = require("../lib/tags"), diff --git a/gulpfile.js b/gulpfile.js index feb1815..2c079a9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,8 @@ -(function() { - "use strict"; +"use strict"; - var requireDir = require("require-dir"); +var requireDir = require("require-dir"); - // require all tasks in gulp/tasks, including sub-folders - requireDir("./gulp/tasks", { recurse: true }); -})(); +// require all tasks in gulp/tasks, including sub-folders +requireDir("./gulp/tasks", { + recurse: true +}); \ No newline at end of file diff --git a/install.js b/install.js index 6ae19cb..bbbee5c 100644 --- a/install.js +++ b/install.js @@ -1,4 +1,3 @@ -/* global process, __dirname */ "use strict"; /* diff --git a/install/content/index.md b/install/content/index.md deleted file mode 100644 index 676ad86..0000000 --- a/install/content/index.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -slug: index -title: Home -template: index.hbs ---- - diff --git a/install/files.json b/install/files.json index 321956c..d08075b 100644 --- a/install/files.json +++ b/install/files.json @@ -12,10 +12,6 @@ "file": "site.json", "encoding": "utf8" }, - { - "file": "content/index.md", - "encoding": "utf8" - }, { "file": "content/template.md", "encoding": "utf8" diff --git a/install/tests/version-compare.spec.js b/install/tests/version-compare.spec.js index a7265bf..a05ebfe 100644 --- a/install/tests/version-compare.spec.js +++ b/install/tests/version-compare.spec.js @@ -1,5 +1,3 @@ -/* globals it, afterEach, beforeEach, after, describe, before */ -/* jshint -W079 */ "use strict"; var versionCompare = require("../lib/version-compare"), diff --git a/package.json b/package.json index 52765c1..aed22e7 100644 --- a/package.json +++ b/package.json @@ -1,55 +1,59 @@ { - "name": "gulp-site-generator", - "version": "0.1.28", - "description": "Static site generator using Gulp", - "main": "gulpfile.js", - "scripts": { - "test": "gulp test" - }, - "keywords": [ - "gulp", - "static", - "generator" - ], - "author": "Matt Levy ", - "license": "ISC", - "dependencies": { - "bluebird": "^3.1.1", - "downsize": "0.0.8", - "glob": "^6.0.3", - "gulp": "^3.9.0", - "gulp-compile-handlebars": "^0.6.1", - "gulp-concat": "^2.6.0", - "gulp-connect": "^2.3.1", - "gulp-if": "^2.0.0", - "gulp-markdown-to-json": "^0.2.1", - "gulp-minify-css": "^1.2.3", - "gulp-minify-html": "^1.0.5", - "gulp-rename": "^1.2.2", - "gulp-replace": "^0.5.4", - "gulp-sass": "^2.1.1", - "gulp-uglify": "^1.5.1", - "gulp-uncss": "^1.0.4", - "gulp-util": "^3.0.7", - "handlebars": "^4.0.5", - "imagemin-mozjpeg": "^5.1.0", - "imagemin-optipng": "^4.3.0", - "imagemin-pngquant": "^4.2.0", - "lodash": "^3.10.1", - "minimist": "^1.2.0", - "moment": "^2.10.6", - "mout": "^0.11.1", - "require-dir": "^0.3.0", - "rss": "^1.2.1" - }, - "devDependencies": { - "chai": "^3.4.1", - "github-changes": "^1.0.0", - "gulp-coveralls": "^0.1.4", - "gulp-istanbul": "^0.10.3", - "gulp-mocha": "^2.2.0", - "mocha": "^2.3.4", - "mockery": "^1.4.0", - "sinon": "^1.17.2" - } -} + "name": "gulp-site-generator", + "version": "0.2.0", + "description": "Static site generator using Gulp", + "main": "gulpfile.js", + "scripts": { + "test": "gulp test", + "debug": "mocha --debug-brk gulp/tests/*.spec.js" + }, + "keywords": [ + "gulp", + "static", + "generator" + ], + "author": "Matt Levy ", + "license": "ISC", + "dependencies": { + "bluebird": "3.4.7", + "downsize": "0.0.8", + "glob": "7.1.1", + "gulp": "3.9.1", + "gulp-compile-handlebars": "0.6.1", + "gulp-concat": "2.6.1", + "gulp-connect": "5.0.0", + "gulp-if": "2.0.2", + "gulp-markdown-to-json": "1.0.1", + "gulp-minify-css": "1.2.4", + "gulp-minify-html": "1.0.6", + "gulp-rename": "1.2.2", + "gulp-replace": "0.5.4", + "gulp-sass": "3.1.0", + "gulp-uglify": "2.0.0", + "gulp-uncss": "1.0.6", + "gulp-util": "3.0.8", + "handlebars": "4.0.6", + "imagemin-mozjpeg": "5.1.0", + "imagemin-optipng": "4.3.0", + "imagemin-pngquant": "4.2.0", + "lodash": "4.17.4", + "markdown-it": "8.2.2", + "marked": "0.3.6", + "minimist": "1.2.0", + "moment": "2.17.1", + "mout": "1.0.0", + "relative": "3.0.2", + "require-dir": "0.3.1", + "rss": "1.2.1" + }, + "devDependencies": { + "chai": "3.5.0", + "github-changes": "1.0.4", + "gulp-coveralls": "0.1.4", + "gulp-istanbul": "1.1.1", + "gulp-mocha": "3.0.1", + "mocha": "3.2.0", + "mockery": "2.0.0", + "sinon": "1.17.7" + } +} \ No newline at end of file diff --git a/update.js b/update.js index e563598..dbd1eb0 100644 --- a/update.js +++ b/update.js @@ -1,4 +1,3 @@ -/* global process, __dirname */ "use strict"; /*