More actions
Content deleted Content added
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
function formatItem(item, format) |
|||
return format:gsub("%%", item) |
|||
end |
|||
function p.clean(frame) |
|||
⚫ | |||
local delimiter = frame.args['delimiter'] or frame.args['delim'] or frame.args['d'] or "," |
|||
local format = frame.args['format'] or frame.args['f'] or "%%" |
|||
input = input:gsub("%s*%|%s*", ",") -- Convert DPL separators to commas if present |
|||
local items = {} |
|||
for item in string.gmatch(input, "([^,]+)") do |
|||
local trimmed_item = item:match("^%s*(.-)%s*$") |
|||
end |
|||
table.sort(items) |
|||
local processed_items = {} |
|||
for _, item in ipairs(items) do |
|||
table.insert(processed_items, formatItem(item, format)) |
|||
end |
|||
return frame:preprocess(table.concat(processed_items, delimiter)) |
|||
end |
|||
function p.parse(frame) |
function p.parse(frame) |
||
Line 10: | Line 31: | ||
local pre = "" |
local pre = "" |
||
local post = "" |
local post = "" |
||
local prePublic = "" |
|||
⚫ | |||
local postPublic = "" |
|||
⚫ | |||
local prePrivate = "" |
|||
local postPrivate = "" |
|||
⚫ | |||
prePublic = frame.args['prepublic'] |
|||
end |
end |
||
if frame.args[' |
if frame.args['postpublic'] then |
||
postPublic = frame.args['postpublic'] |
|||
end |
end |
||
if frame.args[' |
if frame.args['preprivate'] then |
||
prePrivate = frame.args['preprivate'] |
|||
end |
end |
||
if frame.args[' |
if frame.args['postprivate'] then |
||
postPrivate = frame.args['postprivate'] |
|||
end |
end |
||
if frame.args['wrap'] then |
if frame.args['wrap'] then |
||
pre = "{{L|" .. |
pre = "{{L|" .. prePrivate .. frame.args['wrap'] .. postPrivate .. "|" .. prePublic .. frame.args['wrap'] .. postPublic .. "|" |
||
post = |
post = "|u=1}}" |
||
end |
end |
||
if frame.args['cat'] and frame.args['name'] and frame.args['ns'] then |
if frame.args['cat'] and frame.args['name'] and frame.args['ns'] then |
Revision as of 19:57, 8 February 2025
Documentation for this module may be created at Module:Sort/doc
local p = {}
function formatItem(item, format)
return format:gsub("%%", item)
end
function p.clean(frame)
local input = frame.args[1] or ""
local delimiter = frame.args['delimiter'] or frame.args['delim'] or frame.args['d'] or ","
local format = frame.args['format'] or frame.args['f'] or "%%"
input = input:gsub("%s*%|%s*", ",") -- Convert DPL separators to commas if present
local items = {}
for item in string.gmatch(input, "([^,]+)") do
local trimmed_item = item:match("^%s*(.-)%s*$")
end
table.sort(items)
local processed_items = {}
for _, item in ipairs(items) do
table.insert(processed_items, formatItem(item, format))
end
return frame:preprocess(table.concat(processed_items, delimiter))
end
function p.parse(frame)
local input = frame.args[1] or ""
-- DPL-specific preprocessing
input = input:gsub("%s*%|%s*", ",") -- Convert DPL separators to commas if present
local pre = ""
local post = ""
local prePublic = ""
local postPublic = ""
local prePrivate = ""
local postPrivate = ""
if frame.args['prepublic'] then
prePublic = frame.args['prepublic']
end
if frame.args['postpublic'] then
postPublic = frame.args['postpublic']
end
if frame.args['preprivate'] then
prePrivate = frame.args['preprivate']
end
if frame.args['postprivate'] then
postPrivate = frame.args['postprivate']
end
if frame.args['wrap'] then
pre = "{{L|" .. prePrivate .. frame.args['wrap'] .. postPrivate .. "|" .. prePublic .. frame.args['wrap'] .. postPublic .. "|"
post = "|u=1}}"
end
if frame.args['cat'] and frame.args['name'] and frame.args['ns'] then
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|"
post = "}}"
end
if frame.args['item'] and frame.args['name'] and frame.args['ns'] then
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|"
post = " equipment}}"
elseif frame.args['item'] and frame.args['ns'] then
pre = "{{Cat|ns=" .. frame.args['ns'] .. "|"
post = " equipment}}"
end
if frame.args['sub'] then
pre = pre .. "{{SSub|Ability:"
post = post .. "}}\n"
end
local items = {}
for item in string.gmatch(input, "([^,]+)") do
local trimmed_item = item:match("^%s*(.-)%s*$") -- Trim whitespace
if trimmed_item ~= "Weapon" then
table.insert(items, pre .. trimmed_item .. post)
end
end
table.sort(items)
if frame.args['cat'] or frame.args['item'] or frame.args['sub'] then
return frame:preprocess(table.concat(items, ""))
else
if (frame.args['wrap'] == 'Ability') and #items > 1 then
items[#items] = "and " .. items[#items]
end
return frame:preprocess(table.concat(items, ", "))
end
end
return p