mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-13 23:24:35 +00:00
Compare commits
No commits in common. "main" and "1.2.0" have entirely different histories.
37
.github/workflows/npm-publish.yml
vendored
37
.github/workflows/npm-publish.yml
vendored
@ -1,37 +0,0 @@
|
|||||||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
||||||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
||||||
|
|
||||||
name: Node.js Package
|
|
||||||
|
|
||||||
on:
|
|
||||||
# push:
|
|
||||||
# tags:
|
|
||||||
# - "*"
|
|
||||||
release:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- run: npm ci
|
|
||||||
- run: npm install
|
|
||||||
- run: npm test
|
|
||||||
|
|
||||||
publish-npm:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
registry-url: https://registry.npmjs.org/
|
|
||||||
- run: npm ci
|
|
||||||
- run: npm publish
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
testfiles
|
|
||||||
planning
|
planning
|
||||||
.vscode
|
.vscode
|
||||||
built
|
built
|
||||||
|
|||||||
54
README.md
54
README.md
@ -72,58 +72,6 @@ let result = Jsste.render(pagecode, templatecode);
|
|||||||
- `_TEMPLATE_` -> Defines the path to the temp file
|
- `_TEMPLATE_` -> Defines the path to the temp file
|
||||||
- `_STYLES_` -> Defines a list of CSS files that will be implemented
|
- `_STYLES_` -> Defines a list of CSS files that will be implemented
|
||||||
|
|
||||||
### Include States
|
|
||||||
|
|
||||||
You can include an Callbackfunction that will be called when the state is change
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
jsste.setStateFunction(({ status, statusMSG }) => {
|
|
||||||
yourstatus = status;
|
|
||||||
yourstatusMSG = statusMSG;
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### States-Codes
|
|
||||||
|
|
||||||
| Code | Meaning |
|
|
||||||
| :--- | :-----: |
|
|
||||||
| 0 | OK |
|
|
||||||
| 1 | ERROR |
|
|
||||||
| 2 | WARNING |
|
|
||||||
| 3 | INFO |
|
|
||||||
| 4 | DEBUG |
|
|
||||||
|
|
||||||
## Commandline
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install jsste -g
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
```sh
|
|
||||||
yarn install jsste -g
|
|
||||||
```
|
|
||||||
|
|
||||||
## excuting
|
|
||||||
|
|
||||||
```sh
|
|
||||||
jsste <argument>
|
|
||||||
```
|
|
||||||
|
|
||||||
| arguemnt | description | Example |
|
|
||||||
| :--------- | :--------------------------------------: | :-----: |
|
|
||||||
| -log | show jsste log | |
|
|
||||||
| -Jsconfig= | set jsste config as json | |
|
|
||||||
| -pageFile= | set pageFile path | |
|
|
||||||
| -page= | set pageFile as json | |
|
|
||||||
| -tempFile= | set tempFile path | |
|
|
||||||
| -temp= | set pageFile as code | |
|
|
||||||
| -info | show jsste.info | |
|
|
||||||
| -out | write rendered code into the commandling | |
|
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@ -157,5 +105,3 @@ let result = Jsste.render(pagecode, templatecode);
|
|||||||
// </html>
|
// </html>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Examples on [https://github.com/lucaspalomodevelop/JSSTE-Examples](https://github.com/lucaspalomodevelop/JSSTE-Examples)
|
|
||||||
|
|||||||
9889
package-lock.json
generated
9889
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@ -1,14 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "jsste",
|
"name": "jsste",
|
||||||
"version": "1.3.3",
|
"version": "1.1.3",
|
||||||
"description": "A Javascript Static Template Engine",
|
"description": "A Javascript Static Template Emgine",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"bin": {
|
|
||||||
"jsste": "./src/cli.js"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"package.json",
|
"package.json",
|
||||||
@ -18,7 +15,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha ./test/test.test.js",
|
"test": "mocha ./test/test.test.js",
|
||||||
"publish": "npm publish --access publish",
|
"publish": "npm publish --access publish",
|
||||||
"cmd": "node ./src/cli.js"
|
"compile": "tsc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -26,21 +23,30 @@
|
|||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"engine",
|
"engine",
|
||||||
"templateengine",
|
"templateengine"
|
||||||
"jsste"
|
|
||||||
],
|
],
|
||||||
"author": "Lucas Palomo Lauterbach",
|
"author": "lucas palomo",
|
||||||
"license": "GPL",
|
"license": "GPL",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/lucaspalomodevelop/JSSTE/issues"
|
"url": "https://github.com/lucaspalomodevelop/JSSTE/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/lucaspalomodevelop/JSSTE#readme",
|
"homepage": "https://github.com/lucaspalomodevelop/JSSTE#readme",
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"typechecker": "^7.18.0",
|
||||||
|
"yarn": "^1.22.19"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.10.0"
|
"node": ">= 0.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"assert": "^2.0.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"mocha": "^10.1.0"
|
"express": "^4.17.1",
|
||||||
|
"gulp": "^4.0.2",
|
||||||
|
"gulp-minify": "^3.1.0",
|
||||||
|
"gulp-typescript": "^6.0.0-alpha.1",
|
||||||
|
"mocha": "^8.4.0",
|
||||||
|
"typescript": "^4.5.4",
|
||||||
|
"urldecode": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
99
src/cli.js
99
src/cli.js
@ -1,99 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
let jsste = require("./index");
|
|
||||||
let myargs = process.argv.slice(2);
|
|
||||||
let output = "";
|
|
||||||
let pagefile, tempfile;
|
|
||||||
let path = require("path");
|
|
||||||
let fs = require("fs");
|
|
||||||
|
|
||||||
var currentPath = process.cwd();
|
|
||||||
|
|
||||||
jsste.__config.set("templatePath",currentPath)
|
|
||||||
jsste.__config.set("pagePath",currentPath)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this function filters the prefix and call the callback with the param
|
|
||||||
* @param {prefix, args } settings
|
|
||||||
* @param {*} callback
|
|
||||||
*/
|
|
||||||
let addCommand = ({ prefix, args = myargs }, callback) => {
|
|
||||||
myargs.forEach((elem) => {
|
|
||||||
if (elem.startsWith(prefix)) {
|
|
||||||
elem = elem.replace(prefix, "");
|
|
||||||
callback(elem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -log | show jsste log
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-log" }, (arg) => {
|
|
||||||
jsste.setStateFunction((state) => {
|
|
||||||
console.log(state);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -Jsconfig | set jsste config as json
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-Jsconfig=" }, (arg) => {
|
|
||||||
jsste.__config.setConfig(arg);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -pageFile | set pageFile path
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-pageFile=" }, (arg) => {
|
|
||||||
jsste.setState({ status: 4, statusMSG: currentPath })
|
|
||||||
pagefile = JSON.parse(fs.readFileSync(path.join(currentPath, arg), "utf8"));
|
|
||||||
|
|
||||||
pagefile["_SELFPATH_"] = path.dirname(arg);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -pageFile | set pageFile as json
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-page=" }, (arg) => {
|
|
||||||
pagefile = JSON.parse(arg);
|
|
||||||
pagefile["_SELFPATH_"] = path.dirname(arg);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -tempFile | set tempFile path
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-tempFile=" }, (arg) => {
|
|
||||||
tempfile = fs.readFileSync(arg, "utf8");
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -pageFile | set pageFile as code
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-temp=" }, (arg) => {
|
|
||||||
tempfile = arg;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* rendering
|
|
||||||
*/
|
|
||||||
output = jsste.render(pagefile || undefined, tempfile || undefined);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -info | show jsste.info
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-info" }, (arg) => {
|
|
||||||
if (arg == "?json") {
|
|
||||||
console.log(JSON.stringify(jsste.info));
|
|
||||||
} else {
|
|
||||||
Object.keys(jsste.info).forEach((key) => {
|
|
||||||
console.log(key + " : " + jsste.info[key]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -out | write rendered code into the commandling
|
|
||||||
*/
|
|
||||||
addCommand({ prefix: "-out" }, (arg) => {
|
|
||||||
console.log(output);
|
|
||||||
});
|
|
||||||
@ -6,27 +6,14 @@ let configvar = {
|
|||||||
stylesheets: __dirname + "\\src\\styles",
|
stylesheets: __dirname + "\\src\\styles",
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* get config var by key
|
|
||||||
* @param {*} key
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
config.get = function (key) {
|
config.get = function (key) {
|
||||||
return configvar[key];
|
return configvar[key];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* get full config
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
config.getConfig = function () {
|
config.getConfig = function () {
|
||||||
return configvar;
|
return configvar;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* set full config
|
|
||||||
* @param {*} param0
|
|
||||||
*/
|
|
||||||
config.setConfig = function ({
|
config.setConfig = function ({
|
||||||
templatePath,
|
templatePath,
|
||||||
pagePath,
|
pagePath,
|
||||||
@ -39,11 +26,6 @@ config.setConfig = function ({
|
|||||||
configvar.stylesheets = stylesheets;
|
configvar.stylesheets = stylesheets;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* set config via key
|
|
||||||
* @param {*} key
|
|
||||||
* @param {*} value
|
|
||||||
*/
|
|
||||||
config.set = function (key, value) {
|
config.set = function (key, value) {
|
||||||
configvar[key] = value;
|
configvar[key] = value;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,38 +1,22 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const checker = require("typechecker");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const jsonmerger = require("./jsonMerger");
|
const jsonmerger = require("./jsonMerger");
|
||||||
|
//let appdir = path.join(__dirname, "..");
|
||||||
let app = {};
|
let app = {};
|
||||||
|
|
||||||
app.__config = require("./config");
|
app.__config = require("./config");
|
||||||
app.config = app.__config.getConfig();
|
app.config = app.__config.getConfig();
|
||||||
|
|
||||||
/**
|
//function to escape regex
|
||||||
* function to escape regex
|
|
||||||
* @param {*} string
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string) {
|
||||||
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* replace all placeholder in a string
|
|
||||||
* @param {*} str
|
|
||||||
* @param {*} find
|
|
||||||
* @param {*} replace
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function replaceAll(str, find, replace) {
|
function replaceAll(str, find, replace) {
|
||||||
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
|
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* function to handle consts
|
|
||||||
* @param {*} pagecode
|
|
||||||
* @param {*} constant
|
|
||||||
* @param {*} callback
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
app.CONST = function (pagecode, constant, callback) {
|
app.CONST = function (pagecode, constant, callback) {
|
||||||
if (pagecode[constant] !== undefined) {
|
if (pagecode[constant] !== undefined) {
|
||||||
callback(pagecode, pagecode[constant]);
|
callback(pagecode, pagecode[constant]);
|
||||||
@ -41,55 +25,30 @@ app.CONST = function (pagecode, constant, callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* renders Pagecode in Templatecode
|
|
||||||
* @param {*} pagecode
|
|
||||||
* @param {*} templatecode
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
app.render = function (pagecode, templatecode) {
|
app.render = function (pagecode, templatecode) {
|
||||||
app.setState({ status: 0, statusMSG: "Render Page" });
|
//let result = "";
|
||||||
|
|
||||||
|
//if (!pagecode == JSON) pagecode = JSON.parse(pagecode);
|
||||||
if (
|
if (
|
||||||
(pagecode != null || pagecode != undefined) &&
|
(pagecode != null || pagecode != undefined) &&
|
||||||
typeof pagecode === "string"
|
checker.isString(pagecode)
|
||||||
) {
|
) {
|
||||||
pagecode = JSON.parse(pagecode);
|
pagecode = JSON.parse(pagecode);
|
||||||
app.setState({ status: 0, statusMSG: "Parse Pagecode" });
|
|
||||||
} else {
|
|
||||||
if (typeof pagecode === "object") {
|
|
||||||
app.setState({ status: 0, statusMSG: "Pagecode is an object" });
|
|
||||||
} else {
|
|
||||||
app.setState({ status: 1, statusMSG: "Pagecode is undefined" });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO
|
||||||
if (!templatecode) {
|
if (!templatecode) {
|
||||||
try {
|
try {
|
||||||
app.setState({ status: 0, statusMSG: "Load Templatecode" });
|
|
||||||
app.setState({
|
|
||||||
status: 4,
|
|
||||||
statusMSG: path.join(
|
|
||||||
app.config.templatePath,
|
|
||||||
pagecode["_TEMPLATE_"] + ".tjsste"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
templatecode = fs.readFileSync(
|
templatecode = fs.readFileSync(
|
||||||
path.join(app.config.templatePath, pagecode["_TEMPLATE_"] + ".tjsste"),
|
path.join(app.config.templatePath, pagecode["_TEMPLATE_"] + ".tjsste"),
|
||||||
"utf-8"
|
"utf-8"
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
app.setState({ status: 1, statusMSG: "Cant load Templatecode" });
|
|
||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Dissolve Fileimports
|
|
||||||
* @param {*} _pagecode
|
|
||||||
* @param {*} imports
|
|
||||||
*/
|
|
||||||
let DissolveImports = function (_pagecode, imports) {
|
let DissolveImports = function (_pagecode, imports) {
|
||||||
app.setState({ status: 0, statusMSG: "Dissolve Imports" });
|
|
||||||
let ImportSet = new Set();
|
let ImportSet = new Set();
|
||||||
|
|
||||||
let recursive = function (importNames) {
|
let recursive = function (importNames) {
|
||||||
@ -98,10 +57,11 @@ app.render = function (pagecode, templatecode) {
|
|||||||
let importPath = importName.startsWith(".")
|
let importPath = importName.startsWith(".")
|
||||||
? path.join(_pagecode["_SELFPATH_"].toString(), importName.toString())
|
? path.join(_pagecode["_SELFPATH_"].toString(), importName.toString())
|
||||||
: path.join(app.config.pagePath, importName);
|
: path.join(app.config.pagePath, importName);
|
||||||
|
console.log(importPath);
|
||||||
|
console.log(_pagecode);
|
||||||
try {
|
try {
|
||||||
importCodeString = fs.readFileSync(importPath, "utf-8");
|
importCodeString = fs.readFileSync(importPath, "utf-8");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
app.setState({ status: 1, statusMSG: "Import File Failed" });
|
|
||||||
return "Ups... Import File Failed";
|
return "Ups... Import File Failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,11 +75,12 @@ app.render = function (pagecode, templatecode) {
|
|||||||
|
|
||||||
recursive(imports);
|
recursive(imports);
|
||||||
|
|
||||||
|
//console.log(ImportSet);
|
||||||
|
|
||||||
let currentPagecode = _pagecode;
|
let currentPagecode = _pagecode;
|
||||||
|
|
||||||
ImportSet.forEach(function (importPath) {
|
ImportSet.forEach(function (importPath) {
|
||||||
app.setState({ status: 0, statusMSG: "Import Importfiles" });
|
console.log(importPath);
|
||||||
|
|
||||||
let importCodeString = fs.readFileSync(importPath, "utf-8");
|
let importCodeString = fs.readFileSync(importPath, "utf-8");
|
||||||
let importCode = JSON.parse(importCodeString);
|
let importCode = JSON.parse(importCodeString);
|
||||||
currentPagecode = jsonmerger.mergeJson(currentPagecode, importCode);
|
currentPagecode = jsonmerger.mergeJson(currentPagecode, importCode);
|
||||||
@ -127,12 +88,10 @@ app.render = function (pagecode, templatecode) {
|
|||||||
pagecode = currentPagecode;
|
pagecode = currentPagecode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle _IMPORTS_ const
|
//TODO Killed Root Import
|
||||||
app.CONST(pagecode, "_IMPORTS_", DissolveImports);
|
app.CONST(pagecode, "_IMPORTS_", DissolveImports);
|
||||||
|
//console.log(pagecode);
|
||||||
// Handle _STYLES_ const
|
|
||||||
app.CONST(pagecode, "_STYLES_", (pagecode, value) => {
|
app.CONST(pagecode, "_STYLES_", (pagecode, value) => {
|
||||||
app.setState({ status: 0, statusMSG: "Import Styles" });
|
|
||||||
let rex = /<head>(.|\n|\t|\r)*?<\/head>/;
|
let rex = /<head>(.|\n|\t|\r)*?<\/head>/;
|
||||||
let header = templatecode.match(rex);
|
let header = templatecode.match(rex);
|
||||||
header = header[0].replace("</head>", "");
|
header = header[0].replace("</head>", "");
|
||||||
@ -141,28 +100,23 @@ app.render = function (pagecode, templatecode) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
header += "\n</head>";
|
header += "\n</head>";
|
||||||
|
// console.log(header);
|
||||||
templatecode = templatecode.replace(/<head>(.|\n|\t|\r)*?<\/head>/, header);
|
templatecode = templatecode.replace(/<head>(.|\n|\t|\r)*?<\/head>/, header);
|
||||||
|
// replaceAll(templatecode,rex,value)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.setState({ status: 0, statusMSG: "Set vars" });
|
|
||||||
for (let i in pagecode) {
|
for (let i in pagecode) {
|
||||||
app.setState({ status: 0, statusMSG: "Set " + pagecode[i] });
|
|
||||||
let value = undefined;
|
let value = undefined;
|
||||||
|
|
||||||
if (new RegExp(/\d*_([A-Z]*|[a-z])\w*_/g).test(i)) continue;
|
if (new RegExp(/\d*_([A-Z]*|[a-z])\w*_/g).test(i)) continue;
|
||||||
if (new RegExp(/\/\//g).test(i)) continue;
|
if (new RegExp(/\/\//g).test(i)) continue;
|
||||||
if (new RegExp(/js\$([A-Z]*|[a-z]*)\w+/g).test(i)) {
|
if (new RegExp(/js\$([A-Z]*|[a-z]*)\w+/g).test(i)) {
|
||||||
app.setState({ status: 0, statusMSG: "Execute Serverside Script" });
|
|
||||||
let SE = require("./scriptExecuter");
|
let SE = require("./scriptExecuter");
|
||||||
pagecode[i] = SE(pagecode[i]);
|
pagecode[i] = SE(pagecode[i]);
|
||||||
}
|
}
|
||||||
value = pagecode[i].toString();
|
value = pagecode[i].toString();
|
||||||
templatecode = replaceAll(templatecode, "<[" + i + "]>", value);
|
templatecode = replaceAll(templatecode, "<[" + i + "]>", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.setState({ status: 0, statusMSG: "Delete unused Placeholder" });
|
|
||||||
|
|
||||||
templatecode = templatecode.replace(
|
templatecode = templatecode.replace(
|
||||||
new RegExp(/<\[([A-Z]*|[a-z]*)\w*\]>/g),
|
new RegExp(/<\[([A-Z]*|[a-z]*)\w*\]>/g),
|
||||||
""
|
""
|
||||||
@ -175,7 +129,6 @@ app.render = function (pagecode, templatecode) {
|
|||||||
|
|
||||||
templatecode = templatecode.replace(new RegExp(/<\[\/\/]\>/g), "");
|
templatecode = templatecode.replace(new RegExp(/<\[\/\/]\>/g), "");
|
||||||
|
|
||||||
app.setState({ status: 0, statusMSG: "Return HTML" });
|
|
||||||
return templatecode;
|
return templatecode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
80
src/index.js
80
src/index.js
@ -6,57 +6,45 @@ var app = {};
|
|||||||
|
|
||||||
app.render = engine.render;
|
app.render = engine.render;
|
||||||
app.CONST = engine.CONST;
|
app.CONST = engine.CONST;
|
||||||
|
app.renderFile = (filePath) => {
|
||||||
let pj = require("../package.json");
|
|
||||||
|
|
||||||
app.info = {};
|
|
||||||
app.info["version"] = pj.version;
|
|
||||||
app.info["license"] = pj.license;
|
|
||||||
/**
|
|
||||||
* Render File
|
|
||||||
* @param {*} filePath
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
app.renderFile = (filePath, templatePath) => {
|
|
||||||
app.setState({ status: 0, statusMSG: "read file" });
|
|
||||||
let file = fs.readFileSync(filePath, "utf8");
|
let file = fs.readFileSync(filePath, "utf8");
|
||||||
app.setState({ status: 0, statusMSG: "parse file" });
|
|
||||||
file = JSON.parse(file);
|
file = JSON.parse(file);
|
||||||
app.setState({ status: 0, statusMSG: "set Selfpath" });
|
|
||||||
file["_SELFPATH_"] = path.dirname(filePath);
|
file["_SELFPATH_"] = path.dirname(filePath);
|
||||||
|
return engine.render(file);
|
||||||
if (!(templatePath == undefined)) {
|
|
||||||
app.setState({ status: 0, statusMSG: "read template" });
|
|
||||||
let temp = fs.readFileSync(templatePath, "utf8");
|
|
||||||
return engine.render(file, temp);
|
|
||||||
} else {
|
|
||||||
return engine.render(file);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
// engine.config = app.config;
|
||||||
/**
|
|
||||||
* set State
|
|
||||||
* @param {*} param0
|
|
||||||
*/
|
|
||||||
app.setState = ({ status, statusMSG }) => {
|
|
||||||
if (app.stateCallback != undefined) {
|
|
||||||
app.stateCallback({ status, statusMSG });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set function that would called by new state
|
|
||||||
* @param {*} callback
|
|
||||||
*/
|
|
||||||
app.setStateFunction = function (callback) {
|
|
||||||
app.stateCallback = callback;
|
|
||||||
app.setState({ status: 0, statusMSG: "set Statefunction" });
|
|
||||||
app.setState({ status: 0, statusMSG: "JSSTE is ready" });
|
|
||||||
};
|
|
||||||
|
|
||||||
app.__config = require("./config");
|
app.__config = require("./config");
|
||||||
app.config = app.__config.getConfig();
|
app.config = app.__config.getConfig();
|
||||||
engine.log = app.log;
|
engine.config = app.config;
|
||||||
engine.setState = app.setState;
|
|
||||||
|
// app.expressEngine = (
|
||||||
|
// config = {
|
||||||
|
// templatePath: "templates",
|
||||||
|
// pagePath: "pages",
|
||||||
|
// }
|
||||||
|
// ) => {
|
||||||
|
// config = mergeJson.mergeJson(app.config, config);
|
||||||
|
// let hasrendered = false;
|
||||||
|
// return (filePath, options, callback) => {
|
||||||
|
// if (!hasrendered) {
|
||||||
|
// app.config.templatePath = path.join(
|
||||||
|
// options.settings.views,
|
||||||
|
// config.templatePath
|
||||||
|
// );
|
||||||
|
// app.config.pagePath = path.join(options.settings.views, config.pagePath);
|
||||||
|
// hasrendered = true;
|
||||||
|
// }
|
||||||
|
// // define the template engine
|
||||||
|
// fs.readFile(filePath, function (err, content) {
|
||||||
|
// content = content.toString();
|
||||||
|
// // content = mergeJson.mergeJson(JSON.parse(content), options);
|
||||||
|
|
||||||
|
// if (err) return callback(new Error(err));
|
||||||
|
// // this is an extremely simple template engine
|
||||||
|
// var rendered = app.render(content);
|
||||||
|
// return callback(null, rendered);
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
/**
|
const checker = require("typechecker");
|
||||||
* merge two JSONs
|
|
||||||
* @param {*} org
|
|
||||||
* @param {*} ext
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function mergeJson(org, ext) {
|
|
||||||
|
|
||||||
if (!(typeof org === 'object' && org !== null)) {
|
function mergeJson(org, ext) {
|
||||||
|
// let placeholder = undefined;
|
||||||
|
|
||||||
|
if (!checker.isObject(org)) {
|
||||||
org = JSON.parse(org);
|
org = JSON.parse(org);
|
||||||
}
|
}
|
||||||
if (!(typeof ext === 'object' && ext !== null)) {
|
if (!checker.isObject(ext)) {
|
||||||
ext = JSON.parse(ext);
|
ext = JSON.parse(ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,12 +30,6 @@ function mergeJson(org, ext) {
|
|||||||
return org;
|
return org;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge multiple JSONs
|
|
||||||
* @param {*} org
|
|
||||||
* @param {...any} ext
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function mergeJsons(org, ...ext) {
|
function mergeJsons(org, ...ext) {
|
||||||
ext.forEach((element) => {
|
ext.forEach((element) => {
|
||||||
org = mergeJson(org, element);
|
org = mergeJson(org, element);
|
||||||
|
|||||||
@ -1,18 +1,5 @@
|
|||||||
/**
|
|
||||||
* that functions defines functions to use it in JSSTE JS var (js$varname)
|
|
||||||
*/
|
|
||||||
function Added() {
|
function Added() {
|
||||||
let outString = "";
|
let outString = "";
|
||||||
|
|
||||||
//[jsste_info]
|
|
||||||
|
|
||||||
function jsste_info()
|
|
||||||
{
|
|
||||||
let jssteinfo = jsste_input_file
|
|
||||||
result = `\tINFOS\n\t${Object.keys(jssteinfo).map((key) => key + " : " + jssteinfo[key] ).join("\n\t") }`
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function out(arg) {
|
function out(arg) {
|
||||||
outString += arg;
|
outString += arg;
|
||||||
@ -21,13 +8,11 @@ function Added() {
|
|||||||
function outLine(arg) {
|
function outLine(arg) {
|
||||||
outString += "\n" + arg;
|
outString += "\n" + arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* exectue JSSTE JS var (js$varname)
|
|
||||||
* @param {*} script
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function exec(script) {
|
function exec(script) {
|
||||||
let result = undefined;
|
let result = undefined;
|
||||||
|
|
||||||
@ -36,8 +21,6 @@ function exec(script) {
|
|||||||
script
|
script
|
||||||
);
|
);
|
||||||
|
|
||||||
script = script.replace("//[jsste_info]",`let jsste_input_file = ${JSON.stringify(require("./index").info)}`),
|
|
||||||
|
|
||||||
script += "\n return outString;";
|
script += "\n return outString;";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
let core_render = require("./core.render.test");
|
let core_render = require("./core.render.test");
|
||||||
let core_scriptexec = require("./scriptexec.jsste.test");
|
let core_scriptexec = require("./scriptexec.jsste.test");
|
||||||
let core_includeJSSTE = require("./includeJSSTE.test");
|
let core_includeJSSTE = require("./includeJSSTE.test");
|
||||||
let core_state = require("./core.state.test");
|
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
describe("JSSTE CORE", function () {
|
describe("JSSTE CORE", function () {
|
||||||
core_state();
|
|
||||||
core_render();
|
core_render();
|
||||||
core_scriptexec();
|
core_scriptexec();
|
||||||
core_includeJSSTE();
|
core_includeJSSTE();
|
||||||
|
|||||||
@ -38,27 +38,27 @@ function test() {
|
|||||||
result.should.equal("EXAMPLEEXAMPLE");
|
result.should.equal("EXAMPLEEXAMPLE");
|
||||||
});
|
});
|
||||||
|
|
||||||
// it.only("blub", function () {
|
it.skip("blub", function () {
|
||||||
// let result = JSSTE_Engine.render(
|
let result = JSSTE_Engine.render(
|
||||||
// {
|
{
|
||||||
// js$test: `out('<h1>'+ Date.now().toString() + '</h1>')`,
|
js$test: `out('<h1>'+ Date.now().toString() + '</h1>')`,
|
||||||
// test: "hallo",
|
test: "hallo",
|
||||||
// js$test2: ` retrun "test2"`,
|
js$test2: `test2`,
|
||||||
// _STYLES_: ["./test/style"],
|
_STYLES_: ["./test/style"],
|
||||||
// },
|
},
|
||||||
// `<html>
|
`<html>
|
||||||
// <head>
|
<head>
|
||||||
// <title><[test]></title>
|
<title><[test]></title>
|
||||||
// <meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
// <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
// </head>
|
</head>
|
||||||
// <body>
|
<body>
|
||||||
// <[js$test2]>
|
<[js$test2]>
|
||||||
// </body>
|
</body>
|
||||||
// </html>`
|
</html>`
|
||||||
// );
|
);
|
||||||
// console.log(result);
|
console.log(result);
|
||||||
// });
|
});
|
||||||
|
|
||||||
it("should not rendern _VAR_", function () {
|
it("should not rendern _VAR_", function () {
|
||||||
let template = "<[_VAR_]>";
|
let template = "<[_VAR_]>";
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
let libfolder = "../src/";
|
|
||||||
let JSSTE_Engine = require(libfolder);
|
|
||||||
const { assert } = require("chai");
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
describe("test State", function () {
|
|
||||||
it(" set stateFunction", function () {
|
|
||||||
JSSTE_Engine.setStateFunction(({ status, statusMSG }) => {});
|
|
||||||
assert.typeOf(JSSTE_Engine.setStateFunction, "function");
|
|
||||||
});
|
|
||||||
it(" is setState a function", function () {
|
|
||||||
assert.typeOf(JSSTE_Engine.setState,"function")
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = test;
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
require("chai").should();
|
require("chai").should();
|
||||||
const {assert} = require("chai");
|
|
||||||
let test_jsonMerger = require("./jsonMerger.test");
|
let test_jsonMerger = require("./jsonMerger.test");
|
||||||
let test_core = require("./core.jsste.test");
|
let test_core = require("./core.jsste.test");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user