mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-13 07:19:37 +00:00
commit
e1713d69f1
36
README.md
36
README.md
@ -2,3 +2,39 @@
|
||||
# JSTE
|
||||
|
||||
JSTE is a NodeJS-Module for rendering data in static HTML
|
||||
|
||||
|
||||
## Example Page (JSON)
|
||||
|
||||
```json
|
||||
{
|
||||
"_TEMPLATE_":"firstexample",
|
||||
"TITLE": "app2",
|
||||
"LINK":"http://www.google.de"
|
||||
}
|
||||
```
|
||||
|
||||
## Example Template (HTML)
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><[TITLE]></title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app">
|
||||
<a id="googlelink"><[LINK]></a>
|
||||
</div>
|
||||
<[[ARRAY]]>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
```
|
||||
|
||||
## special constants:
|
||||
- ```_TEMPLATE_``` -> Defines the path to the temp file
|
||||
26
index.js
26
index.js
@ -1,21 +1,15 @@
|
||||
|
||||
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.getTemplateNameFromPage = function(pageName)
|
||||
{
|
||||
return app.pages.get(pageName)["_TEMPLATE_"]
|
||||
}
|
||||
|
||||
app.render = engine.render(pagecode, templatecode);
|
||||
|
||||
// app.getTemplateNameFromPage = function(pageName)
|
||||
// {
|
||||
// return app.pages.get(pageName)["_TEMPLATE_"]
|
||||
// }
|
||||
|
||||
module.exports = app;
|
||||
|
||||
|
||||
@ -1,29 +1,37 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
var appdir = path.join(__dirname, '..');
|
||||
var app = {}
|
||||
var appdir = path.join(__dirname, "..");
|
||||
var app = {};
|
||||
|
||||
app.render = function(pagecode, templatecode) {
|
||||
result = "";
|
||||
|
||||
pagecode = JSON.parse(pagecode);
|
||||
|
||||
//TODO
|
||||
//if(templatecode === null)
|
||||
|
||||
|
||||
for (var i in pagecode) {
|
||||
var value = undefined;
|
||||
|
||||
if(i.startsWith("_"))
|
||||
continue;
|
||||
|
||||
value = pagecode[i].toString();
|
||||
templatecode = templatecode.replace("<["+i+"]>",value)
|
||||
}
|
||||
|
||||
return templatecode;
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
function replaceAll(str, find, replace) {
|
||||
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
|
||||
}
|
||||
|
||||
module.exports = app;
|
||||
app.render = function (pagecode, templatecode) {
|
||||
result = "";
|
||||
|
||||
if (!pagecode == JSON) pagecode = JSON.parse(pagecode);
|
||||
|
||||
//TODO
|
||||
if (templatecode === null || templatecode == undefined) {
|
||||
templatecode == fs.readFileSync(pagecode["_TEMPLATE_"] + ".html");
|
||||
}
|
||||
|
||||
for (var i in pagecode) {
|
||||
var value = undefined;
|
||||
|
||||
var re = new RegExp(/\d*_([A-Z])\w*_/g);
|
||||
if (re.test(i)) continue;
|
||||
|
||||
value = pagecode[i].toString();
|
||||
templatecode = replaceAll(templatecode, "<[" + i + "]>", value);
|
||||
}
|
||||
|
||||
return templatecode.replace(new RegExp(/\d*<\[([A-Z])\w*\]>/g), "");
|
||||
};
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user