Keep a Template
The rules of a subject, kept in your project.
A Template is a Tree kept in your project, to make Constructions from. It lives in one file, named
after it, in .barn/barntree/trees/, and it is the same file whether you work in the browser app or on the command line.
Make one #
From a file #
Write the Template as JSON, with the types and nothing else needed (the document page has the
shape), and give it to Barntree. --from-file=- reads it from standard input.
$ vendor/bin/barntree template:create --from-file=allotment.json
Saved: Allotment
Barntree builds the skeleton, saves the file as Allotment.barntree.json and records its first revision. A file that breaks a rule is refused, and nothing is saved.
In the browser app #
Choose + beside Templates, give it a name and a description, and add types one at a time. Nothing is written until you save.
Look at it #
$ vendor/bin/barntree template:list
Barn: …/allotment
+-----------+----------------------------------+----------+-----------------+
| Name | Document ID | Revision | Source Template |
+-----------+----------------------------------+----------+-----------------+
| Allotment | bd3708f38810ec991ef9a2470b5abe52 | 1 | |
+-----------+----------------------------------+----------+-----------------+
template:show has several views:
--view= | What you get |
|---|---|
tree (the default) | The tree of types from the root down, with the member type under each list. |
overview | The name, description, root and how many types and items. |
skeleton | The starting tree: required map children, and empty lists. |
types | Every type, grouped by kind and sorted by identifier, with where it is used and its item ids. |
glossary | The same, with the meanings and the declared tags. |
$ vendor/bin/barntree template:show Allotment --view=overview
Allotment
Revision: 1 (3c46bfb7e7251ee4a668cf2dd6a79557)
File token: 5f075e17e9f96751d733594974e8696b748ec2aeafa09d1342c5a0f819e70106
name: Allotment
description: A plot of ground, rented to grow food on.
root: Allotment
types: 5
items: 4
$ vendor/bin/barntree template:show Allotment --view=glossary
Allotment
Revision: 1 (3c46bfb7e7251ee4a668cf2dd6a79557)
File token: 5f075e17e9f96751d733594974e8696b748ec2aeafa09d1342c5a0f819e70106
types:
0:
identifier: Allotment
name: Allotment
meaning: The whole plot, from the gate to the far fence.
kind: map
of:
0: Beds
1: Compost
2: Shed
…
Both use --json for scripts. The whole Template is in the JSON as content.
Change it #
Changes are made a step at a time. Each one is saved at once, as one revision, and a change that alters nothing records none.
$ vendor/bin/barntree template:edit Allotment --description="A plot of ground, rented to grow food on, with a path to every bed."
Saved: Allotment
Add a type. It starts unattached: it exists, and nothing holds it yet. Its identifier defaults to its name; --identifier chooses another.
$ vendor/bin/barntree type:create Allotment --kind=leaf --name="Greenhouse" --meaning="Where seedlings start."
Saved: Allotment
Attach it to the map that should hold it. A change to the structure is previewed and needs --yes, or a reply to a prompt, to go ahead.
$ vendor/bin/barntree map:add-child Allotment Allotment Greenhouse --yes
Changed structure: Allotment
Saved: Allotment
| Command | What it does |
|---|---|
type:create | Makes a leaf, a list (--of=IDENTIFIER for its member type) or a map (--of=A,B for its children). Unattached. |
type:edit | Changes a type’s name, meaning, kind or of, never its identifier. A meaning can run to several paragraphs. |
map:add-child, map:remove-child | Connects a type to a map, or removes the connection and keeps the type. |
list:set-member-type | Chooses the one type a list holds. |
type:delete | Deletes a type that nothing uses and that isn’t the root. |
template:edit | Changes the name, the description or the root. |
template:apply | Applies a JSON file of metadata and types as one change. See the command reference. |
A type that something still uses can’t be deleted:
$ vendor/bin/barntree type:delete Allotment Bed --yes
This building block is still used.
When the tree has to follow #
Changing types fits the saved tree to them. An item whose type is still the one expected where it sits is kept, with its id and name. A map entry the new types call for is built, with its own skeleton. A member whose type its list no longer holds, and an entry whose type has left its map, are dropped with everything below them. Barntree decides nothing for you: it previews every item that would go, and asks. Changing the root is the plainest case:
$ vendor/bin/barntree template:edit "Winter beds" --root=Beds
Removed item: Allotment [597dd7eb43ec0363]
Removed item: Beds [615e4cd5d3ff2f65]
Removed item: Compost [a12966e1826a8712]
Removed item: Shed [201774b572c32cbc]
Removed item: Greenhouse [a1260f2a203b1704]
Changed root: Allotment to Beds
This change needs confirmation. Use --yes to confirm.
Nothing was saved. Repeat the command with --yes to keep that result, or don’t. Unattended use always needs --yes, and --yes never skips validation or the conflict check.
Copy, rename and delete #
A copy gets fresh identity and its own history, and keeps the saved members and tags. The name can’t be one a Template already has.
$ vendor/bin/barntree template:copy Allotment "Winter plot"
Saved: Winter plot
$ vendor/bin/barntree template:edit "Winter plot" --name="Winter beds"
Saved: Winter beds
Renaming keeps the identity, the file’s place and the history. Deleting a Template asks first:
$ vendor/bin/barntree template:delete Allotment
Delete Template: Allotment
This change needs confirmation. Use --yes to confirm.
$ vendor/bin/barntree template:delete "Winter beds" --yes
Delete Template: Winter beds
Deleted: Winter beds
A deleted Template’s revisions are kept, and so is every Construction made from it: each holds its own copy of the types, so deleting the Template can’t break one.
Changing a Template from two places #
Every save compares the Template’s file with the state you based your change on, and refuses to overwrite newer work. To base
a change on what you inspected, give --expect-token=TOKEN, using the File token that template:show
prints. If the file was changed outside Barntree, open it in the app, or save it through a command, before changing it further: the
save records what was there first.