From 412d6b33362fb65c76f3da1f0625ebc53a213229 Mon Sep 17 00:00:00 2001 From: Drew Fyock Date: Fri, 17 Jan 2014 10:25:46 -0500 Subject: [PATCH] use consolidate to make template engine configurable --- app/views/{404.jade => 404.html} | 0 app/views/{500.jade => 500.html} | 0 app/views/{index.jade => index.html} | 0 app/views/users/{signin.jade => signin.html} | 0 app/views/users/{signup.jade => signup.html} | 0 config/env/all.js | 3 ++- config/express.js | 16 +++++++++++----- package.json | 1 + public/views/articles/view.html | 4 ++-- 9 files changed, 16 insertions(+), 8 deletions(-) rename app/views/{404.jade => 404.html} (100%) rename app/views/{500.jade => 500.html} (100%) rename app/views/{index.jade => index.html} (100%) rename app/views/users/{signin.jade => signin.html} (100%) rename app/views/users/{signup.jade => signup.html} (100%) diff --git a/app/views/404.jade b/app/views/404.html similarity index 100% rename from app/views/404.jade rename to app/views/404.html diff --git a/app/views/500.jade b/app/views/500.html similarity index 100% rename from app/views/500.jade rename to app/views/500.html diff --git a/app/views/index.jade b/app/views/index.html similarity index 100% rename from app/views/index.jade rename to app/views/index.html diff --git a/app/views/users/signin.jade b/app/views/users/signin.html similarity index 100% rename from app/views/users/signin.jade rename to app/views/users/signin.html diff --git a/app/views/users/signup.jade b/app/views/users/signup.html similarity index 100% rename from app/views/users/signup.jade rename to app/views/users/signup.html diff --git a/config/env/all.js b/config/env/all.js index 6bf44396b7..1fba9f0715 100644 --- a/config/env/all.js +++ b/config/env/all.js @@ -7,10 +7,11 @@ module.exports = { root: rootPath, port: process.env.PORT || 3000, db: process.env.MONGOHQ_URL, + templateEngine: 'jade', // The secret should be set to a non-guessable string that // is used to compute a session hash sessionSecret: 'MEAN', // The name of the MongoDB collection to store sessions in sessionCollection: 'sessions' -} +}; diff --git a/config/express.js b/config/express.js index 3db729e53d..adb3fd11df 100755 --- a/config/express.js +++ b/config/express.js @@ -4,6 +4,7 @@ * Module dependencies. */ var express = require('express'), + consolidate = require('consolidate'), mongoStore = require('connect-mongo')(express), flash = require('connect-flash'), helpers = require('view-helpers'), @@ -31,12 +32,17 @@ module.exports = function(app, passport, db) { app.use(express.logger('dev')); } + // assign the template engine to .html files + app.engine('html', consolidate[config.templateEngine]); + + // set .html as the default extension + app.set('view engine', 'html'); + // Set views path, template engine and default layout app.set('views', config.root + '/app/views'); - app.set('view engine', 'jade'); // Enable jsonp - app.enable("jsonp callback"); + app.enable('jsonp callback'); app.configure(function() { // The cookieParser should be above session @@ -68,7 +74,7 @@ module.exports = function(app, passport, db) { // Routes should be at the last app.use(app.router); - + // Setting the fav icon and static folder app.use(express.favicon()); app.use(express.static(config.root + '/public')); @@ -90,7 +96,7 @@ module.exports = function(app, passport, db) { }); // Assume 404 since no middleware responded - app.use(function(req, res, next) { + app.use(function(req, res) { res.status(404).render('404', { url: req.originalUrl, error: 'Not found' @@ -98,4 +104,4 @@ module.exports = function(app, passport, db) { }); }); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index f181c2c95e..6f1413e172 100755 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "express": "~3.4.7", "jade": "~1.0.2", + "consolidate": "~0.10.0", "mongoose": "~3.8.3", "connect-mongo": "~0.4.0", "connect-flash": "~0.1.1", diff --git a/public/views/articles/view.html b/public/views/articles/view.html index 16b76d8b4e..d1c4ec05ec 100644 --- a/public/views/articles/view.html +++ b/public/views/articles/view.html @@ -1,11 +1,11 @@
- {{article.created | date:'medium'}}/ + {{article.created | date:'medium'}} / {{article.user.name}}

{{article.title}}

- +