Click here to update this documentation.
used to generate lists and replace several old list creating templates, such as Template:Dropped_By making them lightweight
local list = {}
function list.CreateList(template)
function list.split(str, delimiter)
local result = {};
for slice in string.gmatch(str..delimiter,"(.-)"..delimiter) do
table.insert(result, slice);
end
return result
end
function list.wiki_link(name)
if name == "" then
return ""
else
return "[["..name.."]]";
end
end
-- list order/mark type in mediawiki code [https://www.mediawiki.org/wiki/Help:Lists]
local list_order = {
["numbered"] = "#",
["bulleted"] = "*",
["definition"] = ";",
["none"] = ""
}
-- empty lua values before template input parameters
div_wrapper_open = ""
div_wrapper_close = ""
div_wrapper_id = ""
-- loot list values
amount =""
item_name = ""
rarity = ""
-- general values
build_list = ""
list_item = ""
if template.args["id"] ~= nil and template.args["id"]:len() > 0 then
div_wrapper_id = " id=\""..template.args["id"].."\""
else
div_wrapper_id = ""
end
-- wether to wrap the list a div with a class or not
if template.args["class"]~= nil and template.args["class"]:len() > 0 then
div_wrapper_open = "<div class=\""..template.args["class"].."\""..div_wrapper_id..">"
div_wrapper_close = "\n</div>"
else
div_wrapper_open = ""
div_wrapper_close = ""
end
-- list_order value , defaults to list_order["bulleted"] (* / <ul>)
order = list_order[template.args["order"]] or list_order.bulleted
-- what character seperates the list items in the result :
-- 'none' will produce a text list of items seperated by the 'list_separator' value
-- else each value will be seperated by a new line (\n)
if template.args["order"] == "none" then
list_separator = template.args["list_separator"]
else
list_separator = "\n"
end
-- currently for list type loot you can set the character that will seperate the loot arguments (amount,object,rarity) by template.args["splitby"]:
-- defaults to comma (,)
if template.args["list_type"] == "loot" then
splitby = template.args["splitby"] or ","
-- list creation portion, definition by type
-- current list type options :
-- loot = splits each unnamed template arg {up to 3 values in each parameter seperated by "splitby"}
-- link = wraps each unnamed template arg in [[ ]]
-- no type / default = a list of strings with a selected 'list_separator' and 'order', defaults to "\n" and "*" respectively
-- {{loot list}}
for key,value in ipairs(template.args) do
if value ~= "" then
value = value:gsub("\n","")
-- temporary condition to comply with current {{Loot Table|{{Loot Item
value = value:gsub("{{Loot Item|","")
value = value:gsub("}}","")
value = value:gsub("|",splitby)
-- temporary condition
local loot_item = list.split(value, splitby)
if #loot_item >= 3 then
amount = loot_item[1].."x "
item_name = list.wiki_link(loot_item[2])
rarity = " ("..loot_item[3]..")"
elseif #loot_item == 2 then
amount = ""
item_name = list.wiki_link(loot_item[1])
rarity = " ("..loot_item[2]..")"
elseif #loot_item == 1 then
amount = ""
item_name = list.wiki_link(loot_item[1])
rarity = ""
end
list_item = order..amount..item_name..rarity
build_list = build_list..list_separator..list_item
end
end
--html list of links (similar to {{DroppedBy}})
elseif template.args["list_type"] == "link" then
for key,value in ipairs(template.args) do
if value ~= "" then
value = value:gsub("\n","")
list_item = order..list.wiki_link(value)
build_list = build_list..list_separator..list_item
end
end
--html List of strings, or textual list of strings with seperators
else
for key,value in ipairs(template.args) do
if value ~= "" then
value = value:gsub("\n","")
list_item = order..value
build_list = build_list..list_separator..list_item
end
end
end
result = div_wrapper_open..build_list..div_wrapper_close
return result
end
return list