1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-14 00:09:42 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/filters/syntax/Cascade Filter Run Prefix (Examples).tid
Mario Pietsch a49436160d
Improve Filter Syntax documentation (#7368)
* Improve Filter Syntax documentaion / navigation

* update links and missing diagrams

* rename legacy prefix to shortcut prefix

* Update editions/tw5.com/tiddlers/filters/Filter Operators.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/And Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Sort Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/Cascade Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* Update editions/tw5.com/tiddlers/filters/syntax/And Filter Run Prefix.tid

Co-authored-by: yaisog <m@rcuswinter.de>

* add most changes a suggested by yaisog

* fix copy / paste from-version

* replace operand with parameter in the docs

* fix typo

* fix typos and improve railroad diagrams consistency

* move "new from version" info for filter run prefixes below the table

* fix typo transclusion and substitution

* Move Filters tiddler to the top level in the TOC

* wip-breadcrumbs

* breadcrumbs & breadcrumbsList macro final

* remove files that do not belong to this PR

* restore release banner

* add simple / story mode to breadcrumbs

* .breadcrumbs macro update comments

* new breadcrumbs CSS, woks with small screens

* make CSS configurable using hidden-settings

* improve CSS fro small screens

* remove the initial: recursiveParentTag macro

* improve location info for breadcrumbs nav. add "alt-text" for Edge ::after element

* breadcrumbs add mode=field

* bc add initial docs

* breadcrumbsField will also respect the story ordering

* add configurable global filterMode setting

* improve arrow CSS for browser zooming

* add bc links use bc-caption if caption field is non-empty

* breadcrumbs improve comments

* breadcrumbs aria-lable uses caption if there is one

* breadcrumbs improve documentation

* breadcrumbs improve docs for sort param

* fix showArrows docs

* remove .bc-link aria-label .. it's not needed if caption is resolved properly

* use subfilter instead of enlist to evaluate the "excluded" variable. Be consistent with toc-macros

* remove breadcrumbs macros - they have their own PR now

* resolve conflict

* add back doc-macros tiddler

* integrate :then filter run prefix

* remove .breadcrumbs macros and their config tiddlers

* fix typos as requested

---------

Co-authored-by: yaisog <m@rcuswinter.de>
2024-02-14 17:20:32 +01:00

46 lines
2.8 KiB
Plaintext

created: 20211130114857532
filter1: [prefix[ca]then[ca]]
filter2: [suffix[at]then[at]]
filter3: other
modified: 20230305125250563
tags: [[Cascade Filter Run Prefix]]
title: Cascade Filter Run Prefix (Examples)
type: text/vnd.tiddlywiki
The <<.op ":cascade">> filter run prefix is used by the ~TiddlyWiki core to choose the colour for each tiddler as used in the tag pill generated by the tag macro.
`:cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]]`
The filter expression inside the above <<.op :cascade>> filter run returns a list of filters from the text fields of tiddlers tagged <<tag $:/tags/TiddlerColourFilter>> as shown below:
<ul>
<$list filter="[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]]">
<li><pre><$text text=<<currentTiddler>>/></pre></li>
</$list>
</ul>
For each input title, each of these filters is now applied to in turn until the first filter that returns a non-empty list. The first result from this non-empty list replaces that input title and is used as the colour for that tiddler.
<<.operator-example 1 """[all[shadows+tiddlers]] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] +[!is[blank]limit[10]]""">>
!! Extended example
This example illustrates step-by-step how the <<.op :cascade>> filter run works.
A filter expression whose output returns a list of filters is required. Typically such a filter expression will construct the list of filters by querying some field in a set of tiddlers (likely via tag). To keep this example self-contained, 3 filters are stored in the //filter1//, //filter2// and //filter3// fields of this tiddler. [[Text references|TextReference]] and instances of the [[append operator|append Operator]] are used to combine the fields into a list of filters.
The filter `[{!!filter1}append{!!filter2}append{!!filter3}]`, generates this list of filters:
<ul>
<$list filter="[{!!filter1}append{!!filter2}append{!!filter3}]">
<li><pre><$text text=<<currentTiddler>>/></pre></li>
</$list>
</ul>
For this example, `cat can bat bug` will be used as the input titles. Each input title will be evaluated by <<.op :cascade>> against each of the above filters in turn. To help understand what <<.op :cascade>> sees internally, the following table uses the [[Map Filter Run Prefix]] to show the result of each individual filter.
|^<<.operator-example c1.1 "cat can bat bug :map[prefix[ca]then[ca]]">>|^<<.operator-example c1.2 "cat can bat bug :map[suffix[at]then[at]]">>|^<<.operator-example c1.3 "cat can bat bug :map[[other]]">>|
Click "Try it" on the above 3 examples. The first non-blank value from each row as read from left to right will be returned when <<.op :cascade>> is used. Click "Try it" below to see the final result:
<<.operator-example c1.4 "cat can bat bug :cascade[{!!filter1}append{!!filter2}append{!!filter3}]">>