The Puggening: Update from Jade to Pug

1.) module dependency updated from jade 1.11.0 to pug 2.0.0-beta3
2.) All references to Jade have been changed to Pug
3.) /srv/web/jade.js is renamed to pug.js
4.) all template files renamed accordingly
5.) "mixin somename" is automatically considered a declaration, invocations must use "+somename"
6.) variable interpolation is no longer supported inside element attributes, use direct references and string concatenation instead.
7.) bumped minor version
This commit is contained in:
Xaekai 2016-07-07 01:11:56 -07:00
parent f75d40d278
commit df5c5cd54f
31 changed files with 233 additions and 233 deletions

View file

@ -5,7 +5,7 @@
*/
var webserver = require("./webserver");
var sendJade = require("./jade").sendJade;
var sendPug = require("./pug").sendPug;
var Logger = require("../logger");
var db = require("../database");
var $util = require("../utilities");
@ -22,7 +22,7 @@ function handleAccountEditPage(req, res) {
return;
}
sendJade(res, "account-edit", {});
sendPug(res, "account-edit", {});
}
/**
@ -61,14 +61,14 @@ function handleChangePassword(req, res) {
}
if (newpassword.length === 0) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: "New password must not be empty"
});
return;
}
if (!req.user) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: "You must be logged in to change your password"
});
return;
@ -78,7 +78,7 @@ function handleChangePassword(req, res) {
db.users.verifyLogin(name, oldpassword, function (err, user) {
if (err) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: err
});
return;
@ -86,7 +86,7 @@ function handleChangePassword(req, res) {
db.users.setPassword(name, newpassword, function (err, dbres) {
if (err) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: err
});
return;
@ -97,7 +97,7 @@ function handleChangePassword(req, res) {
db.users.getUser(name, function (err, user) {
if (err) {
return sendJade(res, "account-edit", {
return sendPug(res, "account-edit", {
errorMessage: err
});
}
@ -106,7 +106,7 @@ function handleChangePassword(req, res) {
var expiration = new Date(parseInt(req.signedCookies.auth.split(":")[1]));
session.genSession(user, expiration, function (err, auth) {
if (err) {
return sendJade(res, "account-edit", {
return sendPug(res, "account-edit", {
errorMessage: err
});
}
@ -126,7 +126,7 @@ function handleChangePassword(req, res) {
});
}
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
successMessage: "Password changed."
});
});
@ -151,7 +151,7 @@ function handleChangeEmail(req, res) {
}
if (!$util.isValidEmail(email) && email !== "") {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: "Invalid email address"
});
return;
@ -159,7 +159,7 @@ function handleChangeEmail(req, res) {
db.users.verifyLogin(name, password, function (err, user) {
if (err) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: err
});
return;
@ -167,7 +167,7 @@ function handleChangeEmail(req, res) {
db.users.setEmail(name, email, function (err, dbres) {
if (err) {
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
errorMessage: err
});
return;
@ -175,7 +175,7 @@ function handleChangeEmail(req, res) {
Logger.eventlog.log("[account] " + req.realIP +
" changed email for " + name +
" to " + email);
sendJade(res, "account-edit", {
sendPug(res, "account-edit", {
successMessage: "Email address changed."
});
});
@ -191,13 +191,13 @@ function handleAccountChannelPage(req, res) {
}
if (!req.user) {
return sendJade(res, "account-channels", {
return sendPug(res, "account-channels", {
channels: []
});
}
db.channels.listUserChannels(req.user.name, function (err, channels) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: channels
});
});
@ -235,14 +235,14 @@ function handleNewChannel(req, res) {
}
if (!req.user) {
return sendJade(res, "account-channels", {
return sendPug(res, "account-channels", {
channels: []
});
}
db.channels.listUserChannels(req.user.name, function (err, channels) {
if (err) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: [],
newChannelError: err
});
@ -250,7 +250,7 @@ function handleNewChannel(req, res) {
}
if (name.match(Config.get("reserved-names.channels"))) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: channels,
newChannelError: "That channel name is reserved"
});
@ -259,7 +259,7 @@ function handleNewChannel(req, res) {
if (channels.length >= Config.get("max-channels-per-user") &&
req.user.global_rank < 255) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: channels,
newChannelError: "You are not allowed to register more than " +
Config.get("max-channels-per-user") + " channels."
@ -290,7 +290,7 @@ function handleNewChannel(req, res) {
}
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: channels,
newChannelError: err ? err : undefined
});
@ -309,7 +309,7 @@ function handleDeleteChannel(req, res) {
}
if (!req.user) {
return sendJade(res, "account-channels", {
return sendPug(res, "account-channels", {
channels: [],
});
}
@ -317,7 +317,7 @@ function handleDeleteChannel(req, res) {
db.channels.lookup(name, function (err, channel) {
if (err) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: [],
deleteChannelError: err
});
@ -326,7 +326,7 @@ function handleDeleteChannel(req, res) {
if (channel.owner !== req.user.name && req.user.global_rank < 255) {
db.channels.listUserChannels(req.user.name, function (err2, channels) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: err2 ? [] : channels,
deleteChannelError: "You do not have permission to delete this channel"
});
@ -354,7 +354,7 @@ function handleDeleteChannel(req, res) {
}
}
db.channels.listUserChannels(req.user.name, function (err2, channels) {
sendJade(res, "account-channels", {
sendPug(res, "account-channels", {
channels: err2 ? [] : channels,
deleteChannelError: err ? err : undefined
});
@ -372,7 +372,7 @@ function handleAccountProfilePage(req, res) {
}
if (!req.user) {
return sendJade(res, "account-profile", {
return sendPug(res, "account-profile", {
profileImage: "",
profileText: ""
});
@ -380,7 +380,7 @@ function handleAccountProfilePage(req, res) {
db.users.getProfile(req.user.name, function (err, profile) {
if (err) {
sendJade(res, "account-profile", {
sendPug(res, "account-profile", {
profileError: err,
profileImage: "",
profileText: ""
@ -388,7 +388,7 @@ function handleAccountProfilePage(req, res) {
return;
}
sendJade(res, "account-profile", {
sendPug(res, "account-profile", {
profileImage: profile.image,
profileText: profile.text,
profileError: false
@ -403,7 +403,7 @@ function handleAccountProfile(req, res) {
csrf.verify(req);
if (!req.user) {
return sendJade(res, "account-profile", {
return sendPug(res, "account-profile", {
profileImage: "",
profileText: "",
profileError: "You must be logged in to edit your profile",
@ -415,7 +415,7 @@ function handleAccountProfile(req, res) {
db.users.setProfile(req.user.name, { image: image, text: text }, function (err) {
if (err) {
sendJade(res, "account-profile", {
sendPug(res, "account-profile", {
profileImage: "",
profileText: "",
profileError: err
@ -423,7 +423,7 @@ function handleAccountProfile(req, res) {
return;
}
sendJade(res, "account-profile", {
sendPug(res, "account-profile", {
profileImage: image,
profileText: text,
profileError: false
@ -439,7 +439,7 @@ function handlePasswordResetPage(req, res) {
return;
}
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: false
@ -461,7 +461,7 @@ function handlePasswordReset(req, res) {
}
if (!$util.isValidUserName(name)) {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: "Invalid username '" + name + "'"
@ -471,7 +471,7 @@ function handlePasswordReset(req, res) {
db.users.getEmail(name, function (err, actualEmail) {
if (err) {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: err
@ -480,14 +480,14 @@ function handlePasswordReset(req, res) {
}
if (actualEmail !== email.trim()) {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: "Provided email does not match the email address on record for " + name
});
return;
} else if (actualEmail === "") {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: name + " doesn't have an email address on record. Please contact an " +
@ -509,7 +509,7 @@ function handlePasswordReset(req, res) {
expire: expire
}, function (err, dbres) {
if (err) {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: "",
resetErr: err
@ -521,7 +521,7 @@ function handlePasswordReset(req, res) {
name + " <" + email + ">");
if (!Config.get("mail.enabled")) {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: email,
resetErr: "This server does not have mail support enabled. Please " +
@ -548,14 +548,14 @@ function handlePasswordReset(req, res) {
Config.get("mail.nodemailer").sendMail(mail, function (err, response) {
if (err) {
Logger.errlog.log("mail fail: " + err);
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: email,
resetErr: "Sending reset email failed. Please contact an " +
"administrator for assistance."
});
} else {
sendJade(res, "account-passwordreset", {
sendPug(res, "account-passwordreset", {
reset: true,
resetEmail: email,
resetErr: false
@ -580,7 +580,7 @@ function handlePasswordRecover(req, res) {
db.lookupPasswordReset(hash, function (err, row) {
if (err) {
sendJade(res, "account-passwordrecover", {
sendPug(res, "account-passwordrecover", {
recovered: false,
recoverErr: err
});
@ -588,7 +588,7 @@ function handlePasswordRecover(req, res) {
}
if (Date.now() >= row.expire) {
sendJade(res, "account-passwordrecover", {
sendPug(res, "account-passwordrecover", {
recovered: false,
recoverErr: "This password recovery link has expired. Password " +
"recovery links are valid only for 24 hours after " +
@ -604,7 +604,7 @@ function handlePasswordRecover(req, res) {
}
db.users.setPassword(row.name, newpw, function (err) {
if (err) {
sendJade(res, "account-passwordrecover", {
sendPug(res, "account-passwordrecover", {
recovered: false,
recoverErr: "Database error. Please contact an administrator if " +
"this persists."
@ -616,7 +616,7 @@ function handlePasswordRecover(req, res) {
db.deletePasswordReset(hash);
Logger.eventlog.log("[account] " + ip + " recovered password for " + row.name);
sendJade(res, "account-passwordrecover", {
sendPug(res, "account-passwordrecover", {
recovered: true,
recoverPw: newpw
});

View file

@ -1,7 +1,7 @@
var path = require("path");
var fs = require("fs");
var webserver = require("./webserver");
var sendJade = require("./jade").sendJade;
var sendPug = require("./pug").sendPug;
var Logger = require("../logger");
var db = require("../database");
var Config = require("../config");
@ -35,7 +35,7 @@ function handleAcp(req, res, user) {
}
sio += "/socket.io/socket.io.js";
sendJade(res, "acp", {
sendPug(res, "acp", {
sioSource: sio
});
}

View file

@ -4,11 +4,11 @@
* @author Calvin Montgomery <cyzon@cyzon.us>
*/
var jade = require("jade");
var pug = require("pug");
var path = require("path");
var webserver = require("./webserver");
var cookieall = webserver.cookieall;
var sendJade = require("./jade").sendJade;
var sendPug = require("./pug").sendPug;
var Logger = require("../logger");
var $util = require("../utilities");
var db = require("../database");
@ -56,7 +56,7 @@ function handleLogin(req, res) {
Logger.eventlog.log("[loginfail] Login failed (bad password): " + name
+ "@" + req.realIP);
}
sendJade(res, "login", {
sendPug(res, "login", {
loggedIn: false,
loginError: err
});
@ -65,7 +65,7 @@ function handleLogin(req, res) {
session.genSession(user, expiration, function (err, auth) {
if (err) {
sendJade(res, "login", {
sendPug(res, "login", {
loggedIn: false,
loginError: err
});
@ -93,7 +93,7 @@ function handleLogin(req, res) {
res.redirect(dest);
} else {
res.user = user;
sendJade(res, "login", {});
sendPug(res, "login", {});
}
});
});
@ -108,12 +108,12 @@ function handleLoginPage(req, res) {
}
if (req.user) {
return sendJade(res, "login", {
return sendPug(res, "login", {
wasAlreadyLoggedIn: true
});
}
sendJade(res, "login", {
sendPug(res, "login", {
redirect: req.query.dest || req.header("referer")
});
}
@ -138,7 +138,7 @@ function handleLogout(req, res) {
if (dest) {
res.redirect(dest);
} else {
sendJade(res, "logout", {});
sendPug(res, "logout", {});
}
}
@ -151,11 +151,11 @@ function handleRegisterPage(req, res) {
}
if (req.user) {
sendJade(res, "register", {});
sendPug(res, "register", {});
return;
}
sendJade(res, "register", {
sendPug(res, "register", {
registered: false,
registerError: false
});
@ -181,21 +181,21 @@ function handleRegister(req, res) {
}
if (name.length === 0) {
sendJade(res, "register", {
sendPug(res, "register", {
registerError: "Username must not be empty"
});
return;
}
if (name.match(Config.get("reserved-names.usernames"))) {
sendJade(res, "register", {
sendPug(res, "register", {
registerError: "That username is reserved"
});
return;
}
if (password.length === 0) {
sendJade(res, "register", {
sendPug(res, "register", {
registerError: "Password must not be empty"
});
return;
@ -204,7 +204,7 @@ function handleRegister(req, res) {
password = password.substring(0, 100);
if (email.length > 0 && !$util.isValidEmail(email)) {
sendJade(res, "register", {
sendPug(res, "register", {
registerError: "Invalid email address"
});
return;
@ -212,13 +212,13 @@ function handleRegister(req, res) {
db.users.register(name, password, email, ip, function (err) {
if (err) {
sendJade(res, "register", {
sendPug(res, "register", {
registerError: err
});
} else {
Logger.eventlog.log("[register] " + ip + " registered account: " + name +
(email.length > 0 ? " <" + email + ">" : ""));
sendJade(res, "register", {
sendPug(res, "register", {
registered: true,
registerName: name,
redirect: req.body.redirect

View file

@ -1,4 +1,4 @@
var jade = require("jade");
var pug = require("pug");
var fs = require("fs");
var path = require("path");
var Config = require("../config");
@ -6,7 +6,7 @@ var templates = path.join(__dirname, "..", "..", "templates");
var cache = {};
/**
* Merges locals with globals for jade rendering
* Merges locals with globals for pug rendering
*/
function merge(locals, res) {
var _locals = {
@ -33,14 +33,14 @@ function getBaseUrl(res) {
}
/**
* Renders and serves a jade template
* Renders and serves a pug template
*/
function sendJade(res, view, locals) {
function sendPug(res, view, locals) {
locals.loggedIn = locals.loggedIn || !!res.user;
locals.loginName = locals.loginName || res.user ? res.user.name : false;
if (!(view in cache) || Config.get("debug")) {
var file = path.join(templates, view + ".jade");
var fn = jade.compile(fs.readFileSync(file), {
var file = path.join(templates, view + ".pug");
var fn = pug.compile(fs.readFileSync(file), {
filename: file,
pretty: !Config.get("http.minify")
});
@ -51,5 +51,5 @@ function sendJade(res, view, locals) {
}
module.exports = {
sendJade: sendJade
sendPug: sendPug
};

View file

@ -1,6 +1,6 @@
import CyTubeUtil from '../../utilities';
import { sanitizeText } from '../../xss';
import { sendJade } from '../jade';
import { sendPug } from '../pug';
import * as HTTPStatus from '../httpstatus';
import { HTTPError } from '../../errors';
@ -17,7 +17,7 @@ export default function initialize(app, ioConfig) {
}
const socketBaseURL = endpoints[0].url;
sendJade(res, 'channel', {
sendPug(res, 'channel', {
channelName: req.params.channel,
sioSource: `${socketBaseURL}/socket.io/socket.io.js`
});

View file

@ -1,5 +1,5 @@
import CyTubeUtil from '../../utilities';
import { sendJade } from '../jade';
import { sendPug } from '../pug';
export default function initialize(app, webConfig) {
app.get('/contact', (req, res) => {
@ -19,7 +19,7 @@ export default function initialize(app, webConfig) {
return contact;
});
return sendJade(res, 'contact', {
return sendPug(res, 'contact', {
contacts: contacts
});
});

View file

@ -1,4 +1,4 @@
import { sendJade } from '../jade';
import { sendPug } from '../pug';
export default function initialize(app, channelIndex, maxEntries) {
app.get('/', (req, res) => {
@ -13,7 +13,7 @@ export default function initialize(app, channelIndex, maxEntries) {
channels = channels.slice(0, maxEntries);
sendJade(res, 'index', {
sendPug(res, 'index', {
channels: channels
});
});

View file

@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import net from 'net';
import express from 'express';
import { sendJade } from './jade';
import { sendPug } from './pug';
import Logger from '../logger';
import Config from '../config';
import bodyParser from 'body-parser';
@ -76,7 +76,7 @@ function handleLegacySocketConfig(req, res) {
}
function handleUserAgreement(req, res) {
sendJade(res, 'tos', {
sendPug(res, 'tos', {
domain: Config.get('http.domain')
});
}
@ -92,7 +92,7 @@ function initializeErrorHandlers(app) {
if (err) {
if (err instanceof CSRFError) {
res.status(HTTPStatus.FORBIDDEN);
return sendJade(res, 'csrferror', {
return sendPug(res, 'csrferror', {
path: req.path,
referer: req.header('referer')
});
@ -104,7 +104,7 @@ function initializeErrorHandlers(app) {
}
if (!message) {
message = 'An unknown error occurred.';
} else if (/\.(jade|js)/.test(message)) {
} else if (/\.(pug|js)/.test(message)) {
// Prevent leakage of stack traces
message = 'An internal error occurred.';
}
@ -115,7 +115,7 @@ function initializeErrorHandlers(app) {
}
res.status(status);
return sendJade(res, 'httperror', {
return sendPug(res, 'httperror', {
path: req.path,
status: status,
message: message