mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-14 07:34:35 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d532d08b5 | |||
| 66a989b154 | |||
| f97e535877 | |||
| 99934228da | |||
| 85a51d9003 | |||
| 1c681f06fc | |||
| a61ff94799 | |||
| 1275514b3f | |||
| 4dcd9ff32f | |||
| 7aceb84bcc | |||
| 91ebab68d1 | |||
| ea79d7915c | |||
| 6d54150ca2 | |||
| a60fe69c77 | |||
| 7778fbd1fe | |||
| 63f84f72d2 | |||
| a4e0e11b79 | |||
| 99234c865c | |||
| 21c704eaff | |||
| 240e2fa60c | |||
| f1f5ce44bc | |||
| af2da3ec80 | |||
| d5d1b23546 | |||
| 69d86e44f3 | |||
| 1e6645d90a | |||
| 0a81571827 | |||
| 1c221ef048 | |||
| 4daba83eeb | |||
| ac53995608 | |||
| 1bddfdd4fd | |||
| 60e26ffb37 | |||
| 91ae19c049 | |||
| 479feb029c | |||
| 6294fe702c | |||
| 794d6b5550 | |||
| 908058bce6 | |||
|
|
3552a43714 | ||
| 445d669815 | |||
|
|
df2fd6a888 | ||
| 71bfe7a22e | |||
| 496ad727f2 | |||
| 477570b4e5 | |||
| 6cdef37326 | |||
| 347e83f7f6 | |||
| dab7c7e78e | |||
| 6e371c15f0 | |||
| da12e94818 | |||
| 36225ac7e8 | |||
| 96d4b4ee12 | |||
| 828667c3f3 | |||
| 9f131a1702 | |||
| 71e3e44e3d | |||
| c20047b95c | |||
| 8e3b25722b | |||
| 4fd34232a2 | |||
| f4636b3946 | |||
| 9d20956804 |
37
.github/workflows/npm-publish.yml
vendored
Normal file
37
.github/workflows/npm-publish.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# 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,3 +1,4 @@
|
|||||||
|
testfiles
|
||||||
planning
|
planning
|
||||||
.vscode
|
.vscode
|
||||||
built
|
built
|
||||||
|
|||||||
54
README.md
54
README.md
@ -72,6 +72,58 @@ 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
|
||||||
@ -105,3 +157,5 @@ let result = Jsste.render(pagecode, templatecode);
|
|||||||
// </html>
|
// </html>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Examples on [https://github.com/lucaspalomodevelop/JSSTE-Examples](https://github.com/lucaspalomodevelop/JSSTE-Examples)
|
||||||
|
|||||||
9859
package-lock.json
generated
9859
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "jsste",
|
"name": "jsste",
|
||||||
"version": "1.1.3",
|
"version": "1.3.3",
|
||||||
"description": "A Javascript Static Template Emgine",
|
"description": "A Javascript Static Template Engine",
|
||||||
"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",
|
||||||
@ -15,7 +18,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",
|
||||||
"compile": "tsc"
|
"cmd": "node ./src/cli.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,30 +26,21 @@
|
|||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"engine",
|
"engine",
|
||||||
"templateengine"
|
"templateengine",
|
||||||
|
"jsste"
|
||||||
],
|
],
|
||||||
"author": "lucas palomo",
|
"author": "Lucas Palomo Lauterbach",
|
||||||
"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",
|
||||||
"express": "^4.17.1",
|
"mocha": "^10.1.0"
|
||||||
"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
Normal file
99
src/cli.js
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#!/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,14 +6,27 @@ 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,
|
||||||
@ -26,6 +39,11 @@ 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,22 +1,38 @@
|
|||||||
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]);
|
||||||
@ -25,30 +41,55 @@ 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) {
|
||||||
//let result = "";
|
app.setState({ status: 0, statusMSG: "Render Page" });
|
||||||
|
|
||||||
//if (!pagecode == JSON) pagecode = JSON.parse(pagecode);
|
|
||||||
if (
|
if (
|
||||||
(pagecode != null || pagecode != undefined) &&
|
(pagecode != null || pagecode != undefined) &&
|
||||||
checker.isString(pagecode)
|
typeof pagecode === "string"
|
||||||
) {
|
) {
|
||||||
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) {
|
||||||
@ -57,11 +98,10 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +115,11 @@ 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) {
|
||||||
console.log(importPath);
|
app.setState({ status: 0, statusMSG: "Import Importfiles" });
|
||||||
|
|
||||||
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);
|
||||||
@ -88,10 +127,12 @@ app.render = function (pagecode, templatecode) {
|
|||||||
pagecode = currentPagecode;
|
pagecode = currentPagecode;
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO Killed Root Import
|
// Handle _IMPORTS_ const
|
||||||
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>", "");
|
||||||
@ -100,23 +141,28 @@ 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),
|
||||||
""
|
""
|
||||||
@ -129,6 +175,7 @@ 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,45 +6,57 @@ 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.config = app.config;
|
engine.log = app.log;
|
||||||
|
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,12 +1,15 @@
|
|||||||
const checker = require("typechecker");
|
/**
|
||||||
|
* merge two JSONs
|
||||||
|
* @param {*} org
|
||||||
|
* @param {*} ext
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
function mergeJson(org, ext) {
|
function mergeJson(org, ext) {
|
||||||
// let placeholder = undefined;
|
|
||||||
|
|
||||||
if (!checker.isObject(org)) {
|
if (!(typeof org === 'object' && org !== null)) {
|
||||||
org = JSON.parse(org);
|
org = JSON.parse(org);
|
||||||
}
|
}
|
||||||
if (!checker.isObject(ext)) {
|
if (!(typeof ext === 'object' && ext !== null)) {
|
||||||
ext = JSON.parse(ext);
|
ext = JSON.parse(ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +33,12 @@ 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,5 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
@ -8,11 +21,13 @@ 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;
|
||||||
|
|
||||||
@ -21,6 +36,8 @@ 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,9 +1,11 @@
|
|||||||
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.skip("blub", function () {
|
// it.only("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: `test2`,
|
// js$test2: ` retrun "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_]>";
|
||||||
|
|||||||
17
test/core.state.test.js
Normal file
17
test/core.state.test.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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,4 +1,5 @@
|
|||||||
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