diff --git a/README.md b/README.md
index 4ae3875..f1e4f84 100644
--- a/README.md
+++ b/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
+
+
+
+
+
+
+ <[TITLE]>
+
+
+
+
+ <[[ARRAY]]>
+
+
+
+```
+
+## special constants:
+- ```_TEMPLATE_``` -> Defines the path to the temp file
\ No newline at end of file
diff --git a/index.js b/index.js
index 9126d9b..fe53f3c 100644
--- a/index.js
+++ b/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;
-
diff --git a/src/modules/engine.js b/src/modules/engine.js
index 8916ffe..03a6442 100644
--- a/src/modules/engine.js
+++ b/src/modules/engine.js
@@ -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;
\ No newline at end of file
+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;