From 4049affb3172c0ada1eee4ef4e905cbb7ee92dc5 Mon Sep 17 00:00:00 2001 From: James Welford Anderson Date: Tue, 3 Feb 2015 07:30:24 +0900 Subject: [PATCH 1/3] initial pass at static export macros --- core/modules/commands/rendertiddlers.js | 12 +++++++++--- core/modules/widgets/link.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/modules/commands/rendertiddlers.js b/core/modules/commands/rendertiddlers.js index d02d98417..fabbeb035 100644 --- a/core/modules/commands/rendertiddlers.js +++ b/core/modules/commands/rendertiddlers.js @@ -35,7 +35,8 @@ Command.prototype.execute = function() { wiki = this.commander.wiki, filter = this.params[0], template = this.params[1], - pathname = path.resolve(this.commander.outputPath,this.params[2]), + outputPath = this.commander.outputPath, + pathname = path.resolve(outputPath,this.params[2]), type = this.params[3] || "text/html", extension = this.params[4] || ".html", deleteDirectory = (this.params[5] || "") != "noclean", @@ -43,14 +44,19 @@ Command.prototype.execute = function() { if(deleteDirectory){ $tw.utils.deleteDirectory(pathname); } - $tw.utils.createDirectory(pathname); $tw.utils.each(tiddlers,function(title) { var parser = wiki.parseTiddler(template), widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}}); var container = $tw.fakeDocument.createElement("div"); widgetNode.render(container,null); var text = type === "text/html" ? container.innerHTML : container.textContent; - fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8"); + var export_path = null; + if($tw.utils.hop($tw.macros,"tv-get-export-path")) { + export_path = $tw.macros["tv-get-export-path"].run.apply(self,[title]); + } + var final_path = path.resolve(outputPath,(export_path || encodeURIComponent(title)) + extension); + $tw.utils.createDirectory(path.dirname(final_path)); + fs.writeFileSync(final_path,text,"utf8"); }); return null; }; diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index eac53a050..0088d5134 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -76,7 +76,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"), wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$", wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to)); - wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); + wikiLinkText = this.getVariable("tv-get-export-link") || wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); domNode.setAttribute("href",wikiLinkText); // Set the tooltip // HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/>" From 0b68428bc5bc6b5625188f91d1ad3df222111e56 Mon Sep 17 00:00:00 2001 From: James Welford Anderson Date: Tue, 10 Feb 2015 05:59:56 +0900 Subject: [PATCH 2/3] add image export path macro --- core/modules/widgets/image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/widgets/image.js b/core/modules/widgets/image.js index afa8b447b..c56726609 100644 --- a/core/modules/widgets/image.js +++ b/core/modules/widgets/image.js @@ -52,7 +52,7 @@ ImageWidget.prototype.render = function(parent,nextSibling) { tiddler = this.wiki.getTiddler(this.imageSource); if(!tiddler) { // The source isn't the title of a tiddler, so we'll assume it's a URL - src = this.imageSource; + src = this.getVariable("tv-get-export-image-link") || this.imageSource; } else { // Check if it is an image tiddler if(this.wiki.isImageTiddler(this.imageSource)) { From d1809f352c372daa22b4c587416369145a74d01d Mon Sep 17 00:00:00 2001 From: "James W. Anderson" Date: Tue, 17 Feb 2015 07:11:00 +0900 Subject: [PATCH 3/3] explicitly pass through source params from the image/link widget to the respective static export macros --- core/modules/widgets/image.js | 2 +- core/modules/widgets/link.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/widgets/image.js b/core/modules/widgets/image.js index c56726609..47618aad8 100644 --- a/core/modules/widgets/image.js +++ b/core/modules/widgets/image.js @@ -52,7 +52,7 @@ ImageWidget.prototype.render = function(parent,nextSibling) { tiddler = this.wiki.getTiddler(this.imageSource); if(!tiddler) { // The source isn't the title of a tiddler, so we'll assume it's a URL - src = this.getVariable("tv-get-export-image-link") || this.imageSource; + src = this.getVariable("tv-get-export-image-link",{params: [{name: "src",value: this.imageSource}],defaultValue: this.imageSource}) || this.imageSource; } else { // Check if it is an image tiddler if(this.wiki.isImageTiddler(this.imageSource)) { diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index 0088d5134..36ee98fa2 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -76,7 +76,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"), wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$", wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to)); - wikiLinkText = this.getVariable("tv-get-export-link") || wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); + wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: this.to}) || wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); domNode.setAttribute("href",wikiLinkText); // Set the tooltip // HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/>"