From 80f4250a62bdd82847d0b0ba585f97856bb7924f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 30 Nov 2011 16:06:34 +0000 Subject: [PATCH] Preparing to add support for JSON files loaded from TiddlySpace/TiddlyWeb --- cook.js | 4 +-- js/ArgParser.js | 3 ++- js/FileRetriever.js | 6 ++--- js/Recipe.js | 59 +++++++++++++++++++++++++++++---------------- js/TiddlerInput.js | 29 ++++++++++++---------- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/cook.js b/cook.js index fcb4b1416..62ab0baae 100644 --- a/cook.js +++ b/cook.js @@ -3,7 +3,8 @@ // Usage: node cook.js var TiddlyWiki = require("./js/TiddlyWiki.js").TiddlyWiki, - Recipe = require("./js/Recipe.js").Recipe; + Recipe = require("./js/Recipe.js").Recipe, + util = require("util"); var filename = process.argv[2]; @@ -12,4 +13,3 @@ var store = new TiddlyWiki(); var theRecipe = new Recipe(store,filename,function() { process.stdout.write(theRecipe.cook()); }); - diff --git a/js/ArgParser.js b/js/ArgParser.js index b372f01a9..148f6d95c 100755 --- a/js/ArgParser.js +++ b/js/ArgParser.js @@ -44,8 +44,9 @@ var ArgParser = function(argString,options) { var skipSpace = "(?:\\s*)"; var token = "(?:" + dblQuote + "|" + sngQuote + "|" + dblSquare + "|" + dblBrace + "|" + unQuoted + "|" + emptyQuote + ")"; var re = options.noNames ? new RegExp(token,"mg") : new RegExp(skipSpace + token + skipSpace + "(?:(\\:)" + skipSpace + token + ")?","mg"); + var match; do { - var match = re.exec(argString); + match = re.exec(argString); if(match) { var n = parseToken(match,1); if(options.noNames) { diff --git a/js/FileRetriever.js b/js/FileRetriever.js index 2bb444674..30ada27ea 100644 --- a/js/FileRetriever.js +++ b/js/FileRetriever.js @@ -16,7 +16,6 @@ var FileRetriever = exports; var fileRequestQueue = utils.queue(function(task,callback) { fs.readFile(task.filepath,"utf8", function(err,data) { callback(err,data); -console.error("Retrieved " + task.filepath); }); },10); @@ -31,11 +30,10 @@ var httpRequestQueue = utils.queue(function(task,callback) { } else { var data = []; res.on("data", function(chunk) { - data.push(chunk) + data.push(chunk); }); res.on("end", function() { callback(null,data.join("")); -console.error("Retrieved " + task.url); }); } }); @@ -72,4 +70,4 @@ FileRetriever.retrieveFile = function(filepath,contextPath,callback) { fileRequestQueue.push({filepath: result.path},callback); } return result; -} +}; diff --git a/js/Recipe.js b/js/Recipe.js index 16b604633..88de19a24 100755 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -80,17 +80,28 @@ Recipe.prototype.processRecipe = function (data,contextPath) { if(marker === "recipe") { me.readRecipe(value,contextPath); } else { + // Reserve a place in the ingredients array for this ingredient, just to keep tiddler ordering + // compatible with cook.rb if(!(marker in me.ingredients)) { me.ingredients[marker] = []; } var ingredientLocation = me.ingredients[marker].push(null) - 1; - me.readIngredient(value,contextPath,function(fields) { - var postProcess = me.readIngredientPostProcess[marker]; - if(postProcess) - fields = postProcess(fields); - var ingredientTiddler = new Tiddler(fields); - me.store.addTiddler(ingredientTiddler); - me.ingredients[marker][ingredientLocation] = ingredientTiddler; + me.readIngredient(value,contextPath,function(tiddlers) { + for(var t=0; t