From c4244e8f0493a2d58c3a92ef6939a7029c599bff Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 1 Sep 2015 17:25:45 +0100 Subject: [PATCH] Text-slicer improvements # Allow the slicer to be used as a command # Sort the document preview column --- .../modules/commands/help-slice.tid | 8 ++++ .../text-slicer/modules/commands/slice.js | 44 +++++++++++++++++++ .../tiddlywiki/text-slicer/modules/slicer.js | 20 ++------- .../modules/startup/slicer-message.js | 31 +++++++++++++ .../text-slicer/ui/preview-column.tid | 2 +- 5 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 plugins/tiddlywiki/text-slicer/modules/commands/help-slice.tid create mode 100644 plugins/tiddlywiki/text-slicer/modules/commands/slice.js create mode 100644 plugins/tiddlywiki/text-slicer/modules/startup/slicer-message.js diff --git a/plugins/tiddlywiki/text-slicer/modules/commands/help-slice.tid b/plugins/tiddlywiki/text-slicer/modules/commands/help-slice.tid new file mode 100644 index 000000000..e4c14fa25 --- /dev/null +++ b/plugins/tiddlywiki/text-slicer/modules/commands/help-slice.tid @@ -0,0 +1,8 @@ +title: $:/language/Help/slice +description: Slice a hierarchical document into individual tiddlers + +Slices the specified tiddler + +``` +--slice +``` diff --git a/plugins/tiddlywiki/text-slicer/modules/commands/slice.js b/plugins/tiddlywiki/text-slicer/modules/commands/slice.js new file mode 100644 index 000000000..29db5892a --- /dev/null +++ b/plugins/tiddlywiki/text-slicer/modules/commands/slice.js @@ -0,0 +1,44 @@ +/*\ +title: $:/plugins/tiddlywiki/text-slicer/modules/commands/slice.js +type: application/javascript +module-type: command + +Command to slice a specified tiddler + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var widget = require("$:/core/modules/widgets/widget.js"); + +exports.info = { + name: "slice", + synchronous: true +}; + +var Command = function(params,commander,callback) { + this.params = params; + this.commander = commander; + this.callback = callback; +}; + +Command.prototype.execute = function() { + if(this.params.length < 1) { + return "Missing parameters"; + } + var self = this, + wiki = this.commander.wiki, + tiddlerTitle = this.params[0], + slicer = new $tw.Slicer(wiki,tiddlerTitle); + slicer.sliceTiddler(tiddlerTitle) + slicer.outputTiddlers(); + slicer.destroy(); + return null; +}; + +exports.Command = Command; + +})(); diff --git a/plugins/tiddlywiki/text-slicer/modules/slicer.js b/plugins/tiddlywiki/text-slicer/modules/slicer.js index bbd51c0a5..70045f3a2 100644 --- a/plugins/tiddlywiki/text-slicer/modules/slicer.js +++ b/plugins/tiddlywiki/text-slicer/modules/slicer.js @@ -1,7 +1,7 @@ /*\ title: $:/plugins/tiddlywiki/text-slicer/modules/slicer.js type: application/javascript -module-type: startup +module-type: global Setup the root widget event handlers @@ -12,24 +12,8 @@ Setup the root widget event handlers /*global $tw: false */ "use strict"; -// Export name and synchronous status -exports.name = "slicer"; -exports.platforms = ["browser"]; -exports.after = ["startup"]; -exports.synchronous = true; - var SLICER_OUTPUT_TITLE = "$:/TextSlicer"; -// Install the root widget event handlers -exports.startup = function() { - $tw.rootWidget.addEventListener("tm-slice-tiddler",function(event) { - var slicer = new Slicer($tw.wiki,event.param); - slicer.sliceTiddler(event.param) - slicer.outputTiddlers(); - slicer.destroy(); - }); -}; - function Slicer(wiki,sourceTitle) { this.wiki = wiki; this.sourceTitle = sourceTitle; @@ -283,4 +267,6 @@ Slicer.prototype.outputTiddlers_viaImportTiddler = function(tiddlers) { this.wiki.addTiddler(new $tw.Tiddler(slicerOutputTiddler,newFields)); }; +exports.Slicer = Slicer; + })(); diff --git a/plugins/tiddlywiki/text-slicer/modules/startup/slicer-message.js b/plugins/tiddlywiki/text-slicer/modules/startup/slicer-message.js new file mode 100644 index 000000000..2a38d6a05 --- /dev/null +++ b/plugins/tiddlywiki/text-slicer/modules/startup/slicer-message.js @@ -0,0 +1,31 @@ +/*\ +title: $:/plugins/tiddlywiki/text-slicer/modules/startup/slicer.js +type: application/javascript +module-type: startup + +Setup the root widget event handlers + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +// Export name and synchronous status +exports.name = "slicer"; +exports.platforms = ["browser"]; +exports.after = ["startup"]; +exports.synchronous = true; + +// Install the root widget event handlers +exports.startup = function() { + $tw.rootWidget.addEventListener("tm-slice-tiddler",function(event) { + var slicer = new $tw.Slicer($tw.wiki,event.param); + slicer.sliceTiddler(event.param) + slicer.outputTiddlers(); + slicer.destroy(); + }); +}; + +})(); diff --git a/plugins/tiddlywiki/text-slicer/ui/preview-column.tid b/plugins/tiddlywiki/text-slicer/ui/preview-column.tid index da0fbfcdd..78824e6f3 100644 --- a/plugins/tiddlywiki/text-slicer/ui/preview-column.tid +++ b/plugins/tiddlywiki/text-slicer/ui/preview-column.tid @@ -5,7 +5,7 @@ tags: $:/tags/AboveStory <$set name="tv-default-heading-state" value="closed"> -<$list filter="[toc-type[document]!has[draft.of]]" template="$:/plugins/tiddlywiki/text-slicer/templates/interactive/document"/> +<$list filter="[toc-type[document]!has[draft.of]sort[title]]" template="$:/plugins/tiddlywiki/text-slicer/templates/interactive/document"/> </$set>