Documentation for this module may be created at Module:Sort/doc
local p = {}
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 = ""
if frame.args['pre'] then
pre = frame.args['pre']
end
if frame.args['post'] then
post = frame.args['post']
end
if frame.args['wrap'] then
pre = "{{L|" .. pre .. frame.args['wrap'] .. "|"
post = 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