first working commit

This commit is contained in:
lucaspalomodevelop 2022-10-28 16:40:12 +02:00
parent 5d246946cb
commit 9b9549a35b
24 changed files with 1329 additions and 0 deletions

58
examples/example1.js Normal file
View File

@ -0,0 +1,58 @@
let express = require("express");
let app = express();
let jsste = require("jsste");
const bodyParser = require("body-parser");
let path = require("path");
let fs = require("fs");
var decode = require("urldecode");
jsste.__config.set("templatePath", __dirname + "/templates");
jsste.__config.set("pagePath", __dirname + "/pages");
jsste.__config.set("assetsPath", "./assets");
jsste.__config.set("stylesheets", "./styles");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
let folders = {
jsste: "pages",
css: "styles",
};
function getFolderFromFileEnding(filename) {
let regex_isAnDotfile = /\w+\.[a-z]*[A-Z]*/;
if (regex_isAnDotfile.test(filename)) {
let ending = filename.split(".").pop();
return folders[ending];
}
return folders.jsste;
}
function defaultUse(req, res, next) {
let regex_isAnDotfile = /\w+\.[a-z]*[A-Z]*/;
let filePath = path.join(
__dirname.toString(),
getFolderFromFileEnding(req.url).toString(),
req.url.toString()
);
if (regex_isAnDotfile.test(req.url) && !filePath.endsWith(".jsste")) {
res.sendFile(filePath);
} else if (fs.existsSync(filePath + ".jsste")) {
let content = jsste.renderFile(filePath + ".jsste");
res.send(content);
} else if (fs.lstatSync(filePath).isDirectory()) {
let content = jsste.renderFile(decode(path.join(filePath, "index.jsste")));
res.send(content);
} else next();
}
app.get("/assets/*", (req, res) => {
console.log(req.url);
console.log(__dirname);
res.sendFile(decode(path.join(__dirname, req.url)));
});
app.get("/*", defaultUse);
app.listen(8000, function () {
console.log("Example app listening on port http://127.0.0.1:8000 !");
});

View File

@ -0,0 +1,3 @@
{
"b":"hallo"
}

View File

@ -0,0 +1,5 @@
{
"_IMPORTS_":["data.jsste","lib/base.jsste"],
"a":"h1 - test",
"c":"p - test"
}

View File

@ -0,0 +1,5 @@
{
"_TEMPLATE_":"startpage"
}

View File

@ -0,0 +1,6 @@
{
"_STYLES_":["base"],
"js$Date": "return Date.now() + ' is the TimeStemp';",
"js$uxTime":"Date.Now();",
"js$TimeStemp":"const heute = new Date(); return heute"
}

View File

@ -0,0 +1,5 @@
{
"_IMPORTS_":["data2.jsste"],
"_TEMPLATE_":"page1",
"root":"root"
}

View File

@ -0,0 +1,13 @@
{
"_STYLES_":["base"],
"_TEMPLATE_":"page1",
"_TITLE_":"Page2.2",
"root":"root",
"a":"h1 - test",
"c":"p - test",
"b":"hallo",
"js$Date": "return Date.now() + ' is the TimeStemp';",
"pic$bild":"",
"//":"ich bin ein kommentar",
"//":"ich bin auch ein Kommentar"
}

View File

@ -0,0 +1,5 @@
{
"_TEMPLATE_":"page3",
"Title":"Page3",
"_IMPORTS_":["lib/base.jsste","./mybase.jsste"]
}

View File

@ -0,0 +1,3 @@
{
"js$Date": "return Date.now();"
}

View File

@ -0,0 +1,4 @@
{
"a":"Ameise",
"_IMPORTS_":["./c.jsste","./b.jsste"]
}

View File

@ -0,0 +1,4 @@
{
"b":"braunbär",
"_IMPORTS_":["./d.jsste","./e.jsste"]
}

View File

@ -0,0 +1,4 @@
{
"c":"cobra",
"_IMPORTS_":["./f.jsste","./g.jsste"]
}

View File

@ -0,0 +1,3 @@
{
"d":"delfin"
}

View File

@ -0,0 +1,3 @@
{
"e":"esel"
}

View File

@ -0,0 +1,3 @@
{
"f":"fau"
}

View File

@ -0,0 +1,3 @@
{
"g":"giraffe"
}

View File

@ -0,0 +1,4 @@
{
"_TEMPLATE_": "example",
"_IMPORTS_":["./a.jsste","lib/base.jsste"]
}

3
examples/styles/base.css Normal file
View File

@ -0,0 +1,3 @@
* {
color: green;
}

View File

@ -0,0 +1,36 @@
<html>
<head>
<title>Template Example</title>
</head>
<body>
<ul>
<li>
<p>timestemp: <[js$Date]></p>
</li>
<li>
<p>path: <[_SELFPATH_]></p>
</li>
<li>
<p>a: <[a]></p>
</li>
<li>
<p>b: <[b]></p>
</li>
<li>
<p>c: <[c]></p>
</li>
<li>
<p>d: <[d]></p>
</li>
<li>
<p>e: <[e]></p>
</li>
<li>
<p>f: <[f]></p>
</li>
<li>
<p>g: <[g]></p>
</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,23 @@
<!--example html-->
<!--<[:startpage:]>-->
<html>
<head>
<title>Template Example</title>
</head>
<body>
<h1><[a]></h1>
<p><[c]></p>
<p><[b]></p>
<p><[js$Date]></p>
<p><[js$TimeStemp]></p>
<p> root: <[root]></p>
<p><[Base_Date]></p>
<p>Kommentar: <[//]></p>
<script>
let c = "<[c]>";
console.log(c);
</script>
</body>
</html>

View File

@ -0,0 +1,9 @@
<html>
<head>
<title><[Title]></title>
</head>
<body>
<[js$Date]>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
StartSeite
</body>
</html>

1086
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

29
package.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "jsste-examples",
"version": "1.0.0",
"description": "",
"main": "examples\\example1.js",
"directories": {
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node examples/example1.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lucaspalomodevelop/JSSTE-examples.git"
},
"author": "Lucas Palomo Lauterbach",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/lucaspalomodevelop/JSSTE-examples/issues"
},
"homepage": "https://github.com/lucaspalomodevelop/JSSTE-examples#readme",
"dependencies": {
"body-parser": "^1.20.1",
"express": "^4.18.2",
"jsste": "^1.2.0",
"urldecode": "^1.0.1"
}
}