format everythink

This commit is contained in:
lucaspalomodevelop 2021-04-30 08:26:06 +02:00
parent 754806a52b
commit 8890fa7bbf
3 changed files with 27 additions and 36 deletions

View File

@ -37,4 +37,4 @@ JSTE is a NodeJS-Module for rendering data in static HTML
```
## special constants:
- ```_TEMPLATE_``` -> Defines the path to the temp file
- ```_TEMPLATE_``` -> Defines the path to the temp file

View File

@ -1,14 +1,11 @@
var engine = require("./src/modules/engine")
var engine = require("./src/modules/engine");
var app = {};
app.config = {
templatePath: __dirname + "\\src\\templates",
pagePath: __dirname + "\\src\\pages",
};
"templatePath":__dirname+"\\src\\templates",
"pagePath":__dirname+"\\src\\pages"
};
app.render = engine.render(pagecode,templatecode);
app.render = engine.render(pagecode, templatecode);
// app.getTemplateNameFromPage = function(pageName)
// {
@ -16,4 +13,3 @@ app.render = engine.render(pagecode,templatecode);
// }
module.exports = app;

View File

@ -1,42 +1,37 @@
const fs = require("fs");
const path = require("path");
var appdir = path.join(__dirname, '..');
var app = {}
var appdir = path.join(__dirname, "..");
var app = {};
function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
}
app.render = function(pagecode, templatecode) {
result = "";
app.render = function (pagecode, templatecode) {
result = "";
if(!pagecode == JSON)
pagecode = JSON.parse(pagecode);
if (!pagecode == JSON) pagecode = JSON.parse(pagecode);
//TODO
if(templatecode === null || templatecode == undefined)
{
templatecode == fs.readFileSync(pagecode["_TEMPLATE_"]+".html");
}
//TODO
if (templatecode === null || templatecode == undefined) {
templatecode == fs.readFileSync(pagecode["_TEMPLATE_"] + ".html");
}
for (var i in pagecode) {
var value = undefined;
for (var i in pagecode) {
var value = undefined;
var re = new RegExp(/\d*_([A-Z])\w*_/g);
if (re.test(i)) continue;
var re = new RegExp(/\d*_([A-Z])\w*_/g);
if(re.test(i))
continue;
value = pagecode[i].toString();
templatecode = replaceAll(templatecode, "<[" + i + "]>", value);
}
value = pagecode[i].toString();
templatecode = replaceAll(templatecode,"<["+i+"]>",value);
}
return templatecode.replace(new RegExp(/\d*<\[([A-Z])\w*\]>/g), "");
};
return templatecode.replace(new RegExp(/\d*<\[([A-Z])\w*\]>/g),"");;
}
module.exports = app;
module.exports = app;