mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-13 07:19:37 +00:00
format everythink
This commit is contained in:
parent
754806a52b
commit
8890fa7bbf
@ -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
|
||||
14
index.js
14
index.js
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user