Notify, Notify.validate: correct docblock comments so they work with moondoc

moondoc is the system we use for auto-generating Lua API docs

Ref https://github.com/sbrl/moondoc
This commit is contained in:
Starbeamrainbowlabs 2024-10-15 22:36:47 +01:00
parent 57d09a766b
commit c84fa5f152
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 37 additions and 32 deletions

View file

@ -16,8 +16,8 @@ local globalstate = {
local validate = dofile(wea_c.modpath .. "/utils/notify/validate.lua") local validate = dofile(wea_c.modpath .. "/utils/notify/validate.lua")
local split = dofile(wea_c.modpath .. "/utils/strings/split.lua") local split = dofile(wea_c.modpath .. "/utils/strings/split.lua")
--- WorldEditAdditions player notification system.
-- @class worldeditadditions_core.notify -- @namespace worldeditadditions_core.notify
local Notify = {} local Notify = {}
-- Local send handler -- Local send handler
@ -57,10 +57,10 @@ end
--- Send a notification of type `ntype`. --- Send a notification of type `ntype`.
-- (Same as `Notify[ntype](name, message)`) -- (Same as `Notify[ntype](name, message)`)
-- @param name <string>: The name of the player to send the notification to. -- @param string name The name of the player to send the notification to.
-- @param ntype <string>: The type of notification. -- @param string ntype The type of notification.
-- @param message <string>: The message to send. -- @param string message The message to send.
-- @return <table>: The Notify instance. -- @return table The Notify instance.
function Notify.__call(name, ntype, message) function Notify.__call(name, ntype, message)
if ntype ~= "__call" and not Notify[ntype] then if ntype ~= "__call" and not Notify[ntype] then
Notify.error(name, "Invalid notification type: " .. ntype) Notify.error(name, "Invalid notification type: " .. ntype)
@ -72,25 +72,26 @@ function Notify.__call(name, ntype, message)
end end
--- Send a custom notification. --- Send a custom notification.
-- @param name <string>: The name of the player to send the notification to. -- @param string name The name of the player to send the notification to.
-- @param ntype <string>: The type of notification. -- @param string ntype The type of notification.
-- @param message <string>: The message to send. -- @param string message The message to send.
-- @param colour <string> (optional): The colour of the notification. -- @param string colour optional): The colour of the notification.
-- @param message_coloured <boolean> (optional): Whether the message should be coloured. -- @param message_coloured boolean? Optional. Whether the message should be coloured.
-- @return <boolean>: True if all parameters are valid, false otherwise. -- @return boolean True if all parameters are valid, false otherwise.
function Notify.custom(name, ntype, message, colour, message_coloured) -- @example Predefined notification types
if not colour then colour = "#FFFFFF" end
return send(name, ntype, message, colour, message_coloured)
end
--- Register predefined notification types.
-- @usage
-- Notify.error(name, message) -- Notify.error(name, message)
-- Notify.errinfo(name, message) -- For verbose errors and stack traces -- Notify.errinfo(name, message) -- For verbose errors and stack traces
-- Notify.warn(name, message) -- Notify.warn(name, message)
-- Notify.wrninfo(name, message) -- For verbose warnings and stack traces -- Notify.wrninfo(name, message) -- For verbose warnings and stack traces
-- Notify.ok(name, message) -- Notify.ok(name, message)
-- Notify.info(name, message) -- Notify.info(name, message)
function Notify.custom(name, ntype, message, colour, message_coloured)
if not colour then colour = "#FFFFFF" end
return send(name, ntype, message, colour, message_coloured)
end
--- Register the aforementioned predefined notification types.
do do
local type_colours = { local type_colours = {
error = {"#FF5555", true}, error = {"#FF5555", true},

View file

@ -1,4 +1,6 @@
--- Validation functions for WorldEditAdditions notifications. --- Validation functions for WorldEditAdditions notifications.
-- @internal
-- @namespace worldeditadditions_core.notify.validate
-- Helper functions -- Helper functions
local log_error = function(message) local log_error = function(message)
@ -6,12 +8,13 @@ local log_error = function(message)
" " .. debug.traceback()) " " .. debug.traceback())
end end
--- Collection of functions to validate various parts of WorldEditAdditions notifications to ensure proper input for player names, messages, and colors.
-- @class validate -- @class validate
local validate = {} local validate = {}
--- Validate name --- Validate name
-- - @param name <string>: The name of the player to validate. -- @param string name The name of the player to validate.
-- - @returns <boolean>: True if the name is valid, false otherwise. -- @returns boolean True if the name is valid, false otherwise.
validate.name = function(name) validate.name = function(name)
if type(name) ~= "string" then if type(name) ~= "string" then
log_error(tostring(name) .. " is a " .. type(name) .. " not a string.\n") log_error(tostring(name) .. " is a " .. type(name) .. " not a string.\n")
@ -27,13 +30,13 @@ validate.name = function(name)
end end
--- Validate message --- Validate message
-- - @param message <string>: The message to validate. -- @param string message The message to validate.
-- - @returns <boolean>: True if the message is a string, false otherwise. -- @returns boolean True if the message is a string, false otherwise.
validate.message = function(message) return type(message) == "string" end validate.message = function(message) return type(message) == "string" end
--- Validate colour --- Validate colour
-- - @param colour <string>: The colour to validate. -- @param string colour The colour to validate.
-- - @returns <boolean>: True if the colour is valid, false otherwise. -- @returns boolean True if the colour is valid, false otherwise.
validate.colour = function(colour) validate.colour = function(colour)
return ( type(colour) == "string" and return ( type(colour) == "string" and
colour:match("^#%x+$") and colour:match("^#%x+$") and
@ -41,13 +44,14 @@ validate.colour = function(colour)
end end
--- Validate all --- Validate all
-- - @param name <string>: The name of the player to validate. -- @param string name The name of the player to validate.
-- - @param message <string>: The message to validate. -- @param string message The message to validate.
-- - @param colour <string>: The colour to validate. -- @param string colour The colour to validate.
-- - @returns <boolean>, <table|nil>: -- @returns boolean, table|nil Returns the validation status, followed by details of the failure if bool == false.
-- - <boolean>: True if all parameters are valid, false otherwise. -- | Return arg | Meaning |
-- - <table|nil>: A table containing the fail state of the parameters -- |------------|---------|
-- - or nil if player name is invalid. -- | `boolean` | True if all parameters are valid, false otherwise. |
-- | `table|nil` | A table containing the fail state of the parameters or nil if player name is invalid. |
validate.all = function(name, message, colour) validate.all = function(name, message, colour)
local name_checked = validate.name(name) local name_checked = validate.name(name)
local failed = { local failed = {