mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-25 23:03:15 +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:
parent
d38b42f7c7
commit
b1edcdb757
34
core/modules/macros/uniquetitle.js
Normal file
34
core/modules/macros/uniquetitle.js
Normal 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);
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
16
editions/tw5.com/tiddlers/macros/UnusedTitleMacro.tid
Normal file
16
editions/tw5.com/tiddlers/macros/UnusedTitleMacro.tid
Normal 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">>
|
|
@ -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>>"""/>
|
Loading…
Reference in New Issue
Block a user