Read a Tree another way
One Tree, shown four ways.
A projection turns a Template into something to read. It reads the Template’s saved tree and writes nothing unless you say where. Four are built in:
--as | What you get |
|---|---|
text (the default) | The indented tree, with each item’s tags after its name. |
markdown | A document: a heading per item, with its type’s meaning beneath. |
folder | A folder per item, each with a README.md. Without --to, the tree of folders it would write. |
mermaid | A Mermaid flowchart, which GitHub draws as it is. |
Text #
$ vendor/bin/barntree export Allotment
Barn: …/allotment
Allotment
|
+--Beds
+--Compost [Watered]
+--Shed
Document #
$ vendor/bin/barntree export Allotment --as=markdown
Barn: …/allotment
# Allotment
The whole plot, from the gate to the far fence.
## Beds
The raised beds, each growing one crop at a time.
## Compost \[Watered\]
Where waste becomes next year's soil.
## Shed
Where the tools are kept dry.
Diagram #
$ vendor/bin/barntree export Allotment --as=mermaid
Barn: …/allotment
flowchart TD
n1["Allotment"]
n2["Beds"]
n1 --> n2
n3["Compost"]
n1 --> n3
n4["Shed"]
n1 --> n4
Pipe it into mermaid-cli for an SVG:
barntree export Allotment --as=mermaid | mmdc -i - -o allotment.svg. The Barn line goes to standard error, so a piped export
holds only the projection.
Folders #
$ vendor/bin/barntree export Allotment --as=folder
Barn: …/allotment
Allotment/
├── README.md
├── Beds/
│ └── README.md
├── Compost/
│ └── README.md
└── Shed/
└── README.md
Without --to that wrote nothing. With it:
$ vendor/bin/barntree export Allotment --as=folder --to=garden-folders
Barn: …/allotment
Wrote garden-folders
$ find garden-folders | sort
garden-folders
garden-folders/Beds
garden-folders/Beds/README.md
garden-folders/Compost
garden-folders/Compost/README.md
garden-folders/README.md
garden-folders/Shed
garden-folders/Shed/README.md
--to never overwrites and never merges. A file must go to a path that doesn’t exist, and folders to one that doesn’t
exist or is empty.
$ vendor/bin/barntree export Allotment --as=folder --to=garden-folders
Barn: …/allotment
Will not write over "garden-folders": it already exists
An item whose name can’t be a folder is reported, every one at once, instead of being renamed. The members of a Template that has a saved tree are part of the export, and one of them is called Why?:
$ vendor/bin/barntree export Odd --as=folder
Barn: …/allotment
These names cannot be folders: "Allotment/Beds/Why?": it has one of / \ : * ? " < > |
An unknown kind lists the ones there are:
$ vendor/bin/barntree export Allotment --as=pdf
Cannot export as "pdf". Choose one of: text, markdown, folder, mermaid
In the browser app #
Under a Template’s Overview, View and export previews the saved tree as Tree, Document,
Folders or Diagram. Each has an Export button that downloads allotment.txt,
.md, a .zip of the folders or the diagram as .svg or .mmd. That downloads a copy. To write a
projection into your project, use barntree export --to.
A Construction can’t be exported in this version.