feat(glossy): Panic on multiple requested modes
When multiple modes are requested at the same time (like 'long' & 'short'), panic with a clear error message. This is better than guessing what the user wanted.
No files matched your search
@@ -409,3 +409,5 @@ This project is licensed under the MIT License.
|
|||||||
in your custom theme to keep the previous behaviour.
|
in your custom theme to keep the previous behaviour.
|
||||||
- **Breaking**: The `both` mode (previously called modifier) by default
|
- **Breaking**: The `both` mode (previously called modifier) by default
|
||||||
now counts towards the first use of a term.
|
now counts towards the first use of a term.
|
||||||
|
- **Breaking**: When multiple conflicting modes are supplied (like 'short'
|
||||||
|
and 'long'), glossy now throws an error (with a clear message).
|
||||||
@@ -271,6 +271,9 @@
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Check for illegal mode and/or modifier combinations
|
// Check for illegal mode and/or modifier combinations
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
if requested_modes.len() > 1 {
|
||||||
|
panic("Cannot mix modes ", requested_modes, ", pick one.")
|
||||||
|
}
|
||||||
if "description" in requested_modes and modifiers.len() > 0 {
|
if "description" in requested_modes and modifiers.len() > 0 {
|
||||||
panic("Cannot use mode 'def'/'desc' with other modifiers.")
|
panic("Cannot use mode 'def'/'desc' with other modifiers.")
|
||||||
}
|
}
|
||||||
@@ -405,9 +408,9 @@
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Determine desired options based on modifiers and entry.long availability
|
// Determine desired options based on modifiers and entry.long availability
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
let wants_both = "both" in requested_modes
|
let wants_both = requested_mode == "both"
|
||||||
let wants_long = "long" in requested_modes
|
let wants_long = requested_mode == "long"
|
||||||
let wants_short = "short" in requested_modes
|
let wants_short = requested_mode == "short"
|
||||||
let long_available = entry.long != none
|
let long_available = entry.long != none
|
||||||
|
|
||||||
// Determine mode using the helper function
|
// Determine mode using the helper function
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 490 KiB After Width: | Height: | Size: 104 KiB |
@@ -40,18 +40,29 @@ Now make sure I get your @tps:short reports by 2pm!
|
|||||||
|
|
||||||
== Using conflicting modifiers (short, long, both)
|
== Using conflicting modifiers (short, long, both)
|
||||||
|
|
||||||
These modifiers are semantically mutually exclusive, by they can be combined
|
These modifiers are semantically mutually exclusive. When multiple are used,
|
||||||
syntactically. When multiple are used, `glossy` tries to make a smart choice on
|
`glossy` throws an error to the compiler, explaining the problem.
|
||||||
which one to display.
|
|
||||||
|
#import "/src/gloss.typ": __gls, __default-format-term
|
||||||
|
#let manual-gls(key, mods) = __gls(key, modes-modifiers: mods, format-term: __default-format-term, show-term: (body) => [#strong(body)], term-links: false, display-text: none)
|
||||||
|
#assert-panic(manual-gls.with("tps", ("short", "long")))
|
||||||
|
#let msg-short-long = "panicked with: \"Cannot mix modes \", (\"short\", \"long\"), \", pick one.\""
|
||||||
|
#let msg-short-both = "panicked with: \"Cannot mix modes \", (\"short\", \"both\"), \", pick one.\""
|
||||||
|
#let msg-long-both = "panicked with: \"Cannot mix modes \", (\"long\", \"both\"), \", pick one.\""
|
||||||
|
#let msg-short-long-both = "panicked with: \"Cannot mix modes \", (\"short\", \"long\", \"both\"), \", pick one.\""
|
||||||
|
|
||||||
#table(
|
#table(
|
||||||
columns: 2,
|
columns: 2,
|
||||||
table.header([*Input*], [*Output*]),
|
table.header([*Input*], [*Error*]),
|
||||||
|
|
||||||
[`@tps:short:long` ], [@tps:short:long],
|
[`@tps:short:long` ], [#assert.eq(catch(manual-gls.with("tps", ("short", "long"))),
|
||||||
[`@tps:short:both` ], [@tps:short:both],
|
msg-short-long)#msg-short-long],
|
||||||
[`@tps:long:both` ], [@tps:long:both],
|
[`@tps:short:both` ], [#assert.eq(catch(manual-gls.with("tps", ("short", "both"))),
|
||||||
[`@tps:short:long:both`], [@tps:short:long:both],
|
msg-short-both)#msg-short-both],
|
||||||
|
[`@tps:long:both` ], [#assert.eq(catch(manual-gls.with("tps", ("long", "both"))),
|
||||||
|
msg-long-both)#msg-long-both],
|
||||||
|
[`@tps:short:long:both`], [#assert.eq(catch(manual-gls.with("tps", ("short", "long", "both"))),
|
||||||
|
msg-short-long-both)#msg-short-long-both],
|
||||||
)
|
)
|
||||||
|
|
||||||
#let my-theme = (
|
#let my-theme = (
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 882 KiB After Width: | Height: | Size: 187 KiB |
@@ -78,18 +78,29 @@ Articles are incompatible with the `pl` (plural) modifier.
|
|||||||
|
|
||||||
== Using conflicting modifiers (short, long, both)
|
== Using conflicting modifiers (short, long, both)
|
||||||
|
|
||||||
These modifiers are semantically mutually exclusive, by they can be combined
|
These modifiers are semantically mutually exclusive. When multiple are used,
|
||||||
syntactically. When multiple are used, `glossy` tries to make a smart choice on
|
`glossy` throws an error to the compiler, explaining the problem.
|
||||||
which one to display.
|
|
||||||
|
#import "/src/gloss.typ": __gls, __default-format-term
|
||||||
|
#let manual-gls(key, mods) = __gls(key, modes-modifiers: mods, format-term: __default-format-term, show-term: (body) => [#strong(body)], term-links: false, display-text: none)
|
||||||
|
#assert-panic(manual-gls.with("tps", ("short", "long")))
|
||||||
|
#let msg-short-long = "panicked with: \"Cannot mix modes \", (\"short\", \"long\"), \", pick one.\""
|
||||||
|
#let msg-short-both = "panicked with: \"Cannot mix modes \", (\"short\", \"both\"), \", pick one.\""
|
||||||
|
#let msg-long-both = "panicked with: \"Cannot mix modes \", (\"long\", \"both\"), \", pick one.\""
|
||||||
|
#let msg-short-long-both = "panicked with: \"Cannot mix modes \", (\"short\", \"long\", \"both\"), \", pick one.\""
|
||||||
|
|
||||||
#table(
|
#table(
|
||||||
columns: 2,
|
columns: 2,
|
||||||
table.header([*Input*], [*Output*]),
|
table.header([*Input*], [*Error*]),
|
||||||
|
|
||||||
[`@tps:short:long` ], [@tps:short:long],
|
[`@tps:short:long` ], [#assert.eq(catch(manual-gls.with("tps", ("short", "long"))),
|
||||||
[`@tps:short:both` ], [@tps:short:both],
|
msg-short-long)#msg-short-long],
|
||||||
[`@tps:long:both` ], [@tps:long:both],
|
[`@tps:short:both` ], [#assert.eq(catch(manual-gls.with("tps", ("short", "both"))),
|
||||||
[`@tps:short:long:both`], [@tps:short:long:both],
|
msg-short-both)#msg-short-both],
|
||||||
|
[`@tps:long:both` ], [#assert.eq(catch(manual-gls.with("tps", ("long", "both"))),
|
||||||
|
msg-long-both)#msg-long-both],
|
||||||
|
[`@tps:short:long:both`], [#assert.eq(catch(manual-gls.with("tps", ("short", "long", "both"))),
|
||||||
|
msg-short-long-both)#msg-short-long-both],
|
||||||
)
|
)
|
||||||
|
|
||||||
#let my-theme = (
|
#let my-theme = (
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 275 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 502 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 534 KiB After Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 376 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 407 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 78 KiB |
@@ -293,14 +293,25 @@ This document tries all reference forms and modifiers on a large set of terms.
|
|||||||
|
|
||||||
== Conflicting multiple modifiers combined (short, long, both together)
|
== Conflicting multiple modifiers combined (short, long, both together)
|
||||||
|
|
||||||
- @tps:short:long
|
Assert that a panic occurs.
|
||||||
- @tps:short:both
|
#import "/src/gloss.typ": __gls, __default-format-term
|
||||||
- @tps:long:both
|
#let manual-gls(key, mods) = __gls(key, modes-modifiers: mods, format-term: __default-format-term, show-term: (body) => [#strong(body)], term-links: false, display-text: none)
|
||||||
- @tps:short:long:both
|
//- @tps:short:long
|
||||||
- @html:both:long:short
|
#assert-panic(manual-gls.with("tps", ("short", "long")))
|
||||||
- @doc:long:short
|
//- @tps:short:both
|
||||||
- @cpu:both:long:short
|
#assert-panic(manual-gls.with("tps", ("short", "both")))
|
||||||
- @api:short:long:both
|
//- @tps:long:both
|
||||||
|
#assert-panic(manual-gls.with("tps", ("long", "both")))
|
||||||
|
//- @tps:short:long:both
|
||||||
|
#assert-panic(manual-gls.with("tps", ("short", "long", "both")))
|
||||||
|
//- @html:both:long:short
|
||||||
|
#assert-panic(manual-gls.with("html", ("both", "long", "short")))
|
||||||
|
//- @doc:long:short
|
||||||
|
#assert-panic(manual-gls.with("doc", ("long", "short")))
|
||||||
|
//- @cpu:both:long:short
|
||||||
|
#assert-panic(manual-gls.with("cpu", ("both", "long", "short")))
|
||||||
|
//- @api:short:long:both
|
||||||
|
#assert-panic(manual-gls.with("api", ("short", "long", "both")))
|
||||||
|
|
||||||
== Combining capitalization and plural with short/long/both
|
== Combining capitalization and plural with short/long/both
|
||||||
|
|
||||||
|
|||||||