From 11a07e71dc4bf0396da625af56746dbe5d80fce6 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston <jeremyruston@SilverSlim.local> Date: Fri, 25 Oct 2013 12:32:57 +0100 Subject: [PATCH] Move stripcomments from the classictools plugin into the core It's a bit of a hack for the moment. The plan is to implement stripcomments via the macro mechanism, at which point it can move back into the plugin. --- core/modules/new_widgets/view.js | 15 ++++++ nbld.sh | 11 ++++ .../classictools/modules/stripcomments.js | 54 ------------------- 3 files changed, 26 insertions(+), 54 deletions(-) delete mode 100644 plugins/tiddlywiki/classictools/modules/stripcomments.js diff --git a/core/modules/new_widgets/view.js b/core/modules/new_widgets/view.js index 5294b8e15..b87a8a088 100755 --- a/core/modules/new_widgets/view.js +++ b/core/modules/new_widgets/view.js @@ -61,6 +61,9 @@ ViewWidget.prototype.execute = function() { case "relativedate": this.text = this.getValueAsRelativeDate(); break; + case "stripcomments": + this.text = this.getValueAsStrippedComments(); + break; default: // "text" this.text = this.getValueAsText(); break; @@ -138,6 +141,18 @@ ViewWidget.prototype.getValueAsRelativeDate = function(format) { } }; +ViewWidget.prototype.getValueAsStrippedComments = function() { + var lines = this.getValueAsText().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"); +}; + /* Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering */ diff --git a/nbld.sh b/nbld.sh index 46a4235c2..e89aa8f9b 100755 --- a/nbld.sh +++ b/nbld.sh @@ -53,6 +53,17 @@ node ./tiddlywiki.js \ --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/codemirrordemo.html text/plain \ || exit 1 +# cook the TiddlyWiki 2.x.x index file + +node ./tiddlywiki.js \ + editions/tw2 \ + --verbose \ + --load editions/tw2/source/tiddlywiki.com/index.html.recipe \ + --new_rendertiddler $:/core/templates/tiddlywiki2.template.html ./tmp/tw2/index.html text/plain \ + || exit 1 + +opendiff tmp/tw2/index.html editions/tw2/target/pre-widgetredux2.html + # Run tests ./test.sh diff --git a/plugins/tiddlywiki/classictools/modules/stripcomments.js b/plugins/tiddlywiki/classictools/modules/stripcomments.js deleted file mode 100644 index 956649f53..000000000 --- a/plugins/tiddlywiki/classictools/modules/stripcomments.js +++ /dev/null @@ -1,54 +0,0 @@ -/*\ -title: $:/plugins/tiddlywiki/classictools/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,[{ - type: "text", - text: value - }]); -}; - -exports.stripcomments = StripCommentsViewer; - -})();