From cffe9375b28865ec0da84893e76a92e5d133ff68 Mon Sep 17 00:00:00 2001 From: David Jade Date: Wed, 11 Dec 2013 12:45:35 -0800 Subject: [PATCH] Added TiddlyIE and FSO saver modules Modified tiddlywiki5 template to support TiddlyIE and HTAs Added empty.hta creation to bld scripts Added TiddlyIE topics --- bld.cmd | 1 + bld.sh | 1 + core/modules/savers/fsosaver.js | 75 +++++++++++++++++++ core/modules/savers/tiddlyie.js | 73 ++++++++++++++++++ core/templates/MOTW.html.tid | 5 ++ core/templates/tiddlywiki5.html.tid | 2 + .../tw5.com/tiddlers/definitions/TiddlyIE.tid | 9 +++ .../tiddlers/saving/Saving with TiddlyIE.tid | 19 +++++ 8 files changed, 185 insertions(+) create mode 100644 core/modules/savers/fsosaver.js create mode 100644 core/modules/savers/tiddlyie.js create mode 100644 core/templates/MOTW.html.tid create mode 100644 editions/tw5.com/tiddlers/definitions/TiddlyIE.tid create mode 100644 editions/tw5.com/tiddlers/saving/Saving with TiddlyIE.tid diff --git a/bld.cmd b/bld.cmd index f651f8983..0c730a7e9 100644 --- a/bld.cmd +++ b/bld.cmd @@ -38,6 +38,7 @@ node .\tiddlywiki.js ^ --rendertiddler ReadMe .\readme.md text/html ^ --rendertiddler ContributingTemplate .\contributing.md text/html ^ --rendertiddler $:/editions/tw5.com/download-empty %TW5_BUILD_OUTPUT%\empty.html text/plain ^ + --rendertiddler $:/editions/tw5.com/download-empty %TW5_BUILD_OUTPUT%\empty.hta text/plain ^ --rendertiddler $:/core/templates/static.template.html %TW5_BUILD_OUTPUT%\static.html text/plain ^ --rendertiddler $:/core/templates/static.template.css %TW5_BUILD_OUTPUT%\static\static.css text/plain ^ --rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html %TW5_BUILD_OUTPUT%\static text/plain ^ diff --git a/bld.sh b/bld.sh index 74ded65cc..f41e2e2ba 100755 --- a/bld.sh +++ b/bld.sh @@ -39,6 +39,7 @@ node ./tiddlywiki.js \ --rendertiddler ReadMe ./readme.md text/html \ --rendertiddler ContributingTemplate ./contributing.md text/html \ --rendertiddler $:/editions/tw5.com/download-empty $TW5_BUILD_OUTPUT/empty.html text/plain \ + --rendertiddler $:/editions/tw5.com/download-empty $TW5_BUILD_OUTPUT/empty.hta text/plain \ --rendertiddler $:/core/templates/static.template.html $TW5_BUILD_OUTPUT/static.html text/plain \ --rendertiddler $:/core/templates/static.template.css $TW5_BUILD_OUTPUT/static/static.css text/plain \ --rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html $TW5_BUILD_OUTPUT/static text/plain \ diff --git a/core/modules/savers/fsosaver.js b/core/modules/savers/fsosaver.js new file mode 100644 index 000000000..b036f3b88 --- /dev/null +++ b/core/modules/savers/fsosaver.js @@ -0,0 +1,75 @@ +/*\ +title: $:/core/modules/savers/fsosaver.js +type: application/javascript +module-type: saver + +Handles saving changes via MS FileSystemObject ActiveXObject + +Note: Since TiddlyWiki's markup contains the MOTW, the FileSystemObject normally won't be available. +However, if the wiki is loaded as an .HTA file (Windows HTML Applications) then the FSO can be used. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Select the appropriate saver module and set it up +*/ +var FSOSaver = function(wiki) { +}; + +FSOSaver.prototype.save = function(text,method,callback) { + // Bail out unless this is a save (rather than a download) + if(method !== "save") { + return false; + } + // Get the pathname of this document + var pathname = unescape(document.location.pathname); + // Test for a Windows path of the form /x:\blah... + if(/^\/[A-Z]\:\\[^\\]+/i.test(pathname)) { // ie: ^/[a-z]:/[^/]+ + // Remove the leading slash + pathname = pathname.substr(1); + } else if (document.location.hostname !== "" && /^\/\\[^\\]+\\[^\\]+/i.test(pathname)) { // test for \\server\share\blah... - ^/[^/]+/[^/]+ + // Remove the leading slash + pathname = pathname.substr(1); + // reconstruct UNC path + pathname = "\\\\" + document.location.hostname + pathname; + } else return false; + + // Save the file (as UTF-16) + var fso = new ActiveXObject("Scripting.FileSystemObject"); + var file = fso.OpenTextFile(pathname,2,-1,-1); + + file.Write(text); + file.Close(); + return true; +}; + +/* +Information about this saver +*/ +FSOSaver.prototype.info = { + name: "FSOSaver", + priority: 120 +}; + +/* +Static method that returns true if this saver is capable of working +*/ +exports.canSave = function(wiki) { + try { + return (window.location.protocol === "file:") && !!(new ActiveXObject("Scripting.FileSystemObject")); + } catch(e) { return false; } +}; + +/* +Create an instance of this saver +*/ +exports.create = function(wiki) { + return new FSOSaver(wiki); +}; + +})(); diff --git a/core/modules/savers/tiddlyie.js b/core/modules/savers/tiddlyie.js new file mode 100644 index 000000000..8ba5daba0 --- /dev/null +++ b/core/modules/savers/tiddlyie.js @@ -0,0 +1,73 @@ +/*\ +title: $:/core/modules/savers/tiddlyie.js +type: application/javascript +module-type: saver + +Handles saving changes via Internet Explorer BHO extenion (TiddlyIE) + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Select the appropriate saver module and set it up +*/ +var TiddlyIESaver = function(wiki) { +}; + +TiddlyIESaver.prototype.save = function(text,method,callback) { + // Bail out unless this is a save (rather than a download) + if(method !== "save") { + return false; + } + // check existence of TiddlyIE BHO extension (note: only works after document is complete) + if(typeof(window.TiddlyIE) != "undefined") { + // Get the pathname of this document + var pathname = unescape(document.location.pathname); + // Test for a Windows path of the form /x:/blah... + if(/^\/[A-Z]\:\/[^\/]+/i.test(pathname)) { // ie: ^/[a-z]:/[^/]+ (is this better?: ^/[a-z]:/[^/]+(/[^/]+)*\.[^/]+ ) + // Remove the leading slash + pathname = pathname.substr(1); + // Convert slashes to backslashes + pathname = pathname.replace(/\//g,"\\"); + } else if(document.hostname !== "" && /^\/[^\/]+\/[^\/]+/i.test(pathname)) { // test for \\server\share\blah... - ^/[^/]+/[^/]+ + // Convert slashes to backslashes + pathname = pathname.replace(/\//g,"\\"); + // reconstruct UNC path + pathname = "\\\\" + document.location.hostname + pathname; + } else return false; + + // Prompt the user to save the file + window.TiddlyIE.save(pathname, text); + return true; + } else { + return false; + } +}; + +/* +Information about this saver +*/ +TiddlyIESaver.prototype.info = { + name: "tiddlyiesaver", + priority: 1500 +}; + +/* +Static method that returns true if this saver is capable of working +*/ +exports.canSave = function(wiki) { + return (window.location.protocol === "file:"); +}; + +/* +Create an instance of this saver +*/ +exports.create = function(wiki) { + return new TiddlyIESaver(wiki); +}; + +})(); diff --git a/core/templates/MOTW.html.tid b/core/templates/MOTW.html.tid new file mode 100644 index 000000000..150383bad --- /dev/null +++ b/core/templates/MOTW.html.tid @@ -0,0 +1,5 @@ +title: $:/core/templates/MOTW.html + +\rules only filteredtranscludeinline transcludeinline entity + + \ No newline at end of file diff --git a/core/templates/tiddlywiki5.html.tid b/core/templates/tiddlywiki5.html.tid index 26eb03fa5..c6cb9f2f1 100644 --- a/core/templates/tiddlywiki5.html.tid +++ b/core/templates/tiddlywiki5.html.tid @@ -2,8 +2,10 @@ title: $:/core/templates/tiddlywiki5.html \rules only filteredtranscludeinline transcludeinline +{{$:/core/templates/MOTW.html}} + diff --git a/editions/tw5.com/tiddlers/definitions/TiddlyIE.tid b/editions/tw5.com/tiddlers/definitions/TiddlyIE.tid new file mode 100644 index 000000000..3d355063e --- /dev/null +++ b/editions/tw5.com/tiddlers/definitions/TiddlyIE.tid @@ -0,0 +1,9 @@ +created: 20131211220000000 +modified: 20131211224200000 +tags: definitions +title: TiddlyIE +type: text/vnd.tiddlywiki + +TiddlyIE is an extension for Internet Explorer that allows standalone TiddlyWiki files to save their changes directly to the file system. TiddlyIE works with the desktop version of Internet Explorer. + +See [[Saving with TiddlyIE]]. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/saving/Saving with TiddlyIE.tid b/editions/tw5.com/tiddlers/saving/Saving with TiddlyIE.tid new file mode 100644 index 000000000..4ce52c17b --- /dev/null +++ b/editions/tw5.com/tiddlers/saving/Saving with TiddlyIE.tid @@ -0,0 +1,19 @@ +created: 20131211220000000 +modified: 20131211224900000 +tags: howto +title: Saving with TiddlyIE +type: text/vnd.tiddlywiki + +# Install the TiddlyIE add-on from: +#* https://github.com/davidjade/TiddlyIE/releases +# Restart Internet Explorer. IE will prompt you to enable the TiddlyIE add-on. +#> You may also see a prompt to enable the //Microsoft Script Runtime// +# [[Download]] an empty TiddlyWiki by clicking this button: +#> {{$:/editions/tw5.com/snippets/download-empty-button}} +#> Your browser may ask you to accept the download before it begins +# Locate the file you just downloaded +#* You may rename it, but be sure to keep the `.html` extension +# Open the file in Internet Explorer +# Try creating a new tiddler using the ''plus'' {{$:/core/images/new-button}} button in the sidebar. Type some content for the tiddler, and click the {{$:/core/images/done-button}} ''tick'' button +# Save your changes by clicking the {{$:/core/images/save-button}} ''download'' button in the sidebar. Internet Explorer will ask for your consent to save the file locally by presenting a file ''Save As'' dialog. +# Refresh the browser window to verify that your changes have been saved correctly