From fc09f8e3312f1cf9e6635dda78ce55d53712070b Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 13 Jun 2019 08:47:42 +0100 Subject: [PATCH] Tree macro: allow separator to be customised --- core/wiki/macros/tree.tid | 22 +++++++++---------- .../macros/examples/tree Macro (Examples).tid | 3 +++ .../examples/tree-macro-example-data.multids | 21 ++++++++++++++++++ .../tw5.com/tiddlers/macros/tree Macro.tid | 6 +++-- 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 editions/tw5.com/tiddlers/macros/examples/tree-macro-example-data.multids diff --git a/core/wiki/macros/tree.tid b/core/wiki/macros/tree.tid index d47c1fbc4..5bd877927 100644 --- a/core/wiki/macros/tree.tid +++ b/core/wiki/macros/tree.tid @@ -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__>>/> \end -\define leaf-node(prefix, chunk) +\define leaf-node(prefix,chunk)
  • <$list filter="[<__prefix__>addsuffix<__chunk__>is[shadow]] [<__prefix__>addsuffix<__chunk__>is[tiddler]]" variable="full-title"> <$list filter="[removeprefix<__prefix__>]" variable="chunk"> @@ -15,7 +15,7 @@ tags: $:/tags/Macro
  • \end -\define branch-node(prefix, chunk) +\define branch-node(prefix,chunk,separator: "/")
  • <$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}> <$reveal type="nomatch" stateTitle=<> text="show"> @@ -30,28 +30,28 @@ tags: $:/tags/Macro (<$count filter="[all[shadows+tiddlers]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>) <$reveal type="match" stateTitle=<> text="show"> -<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}}/> +<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
  • \end -\define tree-node(prefix) +\define tree-node(prefix,separator: "/")
      -<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]!suffix[/]]" variable="chunk"> -<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<>/> +<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk"> +<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<> separator=<<__separator__>>/> -<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore[/]sort[]suffix[/]]" variable="chunk"> -<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<>/> +<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]suffix<__separator__>]" variable="chunk"> +<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<> separator=<<__separator__>>/>
    \end -\define tree(prefix: "$:/") +\define tree(prefix: "$:/",separator: "/")
    <$text text=<<__prefix__>>/>
    -<$macrocall $name="tree-node" prefix=<<__prefix__>>/> +<$macrocall $name="tree-node" prefix=<<__prefix__>> separator=<<__separator__>>/>
    \end diff --git a/editions/tw5.com/tiddlers/macros/examples/tree Macro (Examples).tid b/editions/tw5.com/tiddlers/macros/examples/tree Macro (Examples).tid index ed19fa528..8a3c4506e 100644 --- a/editions/tw5.com/tiddlers/macros/examples/tree Macro (Examples).tid +++ b/editions/tw5.com/tiddlers/macros/examples/tree Macro (Examples).tid @@ -6,3 +6,6 @@ type: text/vnd.tiddlywiki <$macrocall $name=".example" n="1" eg="""<>"""/> + +<$macrocall $name=".example" n="2" +eg="""<>"""/> diff --git a/editions/tw5.com/tiddlers/macros/examples/tree-macro-example-data.multids b/editions/tw5.com/tiddlers/macros/examples/tree-macro-example-data.multids new file mode 100644 index 000000000..8f5d61203 --- /dev/null +++ b/editions/tw5.com/tiddlers/macros/examples/tree-macro-example-data.multids @@ -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)]] diff --git a/editions/tw5.com/tiddlers/macros/tree Macro.tid b/editions/tw5.com/tiddlers/macros/tree Macro.tid index 8f6892071..e3cc990a2 100644 --- a/editions/tw5.com/tiddlers/macros/tree Macro.tid +++ b/editions/tw5.com/tiddlers/macros/tree Macro.tid @@ -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">>