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

Lots of JSHint induced tweaks

Still not spotless
This commit is contained in:
Jeremy Ruston 2011-12-09 16:34:02 +00:00
parent 1371423587
commit 7184bc5fa5
15 changed files with 45 additions and 36 deletions

View File

@ -17,7 +17,7 @@ Options and their defaults are:
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var ArgParser = function(argString,options) {
@ -56,10 +56,10 @@ var ArgParser = function(argString,options) {
this.byPos.push({n:"", v:n});
} else {
v = parseToken(match,8);
if(v == null && options.defaultName) {
if(v === undefined && options.defaultName) {
v = n;
n = options.defaultName;
} else if(v == null && options.defaultValue) {
} else if(v === undefined && options.defaultValue) {
v = options.defaultValue;
}
this.byPos.push({n:n, v:v});

View File

@ -3,7 +3,7 @@ FileRetriever can asynchronously retrieve files from HTTP URLs or the local file
throttling so that we don't get error EMFILE "Too many open files".
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var fs = require("fs"),

View File

@ -46,7 +46,7 @@ At this point tiddlers are placed in the store so that they can be referenced by
*/
/*global require: false, exports: false, process: false */
/*jslint node: true */
"use strict";
var Tiddler = require("./Tiddler.js").Tiddler,
@ -347,7 +347,7 @@ Recipe.prototype.cookRss = function()
s.push("</rss>");
// Save it all
return s.join("\n");
}
};
exports.Recipe = Recipe;

View File

@ -33,7 +33,7 @@ as a TiddlyWiki quoted string (eg, "one [[two three]]").
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var utils = require("./Utils.js"),

View File

@ -2,7 +2,7 @@
Functions concerned with parsing representations of tiddlers
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var utils = require("./Utils.js"),
@ -91,9 +91,9 @@ tiddlerInput.parseTiddlerFileByMimeType = {
var match = endOfDivRegExp.exec(text);
while(match && startPos < storeAreaPos[1]) {
var endPos = endOfDivRegExp.lastIndex,
fields = tiddlerInput.parseTiddlerDiv(text.substring(startPos,endPos));
fields.text = utils.htmlDecode(fields.text);
results.push(fields);
tiddlerFields = tiddlerInput.parseTiddlerDiv(text.substring(startPos,endPos),fields);
tiddlerFields.text = utils.htmlDecode(tiddlerFields.text);
results.push(tiddlerFields);
startPos = endPos;
match = endOfDivRegExp.exec(text);
}

View File

@ -2,7 +2,7 @@
Functions concerned with parsing representations of tiddlers
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var utils = require("./Utils.js");

View File

@ -4,7 +4,7 @@ Various static utility functions.
This file is a bit of a dumping ground; the expectation is that most of these functions will be refactored.
*/
/*global require: false, exports: false, process: false */
/*jslint node: true */
"use strict";
var utils = exports;
@ -131,7 +131,7 @@ utils.getDaySuffix = function(date) {
utils.getWeek = function(date) {
var dt = new Date(date.getTime());
var d = dt.getDay();
if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo
var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
return Math.floor(n/7)+1;
@ -140,7 +140,7 @@ utils.getWeek = function(date) {
utils.getYearForWeekNo = function(date) {
var dt = new Date(date.getTime());
var d = dt.getDay();
if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7
dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
return dt.getFullYear();
};

View File

@ -1,4 +1,4 @@
/*global require: false, exports: false, console: false */
/*jslint node: true */
"use strict";
var Tiddler = require("./Tiddler.js").Tiddler,

View File

@ -2,8 +2,7 @@
Wiki text macro implementation
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var ArgParser = require("./ArgParser.js").ArgParser,
@ -74,13 +73,14 @@ wikiTextMacros.macros = {
var args = new ArgParser(macroNode.params,{defaultName:"name"}),
targetTitle = args.getValueByName("name",null),
withTokens = args.getValuesByName("with",[]),
text = store.getTiddlerText(targetTitle,"");
text = store.getTiddlerText(targetTitle,""),
t;
for(t=0; t<withTokens.length; t++) {
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
text = text.replace(placeholderRegExp,withTokens[t]);
}
var parseTree = new WikiTextParserModule.WikiTextParser(text);
for(var t=0; t<parseTree.tree.length; t++) {
for(t=0; t<parseTree.tree.length; t++) {
macroNode.output.push(parseTree.tree[t]);
}
// Execute any macros in the copy

View File

@ -23,7 +23,7 @@ Text nodes are:
*/
/*global require: false, exports: false */
/*jslint node: true */
"use strict";
var wikiTextMacros = require("./WikiTextMacros.js"),
@ -55,7 +55,8 @@ WikiTextParser.prototype.render = function(type,store,title) {
};
WikiTextParser.prototype.renderAsHtml = function(store,title) {
var output = [];
var output = [],
renderSubTree;
var renderElement = function(element, selfClosing) {
var tagBits = [element.type];
if(element.attributes) {
@ -79,7 +80,7 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
output.push("</" + element.type + ">");
}
};
var renderSubTree = function(tree) {
renderSubTree = function(tree) {
for(var t=0; t<tree.length; t++) {
switch(tree[t].type) {
case "text":

View File

@ -1,4 +1,4 @@
/*global require: false, exports: false, process: false */
/*jslint node: true */
"use strict";
var util = require("util");
@ -154,7 +154,7 @@ WikiTextRules.rules = [
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
} else {
var theRow = {type: "tr", children: []};
WikiTextRules.setAttr(theRow,"className",rowCount%2 ? "oddRow" : "evenRow")
WikiTextRules.setAttr(theRow,"className",rowCount%2 ? "oddRow" : "evenRow");
rowContainer.children.push(theRow);
this.rowHandler(w,theRow.children,prevColumns);
rowCount++;

View File

@ -43,8 +43,8 @@ You can use filepaths or URLs to reference recipe files and tiddlers. For exampl
## Testing
`test.sh` contains a simple test that cooks the main tiddlywiki.com recipe and compares it with the results of the old build process (ie, running cook.rb and then opening the file in a browser and performing a 'save changes' operation).
`test.sh` contains a simple test that cooks the main tiddlywiki.com recipe and compares it with the results of the old build process (ie, running cook.rb and then opening the file in a browser and performing a 'save changes' operation). It also invokes `wikitest.js`, a wikification test rig that works off the data in `test/wikitests/`.
## Current status
As of 2nd December 2011, cook.js can now build a fully functional TiddlyWiki from the existing recipe files. There are two or three minor whitespace issues that prevent full byte-for-byte compatibility.
As of 8th December 2011, cook.js can now build a fully functional TiddlyWiki and its RSS feed from the existing recipe files. There are two or three minor whitespace issues that prevent full byte-for-byte compatibility.

11
test.sh
View File

@ -4,10 +4,11 @@
mkdir -p tmp
# cook tiddlywiki 2.6.5 with cook.js
node cook.js $PWD/test/tiddlywiki.2.6.5/source/tiddlywiki.com/index.html.recipe > tmp/newcooked.html || exit 1
mkdir -p tmp/newcooked
node tiddlywiki.js --recipe $PWD/test/tiddlywiki.2.6.5/source/tiddlywiki.com/index.html.recipe --savewiki tmp/newcooked || exit 1
# compare the two
opendiff tmp/newcooked.html test/tiddlywiki.2.6.5/target/index.2.6.5.html
opendiff tmp/newcooked/index.html test/tiddlywiki.2.6.5/target/index.2.6.5.html
# split the newly cooked tiddlywiki into tiddlers, first with the new ginsu
#mkdir -p tmp/newtiddlers
@ -17,3 +18,9 @@ opendiff tmp/newcooked.html test/tiddlywiki.2.6.5/target/index.2.6.5.html
# now cook those tiddlers back again with the respective versions of cook
#cook $PWD/test/data/recipes/oldtiddlers.recipe -d $PWD -o tmp/oldrecooked.html || exit 1
#node cook.js $PWD/test/data/recipes/newtiddlers.recipe > tmp/newrecooked.html || exit 1
# Run the wikification tests
node wikitest.js test/wikitests/
jshint *.js
jshint js

View File

@ -2,7 +2,7 @@
TiddlyWiki command line interface
*/
/*global require: false, exports: false, process: false */
/*jslint node: true */
"use strict";
var WikiStore = require("./js/WikiStore.js").WikiStore,
@ -33,9 +33,9 @@ var parseOptions = function(args,defaultSwitch) {
switchArgs.push(args[a++]);
switchRegExp.lastIndex = 0;
}
result.push({switch: m[1], args: switchArgs});
result.push({switchName: m[1], args: switchArgs});
} else {
result.push({switch: defaultSwitch, args: [args[a++]]});
result.push({switchName: defaultSwitch, args: [args[a++]]});
}
}
return result;
@ -80,16 +80,15 @@ for(var t=0; t<shadowShadows.length; t++) {
shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t]));
}
var processNextSwitch = function() {
if(currSwitch < switches.length) {
var s = switches[currSwitch++],
csw = commandLineSwitches[s.switch];
csw = commandLineSwitches[s.switchName];
if(s.args.length < csw.args.min) {
throw "Command line switch --" + s.switch + " should have a minimum of " + csw.args.min + " arguments"
throw "Command line switch --" + s.switchName + " should have a minimum of " + csw.args.min + " arguments";
}
if(s.args.length > csw.args.max) {
throw "Command line switch --" + s.switch + " should have a maximum of " + csw.args.max + " arguments"
throw "Command line switch --" + s.switchName + " should have a maximum of " + csw.args.max + " arguments";
}
csw.handler(s.args,function (err) {
if(err) {

View File

@ -9,6 +9,8 @@ verifying that the output matches `<tiddlername>.html` and `<tiddlername>.txt`.
*/
/*jslint node: true */
"use strict";
var Tiddler = require("./js/Tiddler.js").Tiddler,
WikiStore = require("./js/WikiStore.js").WikiStore,