Merge pull request #25 from lucaspalomodevelop/fix/renderFile

fixing rendering file wothout template-path
This commit is contained in:
Lucas Manuel Palomo Lauterbach 2022-11-25 22:16:32 +01:00 committed by GitHub
commit 66a989b154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,31 +7,36 @@ var app = {};
app.render = engine.render;
app.CONST = engine.CONST;
let pj = require("../package.json")
let pj = require("../package.json");
app.info = {};
app.info["version"] = pj.version
app.info["license"] = pj.license
app.info["version"] = pj.version;
app.info["license"] = pj.license;
/**
* Render File
* @param {*} filePath
* @returns
* @param {*} filePath
* @returns
*/
app.renderFile = (filePath, templatePath) => {
app.setState({ status: 0, statusMSG: "read file" });
let file = fs.readFileSync(filePath, "utf8");
app.setState({ status: 0, statusMSG: "parse file" });
file = JSON.parse(file);
app.setState({ status: 0, statusMSG: "read template" });
let temp = fs.readFileSync(templatePath, "utf8");
app.setState({ status: 0, statusMSG: "set Selfpath" });
file["_SELFPATH_"] = path.dirname(filePath);
return engine.render(file,temp);
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);
}
};
/**
* set State
* @param {*} param0
* @param {*} param0
*/
app.setState = ({ status, statusMSG }) => {
if (app.stateCallback != undefined) {
@ -41,7 +46,7 @@ app.setState = ({ status, statusMSG }) => {
/**
* Set function that would called by new state
* @param {*} callback
* @param {*} callback
*/
app.setStateFunction = function (callback) {
app.stateCallback = callback;
@ -54,5 +59,4 @@ app.config = app.__config.getConfig();
engine.log = app.log;
engine.setState = app.setState;
module.exports = app;