add comments

This commit is contained in:
lucaspalomodevelop 2022-10-31 15:53:48 +01:00
parent da12e94818
commit 6e371c15f0
5 changed files with 85 additions and 7 deletions

View File

@ -6,14 +6,27 @@ let configvar = {
stylesheets: __dirname + "\\src\\styles",
};
/**
* get config var by key
* @param {*} key
* @returns
*/
config.get = function (key) {
return configvar[key];
};
/**
* get full config
* @returns
*/
config.getConfig = function () {
return configvar;
};
/**
* set full config
* @param {*} param0
*/
config.setConfig = function ({
templatePath,
pagePath,
@ -26,6 +39,11 @@ config.setConfig = function ({
configvar.stylesheets = stylesheets;
};
/**
* set config via key
* @param {*} key
* @param {*} value
*/
config.set = function (key, value) {
configvar[key] = value;
};

View File

@ -6,15 +6,33 @@ let app = {};
app.__config = require("./config");
app.config = app.__config.getConfig();
//function to escape regex
/**
* function to escape regex
* @param {*} string
* @returns
*/
function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
}
/**
* replace all placeholder in a string
* @param {*} str
* @param {*} find
* @param {*} replace
* @returns
*/
function replaceAll(str, find, 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) {
if (pagecode[constant] !== undefined) {
callback(pagecode, pagecode[constant]);
@ -23,17 +41,21 @@ app.CONST = function (pagecode, constant, callback) {
}
};
/**
* renders Pagecode in Templatecode
* @param {*} pagecode
* @param {*} templatecode
* @returns
*/
app.render = function (pagecode, templatecode) {
app.setState({ status: 0, statusMSG: "Render Page" });
if (
(pagecode != null || pagecode != undefined) &&
(typeof pagecode === 'string')
typeof pagecode === "string"
) {
pagecode = JSON.parse(pagecode);
app.setState({ status: 0, statusMSG: "Parse Pagecode" });
}
else
{
} else {
app.setState({ status: 1, statusMSG: "Pagecode is undefined" });
}
@ -50,6 +72,11 @@ app.render = function (pagecode, templatecode) {
}
}
/**
* Dissolve Fileimports
* @param {*} _pagecode
* @param {*} imports
*/
let DissolveImports = function (_pagecode, imports) {
app.setState({ status: 0, statusMSG: "Dissolve Imports" });
let ImportSet = new Set();
@ -89,8 +116,10 @@ app.render = function (pagecode, templatecode) {
pagecode = currentPagecode;
};
// Handle _IMPORTS_ const
app.CONST(pagecode, "_IMPORTS_", DissolveImports);
// Handle _STYLES_ const
app.CONST(pagecode, "_STYLES_", (pagecode, value) => {
app.setState({ status: 0, statusMSG: "Import Styles" });
let rex = /<head>(.|\n|\t|\r)*?<\/head>/;
@ -103,7 +132,6 @@ app.render = function (pagecode, templatecode) {
header += "\n</head>";
templatecode = templatecode.replace(/<head>(.|\n|\t|\r)*?<\/head>/, header);
});
app.setState({ status: 0, statusMSG: "Set vars" });

View File

@ -6,6 +6,11 @@ var app = {};
app.render = engine.render;
app.CONST = engine.CONST;
/**
* Render File
* @param {*} filePath
* @returns
*/
app.renderFile = (filePath) => {
this.setState({ status: 0, statusMSG: "read file" });
let file = fs.readFileSync(filePath, "utf8");
@ -16,12 +21,20 @@ app.renderFile = (filePath) => {
return engine.render(file);
};
/**
* 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;
this.setState({ status: 0, statusMSG: "set Statefunction" });

View File

@ -1,3 +1,9 @@
/**
* merge two JSONs
* @param {*} org
* @param {*} ext
* @returns
*/
function mergeJson(org, ext) {
if (!(typeof org === 'object' && org !== null)) {
@ -27,6 +33,12 @@ function mergeJson(org, ext) {
return org;
}
/**
* Merge multiple JSONs
* @param {*} org
* @param {...any} ext
* @returns
*/
function mergeJsons(org, ...ext) {
ext.forEach((element) => {
org = mergeJson(org, element);

View File

@ -1,3 +1,6 @@
/**
* that functions defines functions to use it in JSSTE JS var (js$varname)
*/
function Added() {
let outString = "";
@ -8,9 +11,13 @@ function Added() {
function outLine(arg) {
outString += "\n" + arg;
}
}
/**
* exectue JSSTE JS var (js$varname)
* @param {*} script
* @returns
*/
function exec(script) {
let result = undefined;