switch to pug
This commit is contained in:
parent
040895a036
commit
fd80d5b0a9
|
@ -1,4 +1,4 @@
|
||||||
const Eta = require('eta');
|
const pug = require('pug');
|
||||||
const fs = require('fs/promises');
|
const fs = require('fs/promises');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
|
@ -7,28 +7,24 @@ const layoutdir = cwd + '/view';
|
||||||
|
|
||||||
let compiled = {};
|
let compiled = {};
|
||||||
|
|
||||||
|
|
||||||
async function loadFile(file) {
|
async function loadFile(file) {
|
||||||
if (compiled[file]) return compiled[file];
|
if (compiled[file]) return compiled[file];
|
||||||
compiled[file] = Eta.compile(await fs.readFile(file, 'utf8'));
|
compiled[file] = await pug.compileFile(file);
|
||||||
|
|
||||||
return compiled[file];
|
return compiled[file];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function load(name, data) {
|
||||||
|
return (await loadFile(layoutdir + '/' + name))(data);
|
||||||
|
}
|
||||||
|
|
||||||
async function preload() {
|
async function preload() {
|
||||||
glob(layoutdir + '/*.eta', (err, files) => {
|
await glob(layoutdir + '/**/*', (err, files) => {
|
||||||
files.filter(file => {return !file.startsWith('.');})
|
files.filter(file => {
|
||||||
.forEach(file => {
|
return !file.startsWith('.');
|
||||||
loadFile(file);
|
}).forEach(file => {
|
||||||
});
|
loadFile(file);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function load(name, data) {
|
|
||||||
return (await loadFile(cwd + '/view/' + name))(data, Eta.config);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = { load, loadFile, preload }
|
module.exports = { load, loadFile, preload }
|
|
@ -13,9 +13,9 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"eta": "^2.0.0",
|
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"glob": "^8.1.0"
|
"glob": "^8.1.0",
|
||||||
|
"pug": "^3.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "^4.0.2"
|
"gulp": "^4.0.2"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Helpers = require('../helpers');
|
const Helpers = require('../helpers');
|
||||||
|
|
||||||
async function handler(req, res) {
|
async function handler(req, res) {
|
||||||
res.send(await Helpers.ViewLoader.load('welcome.eta'));
|
res.send(await Helpers.ViewLoader.load('hi.pug'));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (router) => {
|
module.exports = (router) => {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
p hi
|
|
@ -1,2 +0,0 @@
|
||||||
hi<br/>
|
|
||||||
<%~ Date.now() %>
|
|
Loading…
Reference in New Issue