From ae7d1771fd2e8b03df3d75bf005411a18997036c Mon Sep 17 00:00:00 2001
From: Jeremy Ruston <jeremy@osmosoft.com>
Date: Mon, 21 Jan 2013 17:27:07 +0000
Subject: [PATCH] Fixed TW2 edition

Now we can build TW2 files with just a few whitespace differences from
the old Ruby tools
---
 editions/tw2/plugins/stripcomments.js         | 27 ----------
 .../tw2/plugins/stripcomments/plugin.bundle   |  7 +++
 .../plugins/stripcomments/stripcomments.js    | 54 +++++++++++++++++++
 .../wiki/html-div-tiddler-remove-prefix.tid   |  9 ++++
 .../plain-text-tiddler-strip-comments.tid     |  3 ++
 .../tw2/wiki/tiddlywiki2.template.html.tid    | 45 ++++++++--------
 6 files changed, 96 insertions(+), 49 deletions(-)
 delete mode 100644 editions/tw2/plugins/stripcomments.js
 create mode 100644 editions/tw2/plugins/stripcomments/plugin.bundle
 create mode 100644 editions/tw2/plugins/stripcomments/stripcomments.js
 create mode 100644 editions/tw2/wiki/html-div-tiddler-remove-prefix.tid
 create mode 100644 editions/tw2/wiki/plain-text-tiddler-strip-comments.tid

diff --git a/editions/tw2/plugins/stripcomments.js b/editions/tw2/plugins/stripcomments.js
deleted file mode 100644
index f8a445e60..000000000
--- a/editions/tw2/plugins/stripcomments.js
+++ /dev/null
@@ -1,27 +0,0 @@
-/*\
-title: $:/plugins/stripcomments.js
-type: application/javascript
-module-type: tiddlerserializer
-
-Special serializer for cooking old versions of TiddlyWiki. It removes JavaScript comments formatted as `//#`
-
-\*/
-(function(){
-
-/*jslint node: true, browser: true */
-/*global $tw: false */
-"use strict";
-
-exports["text/plain-strip-comments"] = function(tiddler) {
-	var lines =tiddler.fields.text.split("\n"),
-		out = [];
-	for(var line=0; line<lines.length; line++) {
-		var text = lines[line];
-		if(!/^\s*\/\/#/.test(text)) {
-			out.push(text);
-		}
-	}
-	return out.join("\n");
-};
-
-})();
diff --git a/editions/tw2/plugins/stripcomments/plugin.bundle b/editions/tw2/plugins/stripcomments/plugin.bundle
new file mode 100644
index 000000000..d77ecf134
--- /dev/null
+++ b/editions/tw2/plugins/stripcomments/plugin.bundle
@@ -0,0 +1,7 @@
+{
+	"title": "$:/plugins/tiddlywiki2/stripcomments",
+	"description": "Strips //# comments from JavaScript source",
+	"author": "JeremyRuston",
+	"version": "0.0.0",
+	"coreVersion": ">=5.0.0"
+}
diff --git a/editions/tw2/plugins/stripcomments/stripcomments.js b/editions/tw2/plugins/stripcomments/stripcomments.js
new file mode 100644
index 000000000..579a5ea33
--- /dev/null
+++ b/editions/tw2/plugins/stripcomments/stripcomments.js
@@ -0,0 +1,54 @@
+/*\
+title: $:/plugins/tiddlywiki2/stripcomments/stripcomments.js
+type: application/javascript
+module-type: fieldviewer
+
+Special viewer for cooking old versions of TiddlyWiki. It removes JavaScript comments formatted as `//#`
+
+\*/
+(function(){
+
+/*jslint node: true, browser: true */
+/*global $tw: false */
+"use strict";
+
+var stripComments = function(text) {
+	var lines = text.split("\n"),
+		out = [];
+	for(var line=0; line<lines.length; line++) {
+		var text = lines[line];
+		if(!/^\s*\/\/#/.test(text)) {
+			out.push(text);
+		}
+	}
+	return out.join("\n");
+};
+
+var StripCommentsViewer = function(viewWidget,tiddler,field,value) {
+	this.viewWidget = viewWidget;
+	this.tiddler = tiddler;
+	this.field = field;
+	this.value = value;
+};
+
+StripCommentsViewer.prototype.render = function() {
+	// Get the value as a string
+	if(this.field !== "text" && this.tiddler) {
+		this.value = this.tiddler.getFieldString(this.field);
+	}
+	var value = "";
+	if(this.value !== undefined && this.value !== null) {
+		value = stripComments(this.value);
+	}
+	// Set the element details
+	this.viewWidget.tag = "span";
+	this.viewWidget.attributes = {};
+	this.viewWidget.children = this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,[{
+		type: "text",
+		text: value
+	}]);
+};
+
+exports.stripcomments = StripCommentsViewer;
+
+})();
diff --git a/editions/tw2/wiki/html-div-tiddler-remove-prefix.tid b/editions/tw2/wiki/html-div-tiddler-remove-prefix.tid
new file mode 100644
index 000000000..ef84fad6f
--- /dev/null
+++ b/editions/tw2/wiki/html-div-tiddler-remove-prefix.tid
@@ -0,0 +1,9 @@
+title: $:/core/templates/html-div-tiddler-remove-prefix
+
+<!--
+
+This template is used for saving tiddlers as an HTML DIV tag with attributes representing the tiddler fields.
+
+-->`<div`<$fields template=' $name$="$encoded_value$"' stripTitlePrefix="yes"></$fields>`>
+<pre>`<$view field="text" format="htmlencoded" />`</pre>
+</div>`
diff --git a/editions/tw2/wiki/plain-text-tiddler-strip-comments.tid b/editions/tw2/wiki/plain-text-tiddler-strip-comments.tid
new file mode 100644
index 000000000..3370d436d
--- /dev/null
+++ b/editions/tw2/wiki/plain-text-tiddler-strip-comments.tid
@@ -0,0 +1,3 @@
+title: $:/core/templates/plain-text-tiddler-strip-comments
+
+<$view field="text" format="stripcomments" />
\ No newline at end of file
diff --git a/editions/tw2/wiki/tiddlywiki2.template.html.tid b/editions/tw2/wiki/tiddlywiki2.template.html.tid
index 71eabc5e1..950c97ccd 100644
--- a/editions/tw2/wiki/tiddlywiki2.template.html.tid
+++ b/editions/tw2/wiki/tiddlywiki2.template.html.tid
@@ -1,40 +1,41 @@
 title: $:/core/templates/tiddlywiki2.template.html
-type: text/vnd.tiddlywiki-html
 
+\rules only filteredtranscludeinline transcludeinline
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
 <script id="versionArea" type="text/javascript">
 //<![CDATA[
-<<serialize "[prefix[{version}]]" text/plain>>
+{{{ [prefix[{version}]] ||$:/core/templates/plain-text-tiddler}}}
 //]]>
 </script>
+<meta name="tiddlywiki-version" content="{{$:/core/templates/version}}" />
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
 <meta name="copyright" content="
-<<serialize "[prefix[{copyright}]]" text/plain>>
+{{{ [prefix[{copyright}]] ||$:/core/templates/plain-text-tiddler}}}
 " />
 <!--PRE-HEAD-START-->
-<<serialize "[prefix[{prehead}]]" text/plain>>
+{{{ [prefix[{prehead}]] ||$:/core/templates/plain-text-tiddler}}}
 <!--PRE-HEAD-END-->
 <title>
-<<serialize "[prefix[{title}]]" text/plain>>
+{{{ [prefix[{title}]] ||$:/core/templates/plain-text-tiddler}}}
 </title>
 <style id="styleArea" type="text/css">
-<<serialize "[prefix[{style}]]" text/plain>>
+{{{ [prefix[{style}]] ||$:/core/templates/plain-text-tiddler}}}
 </style>
 <!--POST-HEAD-START-->
-<<serialize "[prefix[{posthead}]]" text/plain>>
+{{{ [prefix[{posthead}]] ||$:/core/templates/plain-text-tiddler}}}
 <!--POST-HEAD-END-->
 </head>
 <body onload="main();" onunload="if(window.unload) unload();">
 <!--PRE-BODY-START-->
-<<serialize "[prefix[{prebody}]]" text/plain>>
+{{{ [prefix[{prebody}]] ||$:/core/templates/plain-text-tiddler}}}
 <!--PRE-BODY-END-->
 <div id="copyright">
 Welcome to TiddlyWiki created by Jeremy Ruston; Copyright &copy; 2004-2007 Jeremy Ruston, Copyright &copy; 2007-2011 UnaMesa Association
 </div>
 <noscript>
-<<serialize "[prefix[{noscript}]]" text/plain>>
+{{{ [prefix[{noscript}]] ||$:/core/templates/plain-text-tiddler}}}
 </noscript>
 <div id="saveTest"></div>
 <div id="backstageCloak"></div>
@@ -46,39 +47,39 @@ Welcome to TiddlyWiki created by Jeremy Ruston; Copyright &copy; 2004-2007 Jerem
 <div id="contentWrapper"></div>
 <div id="contentStash"></div>
 <div id="shadowArea">
-<<serialize "[prefix[{shadow}]] +[sort-case-sensitive[title]]" application/x-tiddler-html-div removePrefix:"{shadow}">>
+{{{ [prefix[{shadow}]] +[sort-case-sensitive[title]] ||$:/core/templates/html-div-tiddler-remove-prefix}}}
 </div>
 <!--POST-SHADOWAREA-->
 <div id="storeArea">
-<<serialize "[prefix[{tiddler}]] +[sort-case-sensitive[title]]" application/x-tiddler-html-div removePrefix:"{tiddler}">>
-<<serialize "[prefix[{plugin}]]" text/plain>>
-<<serialize "[prefix[{posttiddlers}]]" text/plain>>
+{{{ [prefix[{tiddler}]] +[sort-case-sensitive[title]] ||$:/core/templates/html-div-tiddler-remove-prefix}}}
+{{{ [prefix[{plugin}]] ||$:/core/templates/plain-text-tiddler}}}
+{{{ [prefix[{posttiddlers}]] ||$:/core/templates/plain-text-tiddler}}}
 </div>
 <!--POST-STOREAREA-->
 <!--POST-BODY-START-->
-<<serialize "[prefix[{postbody}]]" text/plain>>
+{{{ [prefix[{postbody}]] ||$:/core/templates/plain-text-tiddler}}}
 <!--POST-BODY-END-->
 <script id="jsArea" type="text/javascript">
 //<![CDATA[
-<<serialize "[prefix[{prejs}]]" text/plain-strip-comments>>
-<<serialize "[prefix[{js}]]" text/plain-strip-comments>>
-<<serialize "[prefix[{postjs}]]" text/plain-strip-comments>>
+{{{ [prefix[{prejs}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
+{{{ [prefix[{js}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
+{{{ [prefix[{postjs}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
 //]]>
 </script>
-<<serialize "[prefix[{jsext}]]" text/plain-strip-comments>>
+{{{ [prefix[{jsext}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
 <script id="jsdeprecatedArea" type="text/javascript">
 //<![CDATA[
-<<serialize "[prefix[{jsdeprecated}]]" text/plain-strip-comments>>
+{{{ [prefix[{jsdeprecated}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
 //]]>
 </script>
 <script id="jslibArea" type="text/javascript">
 //<![CDATA[
-<<serialize "[prefix[{jslib}]]" text/plain-strip-comments>>
+{{{ [prefix[{jslib}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
 //]]>
 </script>
 <script id="jqueryArea" type="text/javascript">
 //<![CDATA[
-<<serialize "[prefix[{jquery}]]" text/plain-strip-comments>>
+{{{ [prefix[{jquery}]] ||$:/core/templates/plain-text-tiddler-strip-comments}}}
 //]]>
 </script>
 <script type="text/javascript">
@@ -88,7 +89,7 @@ if(useJavaSaver)
 //]]>
 </script>
 <!--POST-SCRIPT-START-->
-<<serialize "[prefix[{postscript}]]" text/plain>>
+{{{ [prefix[{postscript}]] ||$:/core/templates/plain-text-tiddler}}}
 <!--POST-SCRIPT-END-->
 </body>
 </html>