tbls/doc/Tutorial.md

83 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2024-08-05 04:03:38 +00:00
## Tutorial
2024-08-03 23:09:10 +00:00
2024-08-05 04:03:38 +00:00
### Random Selections
2024-08-02 18:22:14 +00:00
At its most basic, `tbls` selects a random element from a table.
Suppose you have a few tables:
```
:: suit
Hearts
Bells
Whistles
Cups
Knives
Shovels
:: card
Ace
One
Two
2024-08-03 23:09:10 +00:00
[...]
2024-08-02 18:22:14 +00:00
Queen
King
Beast
```
`tbls` might return "Whistles" from suit.
2024-08-03 23:09:10 +00:00
Or "Two" from card.
2024-08-05 04:03:38 +00:00
### Expansion
2024-08-02 18:22:14 +00:00
But wait there's more.
2024-08-03 23:09:10 +00:00
`tbls` will also expand certain text found in a table entry.
2024-08-02 18:22:14 +00:00
Let's add another table:
```
:: draw
[card] of [suit]
```
When you place the name of a table in `[squarebrackets]`,
then `tbls` views that as a placeholder
for a random item from that table.
2024-08-03 23:09:10 +00:00
It will expand that text.
So 'draw' might end up being "Thief of Shovels"
2024-08-02 18:22:14 +00:00
or "Twelve or Cups".
2024-08-03 23:09:10 +00:00
2024-08-05 04:03:38 +00:00
### Filters
2024-08-03 23:09:10 +00:00
`tbls` can run arbitary filters on text after expanding it.
2024-08-05 04:03:38 +00:00
Example filters can be found in `lib/filters.fnl`.
2024-08-03 23:09:10 +00:00
To apply filters,
dot-chain them at the end
of a table reference.
Consider the following tables:
```
:: origin
2024-08-05 04:03:38 +00:00
Evelyn eats one [fruit.c]
Evelyn eats many [fruit.c.s]
2024-08-03 23:09:10 +00:00
:: fruit
banana
apple
pear
```
`s`, `plural`, and `pluralize`
are all different ways
to call the 'plural' filter function.
2024-08-05 04:03:38 +00:00
`c` is 'capitalize.'
2024-08-03 23:09:10 +00:00
Example output:
```
2024-08-05 04:03:38 +00:00
Evelyn eats one Pear
Evelyn eats many Bananas
2024-08-03 23:09:10 +00:00
```