1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-07 04:24:22 +00:00

Cleaned up last few diffs for building 2.6.5

Now the file is byte-for-byte identical with that produced by
TiddlyWiki itself.
This commit is contained in:
Jeremy Ruston 2012-01-23 14:36:12 +00:00
parent 3675958e30
commit fd9d4973e3

View File

@ -302,18 +302,20 @@ Recipe.prototype.readTiddlerFile = function(filepath,baseDir,callback) {
Recipe.prototype.cook = function() { Recipe.prototype.cook = function() {
var template = this.markers.template ? this.store.getTiddlerText(this.markers.template[0]) : "", var template = this.markers.template ? this.store.getTiddlerText(this.markers.template[0]) : "",
out = [], out = [],
me = this; templateLines = template.split("\n");
template.split("\n").forEach(function(line) { for(var line=0; line<templateLines.length; line++) {
var templateRegExp = /^(?:<!--@@(.*)@@-->)|(?:&lt;!--@@(.*)@@--&gt;)$/gi; var templateRegExp = /^(?:<!--@@(.*)@@-->)|(?:&lt;!--@@(.*)@@--&gt;)$/gi;
var match = templateRegExp.exec(line); var match = templateRegExp.exec(templateLines[line]);
if(match) { if(match) {
var marker = match[1] === undefined ? match[2] : match[1]; var marker = match[1] === undefined ? match[2] : match[1];
me.outputTiddlersForMarker(out,marker); this.outputTiddlersForMarker(out,marker);
} else { } else {
out.push(line); if(line !== templateLines.length-1) {
out.push(templateLines[line],"\n");
} }
}); }
return out.join("\n"); }
return out.join("");
}; };
// Output all the tiddlers in the recipe with a particular marker // Output all the tiddlers in the recipe with a particular marker
@ -325,7 +327,16 @@ Recipe.prototype.outputTiddlersForMarker = function(out,marker) {
tiddlers = []; tiddlers = [];
} }
if(outputter) { if(outputter) {
if((out.length > 1) && (Recipe.compatibilityCheats[marker] === "suppressLeadingNewline")) {
var lastLine = out[out.length-1];
if(lastLine.substr(-1) === "\n") {
out[out.length-1] = lastLine.substr(0,lastLine.length-1);
}
}
outputter.call(this,out,tiddlers); outputter.call(this,out,tiddlers);
if(Recipe.compatibilityCheats[marker] === "addTrailingNewline") {
out.push("\n");
}
} }
}; };
@ -333,6 +344,7 @@ Recipe.prototype.outputTiddlersForMarker = function(out,marker) {
Recipe.tiddlerOutputMapper = { Recipe.tiddlerOutputMapper = {
tiddler: "div", tiddler: "div",
js: "javascript", js: "javascript",
jslib: "javascript",
jsdeprecated: "javascript", jsdeprecated: "javascript",
jquery: "javascript", jquery: "javascript",
shadow: "shadow", shadow: "shadow",
@ -340,21 +352,26 @@ Recipe.tiddlerOutputMapper = {
jsmodule: "jsmodule" jsmodule: "jsmodule"
}; };
Recipe.compatibilityCheats = {
"prehead": "addTrailingNewline",
"posthead": "addTrailingNewline",
"prebody": "addTrailingNewline",
"postscript": "addTrailingNewline",
"title": "suppressLeadingNewline"
};
Recipe.tiddlerOutputter = { Recipe.tiddlerOutputter = {
raw: function(out,tiddlers) { raw: function(out,tiddlers) {
// The default is just to output the raw text of the tiddler, ignoring any metadata // The default is just to output the raw text of the tiddler, ignoring any metadata
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
// For compatibility with cook.rb, remove one trailing \n from tiddler out.push(this.store.getTiddlerText(tiddlers[t]));
var text = this.store.getTiddlerText(tiddlers[t]);
text = text.charAt(text.length-1) === "\n" ? text.substr(0,text.length-1) : text;
out.push(text);
} }
}, },
div: function(out,tiddlers) { div: function(out,tiddlers) {
// Ordinary tiddlers are output as a <DIV> // Ordinary tiddlers are output as a <DIV>
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
var tid = this.store.getTiddler(tiddlers[t]); var tid = this.store.getTiddler(tiddlers[t]);
out.push(this.store.serializeTiddler("application/x-tiddler-html-div",tid)); out.push(this.store.serializeTiddler("application/x-tiddler-html-div",tid),"\n");
} }
}, },
javascript: function(out,tiddlers) { javascript: function(out,tiddlers) {
@ -362,13 +379,14 @@ Recipe.tiddlerOutputter = {
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
var tid = this.store.getTiddler(tiddlers[t]), var tid = this.store.getTiddler(tiddlers[t]),
text = tid.text; text = tid.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"); var lines = text.split("\n");
for(var line=0; line<lines.length; line++) { for(var line=0; line<lines.length; line++) {
var commentRegExp = /^\s*\/\/#/gi; var commentRegExp = /^\s*\/\/#/gi;
if(!commentRegExp.test(lines[line])) { if(!commentRegExp.test(lines[line])) {
out.push(lines[line]); out.push(lines[line]);
if(line !== lines.length-1) {
out.push("\n");
}
} }
} }
} }
@ -377,11 +395,11 @@ Recipe.tiddlerOutputter = {
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
var title = tiddlers[t], var title = tiddlers[t],
tid = this.store.shadows.getTiddler(title); tid = this.store.shadows.getTiddler(title);
out.push(this.store.serializeTiddler("application/x-tiddler-html-div",tid)); out.push(this.store.serializeTiddler("application/x-tiddler-html-div",tid),"\n");
} }
}, },
title: function(out,tiddlers) { title: function(out,tiddlers) {
out.push(this.store.renderTiddler("text/plain","WindowTitle")); out.push(" ",this.store.renderTiddler("text/plain","WindowTitle")," ");
}, },
jsmodule: function(out,tiddlers) { jsmodule: function(out,tiddlers) {
// JavaScript modules are output as a special script tag // JavaScript modules are output as a special script tag