1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +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); },10);
// Retrieve a file given a filepath specifier and a context path. If the filepath isn't an absolute // 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 // 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 // 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 // Return a string of the cooked recipe
Recipe.prototype.cook = function() { Recipe.prototype.cook = function() {
var template = this.ingredients.template ? this.ingredients.template[0].fields.text : ""; var template = this.ingredients.template ? this.ingredients.template[0].fields.text : "",
var out = []; out = [],
var me = this; me = this;
template.split("\n").forEach(function(line) { template.split("\n").forEach(function(line) {
var templateRegExp = /^(?:<!--@@(.*)@@-->)|(?:&lt;!--@@(.*)@@--&gt;)$/gi; var templateRegExp = /^(?:<!--@@(.*)@@-->)|(?:&lt;!--@@(.*)@@--&gt;)$/gi;
var match = templateRegExp.exec(line); var match = templateRegExp.exec(line);
@ -157,9 +157,9 @@ Recipe.prototype.cook = function() {
// Output all the tiddlers in the recipe with a particular marker // Output all the tiddlers in the recipe with a particular marker
Recipe.prototype.outputIngredient = function(out,marker) { Recipe.prototype.outputIngredient = function(out,marker) {
var ingredient = this.ingredients[marker]; var ingredient = this.ingredients[marker],
var outputType = Recipe.ingredientOutputMapper[marker] || "raw"; outputType = Recipe.ingredientOutputMapper[marker] || "raw",
var outputter = Recipe.ingredientOutputter[outputType]; outputter = Recipe.ingredientOutputter[outputType];
if(outputter && ingredient) { if(outputter && ingredient) {
outputter(out,ingredient); outputter(out,ingredient);
} }
@ -195,8 +195,8 @@ Recipe.ingredientOutputter = {
javascript: function(out,ingredient) { javascript: function(out,ingredient) {
// Lines starting with //# are removed from javascript tiddlers // Lines starting with //# are removed from javascript tiddlers
for(var t=0; t<ingredient.length; t++) { for(var t=0; t<ingredient.length; t++) {
var tid = ingredient[t]; var tid = ingredient[t],
var text = tid.fields.text; text = tid.fields.text;
// For compatibility with cook.rb, remove one trailing \n from tiddler // 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; text = text.charAt(text.length-1) === "\n" ? text.substr(0,text.length-1) : text;
var lines = text.split("\n"); var lines = text.split("\n");
@ -211,9 +211,9 @@ Recipe.ingredientOutputter = {
shadow: function(out,ingredient) { shadow: function(out,ingredient) {
// Shadows are output as a <DIV> with the the ".shadow" suffix removed from the title // Shadows are output as a <DIV> with the the ".shadow" suffix removed from the title
for(var t=0; t<ingredient.length; t++) { for(var t=0; t<ingredient.length; t++) {
var tid = ingredient[t]; var tid = ingredient[t],
var title = tid.fields.title; title = tid.fields.title,
var tweakedTiddler; tweakedTiddler;
if(title.indexOf(".shadow") === title.length - 7) { if(title.indexOf(".shadow") === title.length - 7) {
tweakedTiddler = new Tiddler(tid,{ tweakedTiddler = new Tiddler(tid,{
title: title.substr(0, title.length-7) title: title.substr(0, title.length-7)

View File

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

View File

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

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) { tiddlyWikiInput.parseTiddlyWiki = function(tiddlywikidoc) {
var results = []; var results = [],
var storeAreaPos = locateStoreArea(tiddlywikidoc); storeAreaPos = locateStoreArea(tiddlywikidoc);
if(storeAreaPos) { if(storeAreaPos) {
var endOfDivRegExp = /(<\/div>\s*)/gi; var endOfDivRegExp = /(<\/div>\s*)/gi,
var startPos = storeAreaPos[0]; startPos = storeAreaPos[0];
endOfDivRegExp.lastIndex = startPos; endOfDivRegExp.lastIndex = startPos;
var match = endOfDivRegExp.exec(tiddlywikidoc); var match = endOfDivRegExp.exec(tiddlywikidoc);
while(match && startPos < storeAreaPos[1]) { while(match && startPos < storeAreaPos[1]) {
var endPos = endOfDivRegExp.lastIndex; var endPos = endOfDivRegExp.lastIndex,
var fields = tiddlerInput.parseTiddlerDiv(tiddlywikidoc.substring(startPos,endPos)); fields = tiddlerInput.parseTiddlerDiv(tiddlywikidoc.substring(startPos,endPos));
fields.text = utils.htmlDecode(fields.text); fields.text = utils.htmlDecode(fields.text);
results.push(fields); results.push(fields);
startPos = endPos; startPos = endPos;
@ -33,17 +33,17 @@ tiddlyWikiInput.parseTiddlyWiki = function(tiddlywikidoc) {
function locateStoreArea(tiddlywikidoc) function locateStoreArea(tiddlywikidoc)
{ {
var startSaveArea = '<div id="' + 'storeArea">'; var startSaveArea = '<div id="' + 'storeArea">',
var startSaveAreaRegExp = /<div id=["']?storeArea['"]?>/gi; startSaveAreaRegExp = /<div id=["']?storeArea['"]?>/gi,
var endSaveArea = '</d' + 'iv>'; endSaveArea = '</d' + 'iv>',
var endSaveAreaCaps = '</D' + 'IV>'; endSaveAreaCaps = '</D' + 'IV>',
var posOpeningDiv = tiddlywikidoc.search(startSaveAreaRegExp); posOpeningDiv = tiddlywikidoc.search(startSaveAreaRegExp),
var limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-STOREAREA--"+">"); limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-STOREAREA--"+">");
if(limitClosingDiv == -1) { if(limitClosingDiv == -1) {
limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-BODY-START--"+">"); limitClosingDiv = tiddlywikidoc.indexOf("<"+"!--POST-BODY-START--"+">");
} }
var start = limitClosingDiv == -1 ? tiddlywikidoc.length : limitClosingDiv; var start = limitClosingDiv == -1 ? tiddlywikidoc.length : limitClosingDiv,
var posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveArea,start); posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveArea,start);
if(posClosingDiv == -1) { if(posClosingDiv == -1) {
posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveAreaCaps,start); posClosingDiv = tiddlywikidoc.lastIndexOf(endSaveAreaCaps,start);
} }

View File

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