diff --git a/js/FileRetriever.js b/js/FileRetriever.js index 8d6a58103..c2585f07f 100644 --- a/js/FileRetriever.js +++ b/js/FileRetriever.js @@ -68,30 +68,30 @@ var httpRequest = function(fileurl,callback) { request.end(); }; -// Retrieve a file given a filepath specifier and a context path. If the filepath isn't an absolute -// filepath or an absolute URL, then it is interpreted relative to the context path, which can also be -// a filepath or a URL. On completion, the callback function is called as callback(err,data). The +// Retrieve a file given a filepath specifier and a base directory. If the filepath isn't an absolute +// filepath or an absolute URL, then it is interpreted relative to the base directory, which can also be +// a local directory or a URL. On completion, the callback function is called as callback(err,data). The // data hashmap is as follows: // text: full text of file // path: full path used to reach the file // basename: the basename of the file // extname: the extension of the file -FileRetriever.retrieveFile = function(filepath,contextPath,callback) { +FileRetriever.retrieveFile = function(filepath,baseDir,callback) { var httpRegExp = /^(https?:\/\/)/gi, result = {}, filepathIsHttp = httpRegExp.test(filepath), - contextPathIsHttp = httpRegExp.test(contextPath), + baseDirIsHttp = httpRegExp.test(baseDir), requester; - if(contextPathIsHttp || filepathIsHttp) { + if(baseDirIsHttp || filepathIsHttp) { // If we've got a full HTTP URI then we're good to go - result.path = url.resolve(contextPath,filepath); + result.path = url.resolve(baseDir,filepath); var parsedPath = url.parse(result.path); result.extname = path.extname(parsedPath.pathname); result.basename = path.basename(parsedPath.extname); requester = httpRequest; } else { // It's a file requested in a file context - result.path = path.resolve(contextPath,filepath); + result.path = path.resolve(baseDir,filepath); result.extname = path.extname(result.path); result.basename = path.basename(result.path,result.extname); requester = fileRequest; diff --git a/js/Recipe.js b/js/Recipe.js index ba72b6a11..c0360d857 100755 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -6,13 +6,13 @@ Recipe processing is in four parts: 1) The recipe file is parsed and any subrecipe files loaded recursively into this structure: this.recipe = [ - {marker: , filepath: , contextPath: }, + {marker: , filepath: , baseDir: }, ... - {marker: , filepath: , contextPath: }, + {marker: , filepath: , baseDir: }, [ - {marker: , filepath: , contextPath: }, + {marker: , filepath: , baseDir: }, ... - {marker: , filepath: , contextPath: }, + {marker: , filepath: , baseDir: }, ] ]; @@ -66,18 +66,18 @@ var Recipe = function(options,callback) { this.markers = {}; // A task queue for loading recipe files this.recipeQueue = async.queue(function(task,callback) { - retrieveFile(task.filepath,task.contextPath,function(err,data) { + retrieveFile(task.filepath,task.baseDir,function(err,data) { if(err) { me.callback(err); } else { - me.processRecipeFile(task.recipe,data.text,path.dirname(data.path)); + me.processRecipeFile(task.recipe,data.text,data.path); callback(null); } }); },1); // A task queue for loading tiddler files this.tiddlerQueue = async.queue(function(task,callback) { - me.readTiddlerFile(task.filepath,task.contextPath,function(err,data) { + me.readTiddlerFile(task.filepath,task.baseDir,function(err,data) { if(err) { callback(err); } else { @@ -113,7 +113,7 @@ var Recipe = function(options,callback) { }; // Start the process off by queueing up the loading of the initial recipe this.recipeQueue.push({filepath: this.filepath, - contextPath: process.cwd(), + baseDir: process.cwd(), recipe: this.recipe}); }; @@ -133,18 +133,18 @@ Recipe.prototype.loadTiddlerFiles = function(recipeLine) { posStar = filename.indexOf("*"); if(posStar !== -1) { var fileRegExp = new RegExp("^" + filename.replace(/[\-\[\]{}()+?.,\\\^$|#\s]/g, "\\$&").replace("*",".*") + "$"); - var files = fs.readdirSync(path.resolve(path.dirname(recipeLine.contextPath),filedir)); + var files = fs.readdirSync(path.resolve(recipeLine.baseDir,filedir)); for(var f=0; f 0) { fields = this.store.deserializeTiddlers("application/x-tiddler",fieldLines.join("\n"),{})[0]; } - recipe.push({marker: match.marker, filepath: match.value, contextPath: contextPath, fields: fields}); + recipe.push({marker: match.marker, filepath: match.value, baseDir: path.dirname(recipePath), fields: fields}); } } } @@ -245,10 +245,10 @@ Recipe.prototype.processRecipeFile = function(recipe,text,contextPath) { // Read a tiddler file and callback with an array of hashmaps of tiddler fields. For single // tiddler files it also looks for an accompanying .meta file -Recipe.prototype.readTiddlerFile = function(filepath,contextPath,callback) { +Recipe.prototype.readTiddlerFile = function(filepath,baseDir,callback) { var me = this; // Read the tiddler file - retrieveFile(filepath,contextPath,function(err,data) { + retrieveFile(filepath,baseDir,function(err,data) { if (err) throw err; // Use the filepath as the default title for the tiddler var fields = { @@ -258,7 +258,7 @@ Recipe.prototype.readTiddlerFile = function(filepath,contextPath,callback) { // Check for the .meta file if(data.extname !== ".json" && tiddlers.length === 1) { var metafile = filepath + ".meta"; - retrieveFile(metafile,contextPath,function(err,data) { + retrieveFile(metafile,baseDir,function(err,data) { if(err && err.code !== "ENOENT" && err.code !== "404") { callback(err); } else {