1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Add unusedtitle macro (#3880)

* Add uniquetitle macro

This macro is a wrapper on the $tw.wiki.generateNewTitle function to return a unique name, it has been requested multiple times in the forums.

* Add documentation tiddler for uniquetitle macro

* Add uniquetitle macro examples

* Change name from uniquetitle to unusedtitle for clarity

The title isn't unique, just not currently used in the wiki.

* Update uniquetitle to unusedtitle

* Change uniquetitle to unusedtitle

* Fix a typo
This commit is contained in:
jed 2019-03-26 22:57:58 +01:00 committed by Jeremy Ruston
parent d38b42f7c7
commit b1edcdb757
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/*\
title: $:/core/modules/macros/unusedtitle.js
type: application/javascript
module-type: macro
Macro to return a new title that is unused in the wiki. It can be given a name as a base.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "unusedtitle";
exports.params = [
{name: "baseName"},
{name: "options"}
];
/*
Run the macro
*/
exports.run = function(baseName, options) {
if(!baseName) {
baseName = $tw.language.getString("DefaultNewTiddlerTitle");
}
return this.wiki.generateNewTitle(baseName, options);
};
})();

View File

@ -0,0 +1,16 @@
caption: unusedtitle
tags: Macros [[Core Macros]]
title: unusedtitle Macro
type: text/vnd.tiddlywiki
The <<.def unusedtitle>> [[macro|Macros]] returns an unused title. Optionally you can provide a base title to generate the new title.
It uses the same method as the create new tiddler button, a number is appended to the end of the base name.
!! Parameters
;baseName
: A string specifying the desired base name, defaulting to `New Tiddler`
<<.macro-examples "unusedtitle">>

View File

@ -0,0 +1,7 @@
tags: [[unusedtitle Macro]] [[Macro Examples]]
title: unusedtitle Macro (Examples)
type: text/vnd.tiddlywiki
<$macrocall $name=".example" n="1" eg="""<<unusedtitle>>"""/>
<$macrocall $name=".example" n="2" eg="""<<unusedtitle AnotherBase>>"""/>
<$macrocall $name=".example" n="3" eg="""<<unusedtitle TiddlyWiki>>"""/>