mirror of
https://github.com/lucaspalomodevelop/JSSTE-examples.git
synced 2026-03-13 00:07:22 +00:00
first working commit
This commit is contained in:
parent
5d246946cb
commit
9b9549a35b
58
examples/example1.js
Normal file
58
examples/example1.js
Normal 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 !");
|
||||
});
|
||||
3
examples/pages/data.jsste
Normal file
3
examples/pages/data.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"b":"hallo"
|
||||
}
|
||||
5
examples/pages/data2.jsste
Normal file
5
examples/pages/data2.jsste
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"_IMPORTS_":["data.jsste","lib/base.jsste"],
|
||||
"a":"h1 - test",
|
||||
"c":"p - test"
|
||||
}
|
||||
5
examples/pages/index.jsste
Normal file
5
examples/pages/index.jsste
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
{
|
||||
"_TEMPLATE_":"startpage"
|
||||
}
|
||||
|
||||
6
examples/pages/lib/base.jsste
Normal file
6
examples/pages/lib/base.jsste
Normal 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"
|
||||
}
|
||||
5
examples/pages/page1.jsste
Normal file
5
examples/pages/page1.jsste
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"_IMPORTS_":["data2.jsste"],
|
||||
"_TEMPLATE_":"page1",
|
||||
"root":"root"
|
||||
}
|
||||
13
examples/pages/page2.jsste
Normal file
13
examples/pages/page2.jsste
Normal 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"
|
||||
}
|
||||
5
examples/pages/page3/index.jsste
Normal file
5
examples/pages/page3/index.jsste
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"_TEMPLATE_":"page3",
|
||||
"Title":"Page3",
|
||||
"_IMPORTS_":["lib/base.jsste","./mybase.jsste"]
|
||||
}
|
||||
3
examples/pages/page3/mybase.jsste
Normal file
3
examples/pages/page3/mybase.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"js$Date": "return Date.now();"
|
||||
}
|
||||
4
examples/pages/test/a.jsste
Normal file
4
examples/pages/test/a.jsste
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"a":"Ameise",
|
||||
"_IMPORTS_":["./c.jsste","./b.jsste"]
|
||||
}
|
||||
4
examples/pages/test/b.jsste
Normal file
4
examples/pages/test/b.jsste
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"b":"braunbär",
|
||||
"_IMPORTS_":["./d.jsste","./e.jsste"]
|
||||
}
|
||||
4
examples/pages/test/c.jsste
Normal file
4
examples/pages/test/c.jsste
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"c":"cobra",
|
||||
"_IMPORTS_":["./f.jsste","./g.jsste"]
|
||||
}
|
||||
3
examples/pages/test/d.jsste
Normal file
3
examples/pages/test/d.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"d":"delfin"
|
||||
}
|
||||
3
examples/pages/test/e.jsste
Normal file
3
examples/pages/test/e.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"e":"esel"
|
||||
}
|
||||
3
examples/pages/test/f.jsste
Normal file
3
examples/pages/test/f.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"f":"fau"
|
||||
}
|
||||
3
examples/pages/test/g.jsste
Normal file
3
examples/pages/test/g.jsste
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"g":"giraffe"
|
||||
}
|
||||
4
examples/pages/test/index.jsste
Normal file
4
examples/pages/test/index.jsste
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"_TEMPLATE_": "example",
|
||||
"_IMPORTS_":["./a.jsste","lib/base.jsste"]
|
||||
}
|
||||
3
examples/styles/base.css
Normal file
3
examples/styles/base.css
Normal file
@ -0,0 +1,3 @@
|
||||
* {
|
||||
color: green;
|
||||
}
|
||||
36
examples/templates/example.tjsste
Normal file
36
examples/templates/example.tjsste
Normal 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>
|
||||
23
examples/templates/page1.tjsste
Normal file
23
examples/templates/page1.tjsste
Normal 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>
|
||||
9
examples/templates/page3.tjsste
Normal file
9
examples/templates/page3.tjsste
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title><[Title]></title>
|
||||
</head>
|
||||
<body>
|
||||
<[js$Date]>
|
||||
</body>
|
||||
</html>
|
||||
12
examples/templates/startpage.tjsste
Normal file
12
examples/templates/startpage.tjsste
Normal 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
1086
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
package.json
Normal file
29
package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user