Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Fixed bug in node and browser platforms implementations of getDocumen…
Browse files Browse the repository at this point in the history
…tFromUrl.
  • Loading branch information
jbeard4 committed Jul 9, 2012
1 parent cbb9df3 commit e48aeb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/browser/platform.js
Expand Up @@ -8,7 +8,7 @@ module.exports = {
getDocumentFromUrl : function(url,cb){
this.ajax.get(url,function(r){
cb(null,r);
},url).error(function(e){
},"xml").error(function(e){
cb(e);
});
},
Expand Down
41 changes: 17 additions & 24 deletions lib/node/platform.js
Expand Up @@ -7,42 +7,35 @@ function parseDocumentFromString(str){
return (new xmldom.DOMParser()).parseFromString(str);
}

function onModelCb(cb){
return function(err,s){
if(err){
cb(err);
}else{
try {
var doc = parseDocumentFromString(s);
cb(null,doc);
}catch(e){
cb(e);
}
}
};
}

module.exports = {

pathSeparator : pathModule.join('x', 'x')[1],

//used in parsing
getDocumentFromUrl : function(url,cb){
get.httpGet(url,function(err,s){
if(err){
cb(err);
}else{
try {
var doc = this.parseDocumentFromString(s);
cb(null,doc);
}catch(e){
cb(e);
}
}
});
get.httpGet(url,onModelCb(cb));
},

parseDocumentFromString : parseDocumentFromString,

//TODO: the callback is duplicate code. move this out.
getDocumentFromFilesystem : function(path,cb){
fs.readFile(path,'utf8',function(err,s){
if(err){
cb(err);
}else{
try{
var doc = parseDocumentFromString(s);
cb(null,doc);
}catch(e){
cb(e);
}
}
});
fs.readFile(path,'utf8',onModelCb(cb));
},

getResourceFromUrl : get.getResource,
Expand Down

0 comments on commit e48aeb7

Please sign in to comment.