1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +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"; "use strict";
var ArgParser = function(argString,options) { var ArgParser = function(argString,options) {
@ -56,10 +56,10 @@ var ArgParser = function(argString,options) {
this.byPos.push({n:"", v:n}); this.byPos.push({n:"", v:n});
} else { } else {
v = parseToken(match,8); v = parseToken(match,8);
if(v == null && options.defaultName) { if(v === undefined && options.defaultName) {
v = n; v = n;
n = options.defaultName; n = options.defaultName;
} else if(v == null && options.defaultValue) { } else if(v === undefined && options.defaultValue) {
v = options.defaultValue; v = options.defaultValue;
} }
this.byPos.push({n:n, v:v}); 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". throttling so that we don't get error EMFILE "Too many open files".
*/ */
/*global require: false, exports: false */ /*jslint node: true */
"use strict"; "use strict";
var fs = require("fs"), 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"; "use strict";
var Tiddler = require("./Tiddler.js").Tiddler, var Tiddler = require("./Tiddler.js").Tiddler,
@ -347,7 +347,7 @@ Recipe.prototype.cookRss = function()
s.push("</rss>"); s.push("</rss>");
// Save it all // Save it all
return s.join("\n"); return s.join("\n");
} };
exports.Recipe = Recipe; 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"; "use strict";
var utils = require("./Utils.js"), var utils = require("./Utils.js"),

View File

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

View File

@ -2,7 +2,7 @@
Functions concerned with parsing representations of tiddlers Functions concerned with parsing representations of tiddlers
*/ */
/*global require: false, exports: false */ /*jslint node: true */
"use strict"; "use strict";
var utils = require("./Utils.js"); 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. 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"; "use strict";
var utils = exports; var utils = exports;
@ -131,7 +131,7 @@ utils.getDaySuffix = function(date) {
utils.getWeek = function(date) { utils.getWeek = function(date) {
var dt = new Date(date.getTime()); var dt = new Date(date.getTime());
var d = dt.getDay(); 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 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); var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
return Math.floor(n/7)+1; return Math.floor(n/7)+1;
@ -140,7 +140,7 @@ utils.getWeek = function(date) {
utils.getYearForWeekNo = function(date) { utils.getYearForWeekNo = function(date) {
var dt = new Date(date.getTime()); var dt = new Date(date.getTime());
var d = dt.getDay(); 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 dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
return dt.getFullYear(); return dt.getFullYear();
}; };

View File

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

View File

@ -2,8 +2,7 @@
Wiki text macro implementation Wiki text macro implementation
*/ */
/*jslint node: true */
/*global require: false, exports: false */
"use strict"; "use strict";
var ArgParser = require("./ArgParser.js").ArgParser, var ArgParser = require("./ArgParser.js").ArgParser,
@ -74,13 +73,14 @@ wikiTextMacros.macros = {
var args = new ArgParser(macroNode.params,{defaultName:"name"}), var args = new ArgParser(macroNode.params,{defaultName:"name"}),
targetTitle = args.getValueByName("name",null), targetTitle = args.getValueByName("name",null),
withTokens = args.getValuesByName("with",[]), withTokens = args.getValuesByName("with",[]),
text = store.getTiddlerText(targetTitle,""); text = store.getTiddlerText(targetTitle,""),
t;
for(t=0; t<withTokens.length; t++) { for(t=0; t<withTokens.length; t++) {
var placeholderRegExp = new RegExp("\\$"+(t+1),"mg"); var placeholderRegExp = new RegExp("\\$"+(t+1),"mg");
text = text.replace(placeholderRegExp,withTokens[t]); text = text.replace(placeholderRegExp,withTokens[t]);
} }
var parseTree = new WikiTextParserModule.WikiTextParser(text); 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]); macroNode.output.push(parseTree.tree[t]);
} }
// Execute any macros in the copy // 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"; "use strict";
var wikiTextMacros = require("./WikiTextMacros.js"), var wikiTextMacros = require("./WikiTextMacros.js"),
@ -55,7 +55,8 @@ WikiTextParser.prototype.render = function(type,store,title) {
}; };
WikiTextParser.prototype.renderAsHtml = function(store,title) { WikiTextParser.prototype.renderAsHtml = function(store,title) {
var output = []; var output = [],
renderSubTree;
var renderElement = function(element, selfClosing) { var renderElement = function(element, selfClosing) {
var tagBits = [element.type]; var tagBits = [element.type];
if(element.attributes) { if(element.attributes) {
@ -79,7 +80,7 @@ WikiTextParser.prototype.renderAsHtml = function(store,title) {
output.push("</" + element.type + ">"); output.push("</" + element.type + ">");
} }
}; };
var renderSubTree = function(tree) { renderSubTree = function(tree) {
for(var t=0; t<tree.length; t++) { for(var t=0; t<tree.length; t++) {
switch(tree[t].type) { switch(tree[t].type) {
case "text": case "text":

View File

@ -1,4 +1,4 @@
/*global require: false, exports: false, process: false */ /*jslint node: true */
"use strict"; "use strict";
var util = require("util"); var util = require("util");
@ -154,7 +154,7 @@ WikiTextRules.rules = [
w.subWikifyTerm(rowContainer.children,this.rowTermRegExp); w.subWikifyTerm(rowContainer.children,this.rowTermRegExp);
} else { } else {
var theRow = {type: "tr", children: []}; 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); rowContainer.children.push(theRow);
this.rowHandler(w,theRow.children,prevColumns); this.rowHandler(w,theRow.children,prevColumns);
rowCount++; rowCount++;

View File

@ -43,8 +43,8 @@ You can use filepaths or URLs to reference recipe files and tiddlers. For exampl
## Testing ## 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 ## 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 mkdir -p tmp
# cook tiddlywiki 2.6.5 with cook.js # 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 # 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 # split the newly cooked tiddlywiki into tiddlers, first with the new ginsu
#mkdir -p tmp/newtiddlers #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 # 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 #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 #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 TiddlyWiki command line interface
*/ */
/*global require: false, exports: false, process: false */ /*jslint node: true */
"use strict"; "use strict";
var WikiStore = require("./js/WikiStore.js").WikiStore, var WikiStore = require("./js/WikiStore.js").WikiStore,
@ -33,9 +33,9 @@ var parseOptions = function(args,defaultSwitch) {
switchArgs.push(args[a++]); switchArgs.push(args[a++]);
switchRegExp.lastIndex = 0; switchRegExp.lastIndex = 0;
} }
result.push({switch: m[1], args: switchArgs}); result.push({switchName: m[1], args: switchArgs});
} else { } else {
result.push({switch: defaultSwitch, args: [args[a++]]}); result.push({switchName: defaultSwitch, args: [args[a++]]});
} }
} }
return result; return result;
@ -80,16 +80,15 @@ for(var t=0; t<shadowShadows.length; t++) {
shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t])); shadowShadowStore.addTiddler(new Tiddler(shadowShadows[t]));
} }
var processNextSwitch = function() { var processNextSwitch = function() {
if(currSwitch < switches.length) { if(currSwitch < switches.length) {
var s = switches[currSwitch++], var s = switches[currSwitch++],
csw = commandLineSwitches[s.switch]; csw = commandLineSwitches[s.switchName];
if(s.args.length < csw.args.min) { 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) { 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) { csw.handler(s.args,function (err) {
if(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, var Tiddler = require("./js/Tiddler.js").Tiddler,
WikiStore = require("./js/WikiStore.js").WikiStore, WikiStore = require("./js/WikiStore.js").WikiStore,