1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Cleaning up

Mostly murging adjacent var statements.
This commit is contained in:
Jeremy Ruston 2011-11-28 17:04:39 +00:00
parent 8bdafd521e
commit dc3546380a
6 changed files with 39 additions and 40 deletions

View File

@ -15,7 +15,6 @@ var fileRequestQueue = utils.queue(function(task,callback) {
});
},10);
// 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. It returns the final path used to reach the file. On completion, the callback

View File

@ -139,9 +139,9 @@ Recipe.prototype.readIngredient = function(filepath,contextPath,callback) {
// Return a string of the cooked recipe
Recipe.prototype.cook = function() {
var template = this.ingredients.template ? this.ingredients.template[0].fields.text : "";
var out = [];
var me = this;
var template = this.ingredients.template ? this.ingredients.template[0].fields.text : "",
out = [],
me = this;
template.split("\n").forEach(function(line) {
var templateRegExp = /^(?:<!--@@(.*)@@-->)|(?:&lt;!--@@(.*)@@--&gt;)$/gi;
var match = templateRegExp.exec(line);
@ -157,9 +157,9 @@ Recipe.prototype.cook = function() {
// Output all the tiddlers in the recipe with a particular marker
Recipe.prototype.outputIngredient = function(out,marker) {
var ingredient = this.ingredients[marker];
var outputType = Recipe.ingredientOutputMapper[marker] || "raw";
var outputter = Recipe.ingredientOutputter[outputType];
var ingredient = this.ingredients[marker],
outputType = Recipe.ingredientOutputMapper[marker] || "raw",
outputter = Recipe.ingredientOutputter[outputType];
if(outputter && ingredient) {
outputter(out,ingredient);
}
@ -195,8 +195,8 @@ Recipe.ingredientOutputter = {
javascript: function(out,ingredient) {
// Lines starting with //# are removed from javascript tiddlers
for(var t=0; t<ingredient.length; t++) {
var tid = ingredient[t];
var text = tid.fields.text;
var tid = ingredient[t],
text = tid.fields.text;
// For compatibility with cook.rb, remove one trailing \n from tiddler
text = text.charAt(text.length-1) === "\n" ? text.substr(0,text.length-1) : text;
var lines = text.split("\n");
@ -211,9 +211,9 @@ Recipe.ingredientOutputter = {
shadow: function(out,ingredient) {
// Shadows are output as a <DIV> with the the ".shadow" suffix removed from the title
for(var t=0; t<ingredient.length; t++) {
var tid = ingredient[t];
var title = tid.fields.title;
var tweakedTiddler;
var tid = ingredient[t],
title = tid.fields.title,
tweakedTiddler;
if(title.indexOf(".shadow") === title.length - 7) {
tweakedTiddler = new Tiddler(tid,{
title: title.substr(0, title.length-7)

View File

@ -109,10 +109,10 @@ tiddlerInput.parseTiddlerDiv = function(text,fields) {
if(fields === undefined) {
var fields = {};
}
var divRegExp = /^\s*<div\s+([^>]*)>((?:.|\n)*)<\/div>\s*$/gi;
var subDivRegExp = /^\s*<pre>((?:.|\n)*)<\/pre>\s*$/gi;
var attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi;
var match = divRegExp.exec(text);
var divRegExp = /^\s*<div\s+([^>]*)>((?:.|\n)*)<\/div>\s*$/gi,
subDivRegExp = /^\s*<pre>((?:.|\n)*)<\/pre>\s*$/gi,
attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi,
match = divRegExp.exec(text);
if(match) {
var subMatch = subDivRegExp.exec(match[2]); // Body of the <DIV> tag
if(subMatch) {

View File

@ -10,8 +10,8 @@ var tiddlerOutput = exports;
Output a tiddler as a .tid file
*/
tiddlerOutput.outputTiddler = function(tid) {
var result = [];
var outputAttribute = function(name,value) {
var result = [],
outputAttribute = function(name,value) {
result.push(name + ": " + value + "\n");
};
for(var t in tid.fields) {
@ -47,10 +47,10 @@ options - options:
omitPrecedingLineFeed - determines if a linefeed is inserted between the <PRE> tag and the text
*/
tiddlerOutput.outputTiddlerDiv = function(tid) {
var result = [];
var outputAttribute = function(name,value) {
result.push(" " + name + "=\"" + value + "\"");
};
var result = [],
outputAttribute = function(name,value) {
result.push(" " + name + "=\"" + value + "\"");
};
result.push("<div");
for(var t in tid.fields) {
switch(t) {

View File

@ -12,16 +12,16 @@ Parses the text of a TiddlyWiki HTML file, and returns the tiddlers as an array
*/
tiddlyWikiInput.parseTiddlyWiki = function(tiddlywikidoc) {
var results = [];
var storeAreaPos = locateStoreArea(tiddlywikidoc);
var results = [],
storeAreaPos = locateStoreArea(tiddlywikidoc);
if(storeAreaPos) {
var endOfDivRegExp = /(<\/div>\s*)/gi;
var startPos = storeAreaPos[0];
var endOfDivRegExp = /(<\/div>\s*)/gi,
startPos = storeAreaPos[0];
endOfDivRegExp.lastIndex = startPos;
var match = endOfDivRegExp.exec(tiddlywikidoc);
while(match && startPos < storeAreaPos[1]) {
var endPos = endOfDivRegExp.lastIndex;
var fields = tiddlerInput.parseTiddlerDiv(tiddlywikidoc.substring(startPos,endPos));
var endPos = endOfDivRegExp.lastIndex,
fields = tiddlerInput.parseTiddlerDiv(tiddlywikidoc.substring(startPos,endPos));
fields.text = utils.htmlDecode(fields.text);
results.push(fields);
startPos = endPos;
@ -33,17 +33,17 @@ tiddlyWikiInput.parseTiddlyWiki = function(tiddlywikidoc) {
function locateStoreArea(tiddlywikidoc)
{
var startSaveArea = '<div id="' + 'storeArea">';
var startSaveAreaRegExp = /<div id=["']?storeArea['"]?>/gi;
var endSaveArea = '</d' + 'iv>';
var endSaveAreaCaps = '</D' + 'IV>';
var posOpeningDiv = tiddlywikidoc.search(startSaveAreaRegExp);
var limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-STOREAREA--"+">");
var startSaveArea = '<div id="' + 'storeArea">',
startSaveAreaRegExp = /<div id=["']?storeArea['"]?>/gi,
endSaveArea = '</d' + 'iv>',
endSaveAreaCaps = '</D' + 'IV>',
posOpeningDiv = tiddlywikidoc.search(startSaveAreaRegExp),
limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-STOREAREA--"+">");
if(limitClosingDiv == -1) {
limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-BODY-START--"+">");
}
var start = limitClosingDiv == -1 ? tiddlywikidoc.length : limitClosingDiv;
var posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveArea,start);
var start = limitClosingDiv == -1 ? tiddlywikidoc.length : limitClosingDiv,
posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveArea,start);
if(posClosingDiv == -1) {
posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveAreaCaps,start);
}

View File

@ -14,10 +14,10 @@ var filename = process.argv[2];
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
var store = new TiddlyWiki();
var theRecipe = new Recipe(store,filename,function() {
response.end(theRecipe.cook(), "utf-8");
});
var store = new TiddlyWiki(),
theRecipe = new Recipe(store,filename,function() {
response.end(theRecipe.cook(), "utf-8");
});
}).listen(8000);
sys.puts("Server running at http://127.0.0.1:8000/");