{"tiddlers":{"$:/plugins/flibbles/relink-titles/configuration":{"title":"$:/plugins/flibbles/relink-titles/configuration","caption":"{{$:/plugins/flibbles/relink-titles/language/Caption}}","tags":"$:/tags/flibbles/relink/Configuration","list-after":"","text":"\\define lingo-base() $:/plugins/flibbles/relink-titles/language/\n\\define prefix() $:/config/flibbles/relink-titles/relink/\n\\whitespace trim\n\n<div class=\"tc-control-panel\">\n\n<<lingo Help>>\n\n<table>\n<tbody>\n<$list filter=\"[[relinktitlesrule]modules[]]\">\n<tr>\n<td>\n<$checkbox\n\ttiddler={{{ [all[current]addprefix<prefix>] }}}\n\tfield=\"text\"\n\tchecked=\"enabled\"\n\tunchecked=\"disabled\"\n\tdefault=\"enabled\">\n&#32;\n''{{!!caption}}''\n</$checkbox></td><td>\n\n<$transclude field='description' />\n\n</td></tr></$list>\n</tbody></table></div>\n"},"$:/plugins/flibbles/relink-titles/language/Caption":{"title":"$:/plugins/flibbles/relink-titles/language/Caption","text":"Titles"},"$:/plugins/flibbles/relink-titles/language/Directory/Caption":{"title":"$:/plugins/flibbles/relink-titles/language/Directory/Caption","text":"Rename subdirectories"},"$:/plugins/flibbles/relink-titles/language/Directory/Description":{"title":"$:/plugins/flibbles/relink-titles/language/Directory/Description","text":"For wikis set up hierarchically using `/`, like a filesystem. This option will update all tiddlers nested inside the target tiddler. i.e. `fromTiddler/path/file` becomes `toTiddler/path/file`."},"$:/plugins/flibbles/relink-titles/language/Lookup/Caption":{"title":"$:/plugins/flibbles/relink-titles/language/Lookup/Caption","text":"Lookup tiddlers"},"$:/plugins/flibbles/relink-titles/language/Help":{"title":"$:/plugins/flibbles/relink-titles/language/Help","text":"See the <a href={{{ [{$:/plugins/flibbles/relink-titles!!demo}addsuffix[#Plugins/Titles]] }}} class=\"tc-tiddlylink-external\">//Relink-titles// documentation page</a> for details."},"$:/plugins/flibbles/relink-titles/readme":{"title":"$:/plugins/flibbles/relink-titles/readme","text":"Highly customizable relinking of tiddler titles //related// to the renamed tiddler.\n\n* Rename a hierarchy of subtiddlers when renaming a root tiddler.\n* Make custom filter rules to rename other tiddlers the way you want when Relinking.\n* Integrates with other plugins for plugin-specific rules.\n\nSee <a href={{$:/plugins/flibbles/relink-titles!!source}} class=\"tc-tiddlylink-external\">the tw5-relink website</a> for more details and examples.\n\n{{$:/core/images/warning}} ''Warning:'' You must use //Relink// v1.10.2 or greater with this, or this plugin may delete some tiddler bodies while trying to relink titles.\n"},"$:/plugins/flibbles/relink-titles/relinkoperations/title.js":{"title":"$:/plugins/flibbles/relink-titles/relinkoperations/title.js","text":"/*\\\nmodule-type: relinkoperator\ntitle: $:/plugins/flibbles/relink-titles/relinkoperations/title.js\ntype: application/javascript\n\nRenames tiddlers which have titles derived from fromTitle. Then it makes\nsure that those tiddlers are properly relinked too.\n\n\\*/\n\n/*jslint node: false, browser: true */\n/*global $tw: false */\n\"use strict\";\n\nvar configPrefix = \"$:/config/flibbles/relink-titles/relink/\";\nvar utils = require('$:/plugins/flibbles/relink/js/utils.js');\n// This is using hotDirectories, which is a deprecated feature. It should be\n// using the $:/config/flibbles/relink/{cateogory} directory which would be\n// automatically maintained and regenerated.\n// Maybe in time I'll get around to migrating this, but no need to complicate\n// things now with changes that would require migration, and that would\n// have no outward effect.\nutils.getContext('whitelist').hotDirectories.push(configPrefix);\n\nvar titleRules = Object.create(null);\n$tw.modules.forEachModuleOfType('relinktitlesrule', function(title, module) {\n\ttitleRules[title] = module;\n});\n\nexports.name = 'title';\n\nexports.report = function(tiddler, callback, options) {\n\tvar cache = getCache(options),\n\t\trules = cache.rules;\n\tfor (var i = 0; i < rules.length; i++) {\n\t\trules[i].report(tiddler.fields.title, function(title, blurb, style) {\n\t\t\tcallback(title, blurb ? ('title: ' + blurb) : 'title', style);\n\t\t}, options);\n\t}\n};\n\nexports.relink = function(tiddler, fromTitle, toTitle, changes, options) {\n\tvar cache = getCache(options),\n\t\ttitle = tiddler.fields.title;\n\tif (!cache.touched[title]) {\n\t\tvar rules = cache.rules;\n\t\tfor (var i = 0; i < rules.length; i++) {\n\t\t\tvar rule = rules[i];\n\t\t\tvar entry = rule.relink(title, fromTitle, toTitle, options);\n\t\t\tif (entry) {\n\t\t\t\tvar result = entry.output;\n\t\t\t\tif (result && (result !== title)) {\n\t\t\t\t\tif (options.wiki.getTiddler(result) || cache.touched[result]) {\n\t\t\t\t\t\t// There's already a tiddler there. We won't clobber it.\n\t\t\t\t\t\tentry.impossible = true;\n\t\t\t\t\t\tentry.output = undefined;\n\t\t\t\t\t}\n\t\t\t\t\tcache.touched[result] = true;\n\t\t\t\t}\n\t\t\t\t// Record that we've touched this one, so we only touch it once.\n\t\t\t\t// Both its prior and latter. Neither should be touched again.\n\t\t\t\tcache.touched[title] = true;\n\t\t\t\tchanges.title = entry;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n};\n\nfunction getCache(options) {\n\treturn utils.getCacheForRun(options, 'titles', function() {\n\t\treturn {\n\t\t\trules: getRules(options.wiki),\n\t\t\ttouched: Object.create(null)\n\t\t};\n\t});\n};\n\nfunction getRules(wiki) {\n\tvar activeRules = [];\n\tfor (var rule in titleRules) {\n\t\tvar configTiddler = wiki.getTiddler(configPrefix + rule);\n\t\tif (!configTiddler || configTiddler.fields.text !== \"disabled\") {\n\t\t\tactiveRules.push(titleRules[rule]);\n\t\t}\n\t}\n\treturn activeRules;\n};\n","module-type":"relinkoperator","type":"application/javascript"},"$:/plugins/flibbles/relink-titles/rules/directory":{"title":"$:/plugins/flibbles/relink-titles/rules/directory","text":"/*\\\ncaption: {{$:/plugins/flibbles/relink-titles/language/Directory/Caption}}\ndescription: {{$:/plugins/flibbles/relink-titles/language/Directory/Description}}\nmodule-type: relinktitlesrule\ntitle: $:/plugins/flibbles/relink-titles/rules/directory\ntype: application/javascript\n\nHandles subdirectory renaming.\n\n\\*/\n\n/*jslint node: false, browser: true */\n/*global $tw: false */\n\"use strict\";\n\nexports.name = 'directory';\n\n/**The report returns all parent directories of a given title which exist.\n */\nexports.report = function(title, callback, options) {\n\tvar index = -1;\n\twhile ((index = title.indexOf('/', index+1)) >= 0) {\n\t\tvar dir = title.substr(0, index);\n\t\tcallback(dir, '.' + title.substr(index), {soft: true});\n\t}\n};\n\n/**The relink returns the new title (if any) derived from title for a given\n * rename of fromTitle to toTitle.\n */\nexports.relink = function(title, fromTitle, toTitle, options) {\n\tvar length = fromTitle.length;\n\tif (title.charAt(length) === '/' && title.substr(0, length) === fromTitle) {\n\t\treturn {output: toTitle + title.substr(length)};\n\t}\n\treturn undefined;\n};\n","caption":"{{$:/plugins/flibbles/relink-titles/language/Directory/Caption}}","description":"{{$:/plugins/flibbles/relink-titles/language/Directory/Description}}","module-type":"relinktitlesrule","type":"application/javascript"},"$:/plugins/flibbles/relink-titles/language/Lookup/Description":{"title":"$:/plugins/flibbles/relink-titles/language/Lookup/Description","text":"This option updates all configuration tiddlers which relate to target tiddlers either through fixed prefixes or suffixes, i.e. `$:/config/Buttons/Visibility/fromFile` becomes `$:/config/Buttons/Visibility/toFile` when \"fromFile\" is renamed.\n\nEach line corresponds to a pattern, where `$(currentTiddler)$` would be the name of the tiddler being renamed, and `$(*)$` matches with anything.\n\n<$edit-text\n\ttiddler=\"$:/config/flibbles/relink-titles/lookup/patterns\"\n\ttag=\"textarea\"\n/>\n"},"$:/config/flibbles/relink-titles/lookup/patterns":{"title":"$:/config/flibbles/relink-titles/lookup/patterns","text":"$:/config/$(*)$/Visibility/$(currentTiddler)$\n"},"$:/plugins/flibbles/relink-titles/rules/lookup":{"title":"$:/plugins/flibbles/relink-titles/rules/lookup","text":"/*\\\ncaption: {{$:/plugins/flibbles/relink-titles/language/Lookup/Caption}}\ndescription: {{$:/plugins/flibbles/relink-titles/language/Lookup/Description}}\nmodule-type: relinktitlesrule\ntitle: $:/plugins/flibbles/relink-titles/rules/lookup\ntype: application/javascript\n\nHandles setting tiddlers which are derived from other tiddlers, like how\n\n```\n$:/config/PageControlButtons/Visibility/$(currentTiddler)$\n```\n\nset the visibility for $(currentTiddler)$\n\n\\*/\n\n\"use strict\";\n\nexports.name = 'lookup';\n\nvar patternTiddler = \"$:/config/flibbles/relink-titles/lookup/patterns\";\nvar anyMatcher = /\\$\\((?:\\*|currentTiddler)\\)\\$/g;\n\nexports.report = function(targetTitle, callback, options) {\n\tvar patterns = getPatterns(options.wiki);\n\tfor (var i = 0; i < patterns.length; i++) {\n\t\tvar pattern = patterns[i];\n\t\tvar index = 0;\n\t\tvar results = match(pattern, targetTitle);\n\t\tif (results) {\n\t\t\tvar blurb = pattern.string.replace(anyMatcher, function(match) {\n\t\t\t\tindex++;\n\t\t\t\tif (match === \"$(*)$\") {\n\t\t\t\t\treturn results[index];\n\t\t\t\t} else { // must be \"$(currentTiddler)$\"\n\t\t\t\t\treturn \"...\";\n\t\t\t\t}\n\t\t\t});\n\t\t\tcallback(results.title, blurb);\n\t\t}\n\t}\n};\n\nexports.relink = function(targetTitle, fromTitle, toTitle, options) {\n\tvar patterns = getPatterns(options.wiki);\n\tfor (var i = 0; i < patterns.length; i++) {\n\t\tvar pattern = patterns[i];\n\t\tvar results = match(pattern, targetTitle, fromTitle);\n\t\tif (results) {\n\t\t\tvar groupIndex = 0;\n\t\t\t// Make all the correct substitutions to create the new title\n\t\t\tvar output = pattern.string.replace(anyMatcher, function(match) {\n\t\t\t\tgroupIndex++;\n\t\t\t\tif (match === \"$(*)$\") {\n\t\t\t\t\treturn results[groupIndex];\n\t\t\t\t} else { // must be \"$(currentTiddler)$\"\n\t\t\t\t\treturn toTitle;\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn {output: output};\n\t\t}\n\t}\n\treturn undefined;\n};\n\nfunction match(pattern, string, matchTitle) {\n\tvar results = pattern.matcher.exec(string);\n\tif (results) {\n\t\t// It superficially matches, but we need to make sure all the right\n\t\t// groups match too.\n\t\tfor (var j = 0; j < pattern.groups.length; j++) {\n\t\t\tvar index = pattern.groups[j];\n\t\t\tif (matchTitle === undefined) {\n\t\t\t\t// It doesn't matter what matchTitle is, as long as all\n\t\t\t\t// groups match the same thing.\n\t\t\t\tmatchTitle = results[index];\n\t\t\t} else if (results[index] !== matchTitle) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\tresults.title = matchTitle;\n\t}\n\treturn results;\n};\n\nfunction getPatterns(wiki) {\n\treturn wiki.getCacheForTiddler(patternTiddler, \"relink-titles\", function() {\n\t\tvar text = wiki.getTiddlerText(patternTiddler);\n\t\tvar matchers = []\n\t\tif (text) {\n\t\t\tvar array = text.split('\\n');\n\t\t\tfor (var i = 0; i < array.length; i++) {\n\t\t\t\tvar pattern = formPatternFromString(array[i]);\n\t\t\t\tif (pattern) {\n\t\t\t\t\tmatchers.push(pattern);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn matchers;\n\t});\n};\n\nfunction formPatternFromString(string) {\n\tvar groupIndex = 1;\n\tvar matchingGroups = [];\n\tstring = $tw.utils.trim(string);\n\tvar parts = string.split(\"$(currentTiddler)$\");\n\tif (parts.length <= 1) {\n\t\t// $(currentTiddler)$ must not have been there\n\t\treturn null;\n\t}\n\tfor (var j = 0; j < parts.length; j++) {\n\t\t// Split it up by the wildcards\n\t\tvar sections = parts[j].split(\"$(*)$\");\n\t\tfor (var k = 0; k < sections.length; k++) {\n\t\t\tsections[k] = $tw.utils.escapeRegExp(sections[k]);\n\t\t}\n\t\tparts[j] = sections.join(\"(.*)\");\n\t\t// If there are 3 sections, then there is 2 $(*)$, so the index\n\t\t// must skip them. etc...\n\t\tgroupIndex += sections.length-1;\n\t\tif (j < parts.length-1) {\n\t\t\t// If there are 3 parts, that means 2 $(currentTiddler)$, and\n\t\t\t// so we skip the last part\n\t\t\tmatchingGroups.push(groupIndex);\n\t\t\tgroupIndex++;\n\t\t}\n\t}\n\treturn {\n\t\tstring: string,\n\t\tgroups: matchingGroups,\n\t\tmatcher: new RegExp(\"^\" + parts.join(\"(.*)\") + \"$\")\n\t};\n};\n","caption":"{{$:/plugins/flibbles/relink-titles/language/Lookup/Caption}}","description":"{{$:/plugins/flibbles/relink-titles/language/Lookup/Description}}","module-type":"relinktitlesrule","type":"application/javascript"}}}