Permalink
Browse files

require plugin

  • Loading branch information...
1 parent e8e3b99 commit 4c80d665c54fb89aa1ffb29e0f977487077ea53e @jindw committed May 3, 2014
Showing with 13 additions and 10 deletions.
  1. +6 −3 lite-engine.js
  2. +4 −4 parse/extension-parser.js
  3. +3 −3 process.js
View
@@ -6,7 +6,7 @@ function LiteEngine(root){
this.renderTask = {};
var thiz = this;
try{
- throw new Error();
+ //throw new Error();
this.compiler = require('child_process').fork(__dirname + '/process.js',['cpc',root]);
this.compiler.on('message', function(result){
thiz.onChange(result.path,result.code,result.config)
@@ -18,7 +18,7 @@ function LiteEngine(root){
var setupCompiler = require('./process.js').setupCompiler;
var compiler = setupCompiler(root,function(cmd){
var action = cmd.action;
- if(action == 'remove' || action == 'add'){
+ if(action == 'remove' || action == 'add' || action=='error'){
thiz.onChange(cmd.path,cmd.code,cmd.config)
}
});
@@ -35,7 +35,9 @@ LiteEngine.prototype.requestCompile = function(path){
LiteEngine.prototype.onChange = function(path,code,config) {
if(code){
var tpl = new Template(code,config,config.staticPrefix||'');
- this.templateMap[path] = tpl;
+ if(config.error == null){//发生错误的页面每次都需要重建??
+ this.templateMap[path] = tpl;
+ }
var task = this.renderTask[path];
if(task){
delete this.renderTask[path];
@@ -45,6 +47,7 @@ LiteEngine.prototype.onChange = function(path,code,config) {
doRender.apply(null,args)
}
}
+ }else if(){
}else{//clear cache
delete this.templateMap[path];
console.info('clear template cache:' ,path);
@@ -351,13 +351,13 @@ ExtensionParser.prototype = {
},
addExtension:function(namespace,packageName){
if(typeof packageName == 'string'){
- if(/^[\w\.]+$/.test(packageName)){
+ if(/^[\w\.\/]+$/.test(packageName)){
var objectMap = {};
- var packageObject = $import(packageName+':');
- for(var n in packageObject.objectScriptMap){
+ var packageObject = require(packageName);
+ for(var n in packageObject){
var match = n.match(/^(?:document|xmlns|on|parse|before|seek).*/);
if(match){
- var o = $import(packageObject.name+':'+n,objectMap);
+ objectMap = packageObject[n];
}
}
}else{
View
@@ -73,10 +73,10 @@ function setupCompiler(root,callback){
callback({path:path,action:'add',code:result.code,config:result.config,staticPrefix:result[3]})
//process.send({path:path,action:'add',code:result.code,config:result.config,staticPrefix:result[3]})
}catch(e){
- callback({path:path,action:'add',
+ callback({path:path,action:'error',
code:"function(){return "+JSON.stringify(require('util').inspect(e,true))+"}",
- config:{'contentType':'text/html',encoding:'utf-8'},
- staticPrefix:''})
+ config:{'contentType':'text/html',encoding:'utf-8',error:e}
+ })
}
});
}

0 comments on commit 4c80d66

Please sign in to comment.