Use $:/AdvancedSearch>Filters to create plugins and "importers"

I’m pleased to announce TiddlyTools/Search/SaveAs, that adds “save as plugin” and “save as importer” buttons to the $:/AdvancedSearch>Filters tab.

Start by entering or selecting a filter in the $:/AdvancedSearch>Filters tab. When matching tiddlers are found, “save as plugin” and “save as importer” buttons will appear. Pressing either button displays a popup. In the popup:

  • Enter a new plugin title or press the “list” icon to select an existing plugin title
  • Enter optional plugin fields such as author, name, description, source, etc.
  • You can enable the “add matching tiddlers to existing plugin” checkbox to update the contents of an existing plugin; otherwise, its contents will be replaced
  • Press the “done” (checkmark) button to create the plugin tiddler. If it already exists, you will be asked to confirm before it is overwritten
  • If a plugin tiddler does not contain javascript tiddlers its shadow tiddlers will be immediately available; otherwise, you must save-and-reload for the plugin to be “unpacked” at startup

Alternatively, you can create an “importer” that is similar to a plugin in that it contains a set of tiddlers stored as a JSON object, but works like a snapshot of a TWCore standard $:/Import tiddler.

Instead of installing shadow tiddlers at startup, the set of tiddlers remains “frozen” in the importer tiddler until you view that tiddler and press the “import” button to complete the process and unpack its contents as REAL tiddlers. Note that when an importer tiddler is unpacked, it’s contents are automatically replaced with the same kind of “status” output as the TWCore’s $:/Import tiddler.

Also note that if your filter results include any existing plugins or importers, the contents of those tiddlers will be merged into the new plugin or importer. You can use this feature to combine existing plugins and importers, or convert plugins to importers, or vice versa

enjoy,
-e

7 Likes

Comprehensive indeed. Kudos @EricShulman

@EricShulman This is a fantastic utility that will save me a LOT of time. With the recent discussions of using JSON data structures and limitations around filter operators there, I think packaging content as plugins as you’ve made easy here is going to often be the right alternative.

I’m trying to figure out what the checkbox for “add tiddlers to existing plugin” actually does - as it seems to work both with and without that checkbox being used and it’s bugging me not knowing what difference it makes.

Suppose you do a filter search and get one result, “TiddlerX”. Then, you use “save as plugin” to create a new plugin named “MyPlugin”. Since you are creating a new plugin tiddler, it will be empty to start with, so enabling “add tiddlers to existing plugin” has no effect, and the resulting “MyPlugin” tiddler will contain just “TiddlerX”.

Then suppose you do another filter search and get one result, “TiddlerY”, and use “save as plugin” and enter (or select) “MyPlugin” as the target tiddler.

Without enabling the “add tiddlers to existing plugin” checkbox, the current contents of “MyPlugin” will be replaced, and the resulting “MyPlugin” tiddler will contain just “TiddlerY”.

However, if you enable the “add tiddlers to existing plugin” checkbox, the “TiddlerY” search result will be merged with the current contents of “MyPlugin”, and the resulting “MyPlugin” tiddler will contain both “TiddlerX” and “TiddlerY”.

Thus, the effect of the “add tiddlers to existing plugin” checkbox is that it lets you perform a series of separate filter searches and incrementally collect the results into a single plugin tiddler.

-e

Ah - I feel silly now, for some reason it hadn’t even occurred to me to try it without the plugin itself or it’s shadow tiddlers as part of the filter. Makes perfect sense.

As you’ve noted, you can also add to an existing plugin tiddler simply by including the plugin tiddler title as part of the filter itself. However, for some complex filters, that might not be possible, or at least not practical.

Also, if you are using a saved filter definition, you might not remember to add the name of the plugin tiddler to the end of the filter, so writing to the existing plugin will wind up discarding all the previously packed tiddlers.

-e

Two small updates to TiddlyTools/Serch/SaveAs:

  • when generating the target tiddler, use format:json<tab> to “pretty-print” the JSON output
  • if “[x] add to existing…” is checked and the target tiddler does not yet exist, prevent it from adding an “empty” item in the target tiddler’s JSON output

-e

1 Like