Permalink
Browse files

add error info

  • Loading branch information...
1 parent fa3b52b commit 32b5b7681d9c581c67c5142cf6c55d226d020946 @jindw committed May 1, 2014
Showing with 33 additions and 16 deletions.
  1. +9 −2 compiler.js
  2. +1 −1 package.json
  3. +1 −0 parse/config-parser.js
  4. +6 −4 parse/parse-context.js
  5. +2 −2 parse/xml.js
  6. +14 −7 process.js
View
@@ -5,11 +5,17 @@ var ParseContext = require('./parse/parse-context').ParseContext;
var JSTranslator = require('./parse/js-translator').JSTranslator;
function LiteCompiler(root){
var root =String(path.resolve(root || './')).replace(/\\/g,'/');
- var config = path.resolve(root,'WEB-INF/lite.xml');
+ var config = path.resolve(root,'lite.xml');
+ //console.log("@@@@"+config,fs.existsSync(config))
if(fs.existsSync(config)){
this.config = new ParseConfig(root,config);
}else{
- this.config = new ParseConfig(root,null);
+ var config = path.resolve(root,'WEB-INF/lite.xml');
+ if(fs.existsSync(config)){
+ this.config = new ParseConfig(root,config);
+ }else{
+ this.config = new ParseConfig(root,null);
+ }
}
console.info("LiteCompiler root:",root);
@@ -18,6 +24,7 @@ LiteCompiler.prototype.compile=function(path){
var context = new ParseContext(this.config,path);
var uri = context.createURI(path);
context.parse(uri);
+ //console.log("&&&",path)
//console.log(context.getConfigMap(path))
var litecode = context.toList();
View
@@ -1,6 +1,6 @@
{
"name": "lite",
- "version": "3.0.0",
+ "version": "3.0.1",
"description": "A cross platform template engine base on xml/html and javascript expression.",
"keywords": [ "javascript","xhtml","html","Java","PHP","template"],
"author": "jindw <jindw@xidea.org> (http://www.xidea.org)",
View
@@ -53,6 +53,7 @@ function parseConfig(doc){
var doc = doc.nodeType?doc:loadLiteXML(doc);
var lites = doc.getElementsByTagName("lite");
var len = lites.length;
+ //console.log(new (require('xmldom').XMLSerializer)().serializeToString(doc))
if(len >= 1){
var root = new LiteGroup(lites.item(0))
if(len>1){
View
@@ -159,14 +159,16 @@ ParseContext.prototype = {
if(path instanceof URI){
}else{
if(/^\s*</.test(path)){
- return loadLiteXML(path,this.config.root)
+ doc = loadLiteXML(path,this.config.root)
}else{
path = new URI(path)
}
}
- this.setCurrentURI(path);
- var doc = loadLiteXML(path,this.config.root);
- this._context._loadTime+=(new Date()-t1);
+ if(path instanceof URI){
+ this.setCurrentURI(path);
+ var doc = loadLiteXML(path,this.config.root);
+ this._context._loadTime+=(new Date()-t1);
+ }
var root = doc && doc.documentElement;
if(root){
root.setAttribute('xmlns:xhtml',"http://www.w3.org/1999/xhtml")
View
@@ -15,8 +15,8 @@ function loadLiteXML(uri,root){
if(/^[\s\ufeff]*[<#]/.test(path)){
return parseXMLByText(path.replace(/^[\s\ufeff]*/,''),root)
}else{
- //print(url)
- if(/^(?:\w+?\:\/\/|\/).*$/.test(path)){
+ //console.log(path,/^(?:\w+\:\/\/|\w\:\\|\/).*$/.test(path))
+ if(/^(?:\w+\:\/\/|\w\:\\|\/).*$/.test(path)){
var pos = path.indexOf('#')+1;
var xpath = pos && path.substr(pos);
var path = pos?path.substr(0,pos-1):path;
View
@@ -64,13 +64,20 @@ function setupCompiler(root,callback){
}
//process.on('message', function(path) {
return (function(path){
- var result = templateCompiler.compile(path);
- //console.log('child got message:', m.root);
- var res = result.resources;
- //console.info('resource config:' ,res);
- addTemplateWatch(path,res);
- 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]})
+ try{
+ var result = templateCompiler.compile(path);
+ //console.log('child got message:', m.root);
+ var res = result.resources;
+ //console.info('resource config:' ,res);
+ addTemplateWatch(path,res);
+ 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',
+ code:"function(){return "+JSON.stringify(require('util').inspect(e,true))+"}",
+ config:{'contentType':'text/html',encoding:'utf-8'},
+ staticPrefix:''})
+ }
});
}
exports.setupCompiler = setupCompiler;

0 comments on commit 32b5b76

Please sign in to comment.