doc(glossy): update docs on concise syntax

This commit is contained in:
swaits committed 2024-12-16 17:46:09 -07:00
1 parent 7f1d1d711a
commit d2e44f4131
2 files changed
+13 -2

No files matched your search

+4
View File
@@ -85,6 +85,10 @@ Each glossary entry supports the following fields:
- `plural` (optional): Override automatic pluralization of short form - `plural` (optional): Override automatic pluralization of short form
- `longplural` (optional): Override automatic pluralization of long form - `longplural` (optional): Override automatic pluralization of long form
Note that if you just want an entry with `short` and `long`, you can use the
abbreviated syntax. In this case, they `key` is used as the short form, and its
value is used as the long form. See `WWW` as an example below.
You can also load glossary entries from a data file using #yaml(), #json(), or similar. You can also load glossary entries from a data file using #yaml(), #json(), or similar.
For example, the above glossary could be in this YAML file: For example, the above glossary could be in this YAML file:
+9 -2
View File
@@ -10,21 +10,28 @@
// with appropriate default values. // with appropriate default values.
// //
// Parameters: // Parameters:
// key: The key from the input dictionary
// entry (dictionary): Input dictionary containing at least 'short' and optionally // entry (dictionary): Input dictionary containing at least 'short' and optionally
// 'long', 'plural', 'longplural', 'description', and 'group' // 'long', 'plural', 'longplural', 'description', and 'group'
// //
// entry (string): If you pass a string to entry, we assume you're using the
// abbreviated syntax `short: "long"`, where the `key` is used
// for `short` and `entry` is used for `long`.
//
// Returns: // Returns:
// dictionary: Normalized dictionary with all expected keys populated // dictionary: Normalized dictionary with all expected keys populated
// //
// Throws: // Throws:
// - If 'short' key is missing // - If 'short' key is missing when using normal (non-abbreviated) syntax
// - If 'short' value is not a string // - If 'short' value is not a string
// - If 'short' value is an empty string // - If 'short' value is an empty string
// //
#let __normalize_entry(key, entry) = { #let __normalize_entry(key, entry) = {
if (type(entry) == str){ // If it's a string, it's using the abbreviated syntax `short: "long"`.
if (type(entry) == str) {
entry = (short: key, long: entry) entry = (short: key, long: entry)
} }
// Validate required fields // Validate required fields
if not "short" in entry { if not "short" in entry {
panic("Entry must contain a 'short' key") panic("Entry must contain a 'short' key")