mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-21 15:41:22 +00:00
LDoc: add some special tags handling
This commit is contained in:
parent
c00ee93e79
commit
b6ce523957
2 changed files with 128 additions and 42 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
local print, error, type, table, ipairs, string, tostring
|
local dofile, print, error, type, table, ipairs, string, tostring
|
||||||
if import then
|
if import then
|
||||||
|
dofile = import("dofile")
|
||||||
print = import("print")
|
print = import("print")
|
||||||
error = import("error")
|
error = import("error")
|
||||||
type = import("type")
|
type = import("type")
|
||||||
|
@ -38,43 +39,9 @@ local function video_frame(src)
|
||||||
.. ' allow="fullscreen;"></iframe>'
|
.. ' allow="fullscreen;"></iframe>'
|
||||||
end
|
end
|
||||||
|
|
||||||
custom_tags = {
|
|
||||||
{
|
local tags
|
||||||
"privs",
|
tags, custom_tags = dofile(".ldoc/tags.ld")
|
||||||
title = "Required Privileges",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"video",
|
|
||||||
title = "Video",
|
|
||||||
format = video_frame,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"youtube",
|
|
||||||
title = "Video",
|
|
||||||
format = function(value)
|
|
||||||
return video_frame("https://www.youtube.com/embed/" .. value)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
-- settings
|
|
||||||
{
|
|
||||||
"settype",
|
|
||||||
title = "Setting Type",
|
|
||||||
hidden = true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"default",
|
|
||||||
title = "Default Value",
|
|
||||||
hidden = true,
|
|
||||||
},
|
|
||||||
-- craft items/tools
|
|
||||||
{
|
|
||||||
"img",
|
|
||||||
title = "Image",
|
|
||||||
format = function(value)
|
|
||||||
return "<img src=\"../data/" .. value .. "\" style=\"width:32px; height:32px;\" />"
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- START: handling items to prevent re-parsing
|
-- START: handling items to prevent re-parsing
|
||||||
|
@ -172,6 +139,27 @@ local function chatcmd_handler(item)
|
||||||
item.description = item.description .. "\n\n### Parameters:"
|
item.description = item.description .. "\n\n### Parameters:"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if item.tags.chatparam then
|
||||||
|
local pstring = "### Parameters:\n"
|
||||||
|
for _, cp in ipairs(item.tags.chatparam) do
|
||||||
|
local idx, key, desc = cp:find(" ")
|
||||||
|
if idx then
|
||||||
|
key = cp:sub(1, idx-1)
|
||||||
|
value = cp:sub(idx)
|
||||||
|
else
|
||||||
|
key = cp
|
||||||
|
end
|
||||||
|
|
||||||
|
pstring = pstring .. '\n- <span class="parameter">'
|
||||||
|
.. key .. '</span>'
|
||||||
|
if value then
|
||||||
|
pstring = pstring .. value
|
||||||
|
end
|
||||||
|
|
||||||
|
item.description = item.description .. "\n\n" .. pstring
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,10 +170,27 @@ function custom_display_name_handler(item, default_handler)
|
||||||
elseif item.type == "chatcmd" then
|
elseif item.type == "chatcmd" then
|
||||||
item = chatcmd_handler(item)
|
item = chatcmd_handler(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local parse_tags = {"priv", "note"}
|
||||||
|
for _, pt in ipairs(parse_tags) do
|
||||||
|
local tvalues = item.tags[pt]
|
||||||
|
if tvalues then
|
||||||
|
local tstring = ""
|
||||||
|
|
||||||
|
local title = tags.get_title(pt)
|
||||||
|
if title then
|
||||||
|
tstring = tstring .. "\n\n### " .. title .. ":\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, tv in ipairs(tvalues) do
|
||||||
|
tstring = tstring .. "\n- " .. tags.format(pt, tv)
|
||||||
|
end
|
||||||
|
|
||||||
|
item.description = item.description .. tstring
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if item then
|
register(item)
|
||||||
register(item)
|
return default_handler(item)
|
||||||
return default_handler(item)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
81
.ldoc/tags.ld
Normal file
81
.ldoc/tags.ld
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
|
||||||
|
local tags = {}
|
||||||
|
local tag_list = {}
|
||||||
|
local custom_tags = {}
|
||||||
|
|
||||||
|
local register_tag = function(name, tag)
|
||||||
|
local new_tag = {name, title=tag.title, hidden=tag.hidden, format=tag.format}
|
||||||
|
table.insert(custom_tags, new_tag)
|
||||||
|
tag_list[name] = {title=tag.title, format=tag.format}
|
||||||
|
end
|
||||||
|
|
||||||
|
tags.get_title = function(tname)
|
||||||
|
local t = tag_list[tname]
|
||||||
|
if t then
|
||||||
|
return t.title
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tags.format = function(tname, value)
|
||||||
|
local t = tag_list[tname]
|
||||||
|
if t then
|
||||||
|
if type(t.format) == "function" then
|
||||||
|
value = t.format(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local new_tags = {
|
||||||
|
["priv"] = {
|
||||||
|
title = "Required Privileges",
|
||||||
|
hidden = true,
|
||||||
|
},
|
||||||
|
["note"] = {
|
||||||
|
title = "Notes",
|
||||||
|
hidden = true,
|
||||||
|
format = function(value)
|
||||||
|
return "*" .. value .. "*"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
["video"] = {
|
||||||
|
title = "Video",
|
||||||
|
format = video_frame,
|
||||||
|
},
|
||||||
|
["youtube"] = {
|
||||||
|
title = "Video",
|
||||||
|
format = function(value)
|
||||||
|
return video_frame("https://www.youtube.com/embed/" .. value)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- settings
|
||||||
|
["settype"] = {
|
||||||
|
title = "Setting Type",
|
||||||
|
hidden = true,
|
||||||
|
},
|
||||||
|
["default"] = {
|
||||||
|
title = "Default Value",
|
||||||
|
hidden = true,
|
||||||
|
},
|
||||||
|
-- craft items/tools
|
||||||
|
["img"] = {
|
||||||
|
title = "Image",
|
||||||
|
format = function(value)
|
||||||
|
return "<img src=\"../data/" .. value .. "\" style=\"width:32px; height:32px;\" />"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- chat commands
|
||||||
|
["chatparam"] = {
|
||||||
|
title = "Parameters",
|
||||||
|
hidden = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v in pairs(new_tags) do
|
||||||
|
register_tag(k, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return tags, custom_tags
|
Loading…
Add table
Reference in a new issue