ultimate.mvc
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -13,3 +13,4 @@ import fs from 'fs'; | ||
var filename=path.join(this.__dirname,filename); | ||
return {filename, | ||
return {filename,viewdir:path.resolve(this.__viewdir), | ||
details:details?details:{type:'view'}, | ||
@@ -19,2 +20,22 @@ data:null,local:next_local,options,parent_local:this}; | ||
function readAccessFileData(filename){ | ||
return new Promise((resolve,reject)=>{ | ||
fs.access(filename, fs.constants.F_OK, function(err){ | ||
if (err) { | ||
reject(new Error("File not found:"+filename)); | ||
} else { | ||
fs.readFile(filename,function(err, file_data){ | ||
if (err) { | ||
reject(new Error("file read error:"+filename)); | ||
} | ||
else{ | ||
resolve(file_data.toString()); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
async function createElementFuns(tag,props,...children){ | ||
@@ -37,2 +58,8 @@ var child_data=''; | ||
var attrs=''; | ||
if(props)for(var i in props){ | ||
attrs+=` ${i}="${props[i]}"`; | ||
} | ||
if(typeof tag === 'object'){ | ||
@@ -42,20 +69,6 @@ if(!('data' in tag))throw new Error("View object must have data property"); | ||
tag.data=await new Promise((resolve,reject)=>{ | ||
fs.access(tag.filename, fs.constants.F_OK, function(err){ | ||
if (err) { | ||
reject(new Error("File not found:"+tag.filename)); | ||
} else { | ||
fs.readFile(tag.filename,function(err, file_data){ | ||
if (err) { | ||
reject(new Error("file read error:"+tag.filename)); | ||
} | ||
else{ | ||
resolve(file_data.toString()); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
if(tag.details.type=='view'){ | ||
tag.data=await readAccessFileData(tag.filename); | ||
if(tag.details.type=='view'){ | ||
//updated. new insteant need to create at the time of rendering | ||
@@ -74,5 +87,22 @@ var next_local=tag.local?tag.local:{}; | ||
} | ||
//reamek the type | ||
child_data=tag.data+child_data; | ||
tag=tag.details.type; | ||
else if('instant' in tag.details && tag.details.instant===false){ | ||
//if remote access for links or scripts | ||
let accesspath=path.relative(tag.viewdir,path.resolve(tag.filename)); | ||
//attrs | ||
if(tag.details.type=='script'){ | ||
tag=tag.details.type; | ||
attrs+=` src="${accesspath}"`; | ||
} | ||
else if(tag.details.type=='style'){ | ||
return `<link rel="stylesheet" type="text/css" href="${accesspath}" ${attrs}/>`; | ||
} | ||
} | ||
else{ | ||
tag.data=await readAccessFileData(tag.filename); | ||
//reamek the type | ||
child_data=tag.data+child_data; | ||
tag=tag.details.type; | ||
} | ||
} | ||
@@ -83,7 +113,2 @@ else if(typeof tag === 'function'){ | ||
var attrs=''; | ||
for(var i in props){ | ||
attrs+=` ${i}="${props[i]}"`; | ||
} | ||
return `<${tag} ${attrs}>${child_data}</${tag}>`; | ||
@@ -90,0 +115,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Pallob Gain", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"debug":true, | ||
@@ -8,0 +8,0 @@ "orginal_path":false, |
{ | ||
"name": "ultimate.mvc", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "It is node js MVC for creating interactive chromium based cross-platform desktop-app and web-app", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
11741589
57112