From b6dc717a002568ab68db4dc1b8892d93e974346c Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 19 Feb 2016 16:17:59 -0500 Subject: [PATCH] Basic app setup --- .gitignore | 15 +------------ app/config/error-handlers.js | 7 +++++- app/config/view-engine.js | 21 ++++++++++-------- app/controllers/admin.js | 13 +++++++++++ app/controllers/index.js | 12 ++-------- app/views/error.stache | 16 ++++++++++++++ app/views/index.stache | 28 ++++++++++++++++++++++++ app/views/layouts/admin.stache | 7 ++++++ app/views/layouts/blog.stache | 7 ++++++ app/views/partials/blog/head.stache | 5 +++++ gulpfile.js | 6 ++--- package.json | 3 +-- public/{.gitkeep => assets/css/blog.css} | 0 public/assets/css/blog.myth.css | 0 public/assets/js/admin.js | 0 15 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 app/controllers/admin.js create mode 100644 app/views/error.stache create mode 100644 app/views/index.stache create mode 100644 app/views/layouts/admin.stache create mode 100644 app/views/layouts/blog.stache create mode 100644 app/views/partials/blog/head.stache rename public/{.gitkeep => assets/css/blog.css} (100%) create mode 100644 public/assets/css/blog.myth.css create mode 100644 public/assets/js/admin.js diff --git a/.gitignore b/.gitignore index 8b4b628..5b012ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -# Created by https://www.gitignore.io/api/node,osx,webstorm,eclipse - ### Node ### # Logs logs @@ -11,15 +9,6 @@ pids *.pid *.seed -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - # node-waf configuration .lock-wscript @@ -65,9 +54,7 @@ Temporary Items .apdisk # Don't commit generated docs -public/docs/* -public/api-docs/* -public/coverage/* +public/generated/* # Don't commit environment file .env \ No newline at end of file diff --git a/app/config/error-handlers.js b/app/config/error-handlers.js index 3561bc1..162dd65 100644 --- a/app/config/error-handlers.js +++ b/app/config/error-handlers.js @@ -36,7 +36,12 @@ let errorHandlers = new Set([ output.error = err; } - res.json(output); + res.render('error', { + title: `${err.status} ${err.message}`, + error: output, + }); + + //res.json(output); }, ]); diff --git a/app/config/view-engine.js b/app/config/view-engine.js index 628e023..03d6edf 100644 --- a/app/config/view-engine.js +++ b/app/config/view-engine.js @@ -1,15 +1,18 @@ 'use strict'; -// Stupid template engine requires coffescript for some reason -const cs = require('coffee-script'); -cs.register(); - +const handlebars = require('express-handlebars'); const path = require('path'); -const hulk = require('hulk-hogan'); module.exports.setup = (app) => { - let viewPath = path.resolve(__dirname, '../views'); - app.set('views', viewPath); - app.set('view options', { layout: false }); - app.set('view engine', 'hulk'); + const baseViewDir = path.resolve(__dirname, '../views'); + app.set('views', baseViewDir); + app.engine('.stache', handlebars({ + defaultLayout: 'blog', + extname: '.stache', + layoutsDir: `${baseViewDir}/layouts/`, + partialsDir: `${baseViewDir}/partials/`, + })); + + // use .stache files as a default view extension + app.set('view engine', '.stache'); }; \ No newline at end of file diff --git a/app/controllers/admin.js b/app/controllers/admin.js new file mode 100644 index 0000000..3126752 --- /dev/null +++ b/app/controllers/admin.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = { + '/': { + + }, + '/login': { + + }, + '/logout': { + + }, +}; \ No newline at end of file diff --git a/app/controllers/index.js b/app/controllers/index.js index 1c1ba9b..dfa570f 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -2,19 +2,11 @@ module.exports = { '/': { - // Get homepage get: (req, res) => { - return res.json({ - status: 200, - data: { - index: { title: 'Express' }, - }, + return res.render('index', { + title: 'Blog test page', }); }, - - put: (req, res, next) => { - return next(); - }, }, }; \ No newline at end of file diff --git a/app/views/error.stache b/app/views/error.stache new file mode 100644 index 0000000..b075502 --- /dev/null +++ b/app/views/error.stache @@ -0,0 +1,16 @@ +
+

{{error.status}}

+

{{error.message}}

+ {{#if error.error}} +
+ + + {{#each error as |value key|}} + + + + {{/each}} +
Error Details
{{key}}{{value}}
+
+ {{/if}} +
\ No newline at end of file diff --git a/app/views/index.stache b/app/views/index.stache new file mode 100644 index 0000000..bf228f0 --- /dev/null +++ b/app/views/index.stache @@ -0,0 +1,28 @@ +
+
+ +
+ +
+

Article

+
+ + + +
+

Section

+
+ +
+

© Timothy J. Warren

+
+
\ No newline at end of file diff --git a/app/views/layouts/admin.stache b/app/views/layouts/admin.stache new file mode 100644 index 0000000..50405f4 --- /dev/null +++ b/app/views/layouts/admin.stache @@ -0,0 +1,7 @@ + + + {{>head}} + + {{{body}}} + + \ No newline at end of file diff --git a/app/views/layouts/blog.stache b/app/views/layouts/blog.stache new file mode 100644 index 0000000..815fbf8 --- /dev/null +++ b/app/views/layouts/blog.stache @@ -0,0 +1,7 @@ + + + {{>blog/head}} + + {{{body}}} + + \ No newline at end of file diff --git a/app/views/partials/blog/head.stache b/app/views/partials/blog/head.stache new file mode 100644 index 0000000..a488617 --- /dev/null +++ b/app/views/partials/blog/head.stache @@ -0,0 +1,5 @@ + + + {{title}} + + \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 2eaf9d9..e1ca9b6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -155,7 +155,7 @@ gulp.task('src-docs', () => { documentation({ format: 'html', }), - gulp.dest('public/docs'), + gulp.dest('public/generated/docs'), ]); }); @@ -165,7 +165,7 @@ gulp.task('src-docs', () => { gulp.task('api-docs', (done) => { apidoc({ src: 'app/', - dest: 'public/api-docs/', + dest: 'public/generated/api-docs/', }, done); }); @@ -217,7 +217,7 @@ gulp.task('coverage', ['lint', 'pre-coverage'], () => { return pipe(gulp.src(UNIT_TEST_FILES), [ mocha(MOCHA_SETTINGS), istanbul.writeReports({ - dir: 'public/coverage', + dir: 'public/generated/coverage', reporters:['lcov', 'lcovonly', 'html', 'text'], }), ]); diff --git a/package.json b/package.json index 59c282f..12acccd 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,18 @@ "axios": "^0.9.1", "body-parser": "~1.13.2", "ci-node-query": "^3.1.0", - "coffee-script": "^1.10.0", "cookie-parser": "~1.3.5", "debug": "~2.2.0", "dotenv": "^2.0.0", "errors": "^0.3.0", "eslint": "^1.10.3", "express": "4.*", + "express-handlebars": "^3.0.0", "express-session": "^1.13.0", "getargs": "0.0.8", "glob": "^6.0.4", "helmet": "^1.1.0", "highlight.js": "^9.1.0", - "hulk-hogan": "0.0.9", "lodash": "^4.5.0", "marked": "^0.3.5", "morgan": "~1.6.1", diff --git a/public/.gitkeep b/public/assets/css/blog.css similarity index 100% rename from public/.gitkeep rename to public/assets/css/blog.css diff --git a/public/assets/css/blog.myth.css b/public/assets/css/blog.myth.css new file mode 100644 index 0000000..e69de29 diff --git a/public/assets/js/admin.js b/public/assets/js/admin.js new file mode 100644 index 0000000..e69de29