Navigation Menu

Skip to content

Commit

Permalink
add error info
Browse files Browse the repository at this point in the history
  • Loading branch information
jindw committed May 1, 2014
1 parent fa3b52b commit 32b5b76
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
11 changes: 9 additions & 2 deletions compiler.js
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -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)",
Expand Down
1 change: 1 addition & 0 deletions parse/config-parser.js
Expand Up @@ -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){
Expand Down
10 changes: 6 additions & 4 deletions parse/parse-context.js
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions parse/xml.js
Expand Up @@ -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;
Expand Down
21 changes: 14 additions & 7 deletions process.js
Expand Up @@ -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.