helpers: Add option helpers for types that are either a lua str or a value (#876)

Those types needed the following code in apply:

if builtins.isString value
then mkRaw value
else value

This commit avoids this boilerplate, and clarifies that the `str` is lua
code in the documentation.
This commit is contained in:
traxys 2024-01-02 00:30:10 +01:00 committed by GitHub
parent 8b8a1c0f4b
commit 8aa4b7e4ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 109 additions and 129 deletions

View file

@ -219,8 +219,7 @@ in {
'';
transformExplicit =
helpers.defaultNullOpts.mkNullable
(with types; either str (enum [false]))
helpers.defaultNullOpts.mkStrLuaFnOr (types.enum [false])
"false"
''
A function that transforms the text to be inserted as the source/path of a link when a
@ -241,8 +240,7 @@ in {
'';
transformImplicit =
helpers.defaultNullOpts.mkNullable
(with types; either str (enum [false]))
helpers.defaultNullOpts.mkStrLuaFnOr (types.enum [false])
''
function(text)
text = text:gsub(" ", "-")
@ -578,14 +576,8 @@ in {
context
;
implicit_extension = implicitExtension;
transform_implicit =
if isString transformImplicit
then helpers.mkRaw transformImplicit
else transformImplicit;
transform_explicit =
if isString transformExplicit
then helpers.mkRaw transformExplicit
else transformExplicit;
transform_implicit = transformImplicit;
transform_explicit = transformExplicit;
};
to_do = with toDo; {
inherit symbols;