1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Tree macro: allow separator to be customised

This commit is contained in:
Jeremy Ruston 2019-06-13 08:47:42 +01:00
parent 23dd8da22c
commit fc09f8e331
4 changed files with 39 additions and 13 deletions

View File

@ -1,11 +1,11 @@
title: $:/core/macros/tree
tags: $:/tags/Macro
\define leaf-link(full-title, chunk)
\define leaf-link(full-title,chunk,separator: "/")
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
\end
\define leaf-node(prefix, chunk)
\define leaf-node(prefix,chunk)
<li>
<$list filter="[<__prefix__>addsuffix<__chunk__>is[shadow]] [<__prefix__>addsuffix<__chunk__>is[tiddler]]" variable="full-title">
<$list filter="[<full-title>removeprefix<__prefix__>]" variable="chunk">
@ -15,7 +15,7 @@ tags: $:/tags/Macro
</li>
\end
\define branch-node(prefix, chunk)
\define branch-node(prefix,chunk,separator: "/")
<li>
<$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$reveal type="nomatch" stateTitle=<<reveal-state>> text="show">
@ -30,28 +30,28 @@ tags: $:/tags/Macro
</$reveal>
<span>(<$count filter="[all[shadows+tiddlers]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>)</span>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}}/>
<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
</$reveal>
</$set>
</li>
\end
\define tree-node(prefix)
\define tree-node(prefix,separator: "/")
<ol>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]!suffix[/]]" variable="chunk">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>>/>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]suffix[/]]" variable="chunk">
<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<<chunk>>/>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]suffix<__separator__>]" variable="chunk">
<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
</ol>
\end
\define tree(prefix: "$:/")
\define tree(prefix: "$:/",separator: "/")
<div class="tc-tree">
<span><$text text=<<__prefix__>>/></span>
<div>
<$macrocall $name="tree-node" prefix=<<__prefix__>>/>
<$macrocall $name="tree-node" prefix=<<__prefix__>> separator=<<__separator__>>/>
</div>
</div>
\end

View File

@ -6,3 +6,6 @@ type: text/vnd.tiddlywiki
<$macrocall $name=".example" n="1"
eg="""<<tree prefix:"$:/">>"""/>
<$macrocall $name=".example" n="2"
eg="""<<tree prefix:"tree-macro-example-" separator:"-">>"""/>

View File

@ -0,0 +1,21 @@
title: tree-macro-example-
tag: [[tree Macro (Examples)]]
house: See [[tree Macro (Examples)]]
house-kitchen: See [[tree Macro (Examples)]]
house-kitchen-table: See [[tree Macro (Examples)]]
house-kitchen-sink: See [[tree Macro (Examples)]]
house-kitchen-window: See [[tree Macro (Examples)]]
house-attic: See [[tree Macro (Examples)]]
house-attic-window: See [[tree Macro (Examples)]]
house-attic-roof: See [[tree Macro (Examples)]]
house-garden: See [[tree Macro (Examples)]]
house-garden-shed: See [[tree Macro (Examples)]]
house-garden-lawn: See [[tree Macro (Examples)]]
car: See [[tree Macro (Examples)]]
car-boot: See [[tree Macro (Examples)]]
car-boot-lock: See [[tree Macro (Examples)]]
car-boot-handle: See [[tree Macro (Examples)]]
car-roof: See [[tree Macro (Examples)]]
car-roof-rails: See [[tree Macro (Examples)]]
car-roof-aerial: See [[tree Macro (Examples)]]

View File

@ -5,11 +5,13 @@ tags: Macros [[Core Macros]]
title: tree Macro
type: text/vnd.tiddlywiki
The <<.def tree>> [[macro|Macros]] renders an expandable tree view based on tiddler titles.
The <<.def tree>> [[macro|Macros]] renders an expandable tree view based on a prefix and separator within tiddler titles.
!! Parameters
;prefix
: The prefix from which to generate the tree, e.g. `$:/`
: The prefix from which to generate the tree, defaults to `$:/`
;separator
: The separator between parts of the tiddler titles, defaults to `/`
<<.macro-examples "tree">>