arab (Arab)
|
├───arab (fa-Arab) ├─── arab (ota-Arab) ├─── arab (tt-Arab) ├─── arab (mzn-Arab) ├─── arab (sd-Arab) ├─── arab (ku-Arab) ├─── arab (kk-Arab) ├─── arab (ms-Arab) ├─── arab (ur-Arab) ├─── arab (ug-Arab) ├─── arab (ps-Arab) ├─── arab (ks-Arab) └─── shahmukhi (pa-Arab) |
avestan (Avst)
|
└───pazend (pal-Avst) |
görög (Grek)
|
└───görög (polytonic) |
latin (Latn)
|
├───latin (nv-Latn) ├─── latin (Latinx) └─── latin (pjt-Latn) |
local p = {}
local scripts = mw.loadData("Module:scripts/data")
local function format(code)
local name = scripts.canonicalName
if not name:find("script$") then
name = name .. " script"
end
return "<code>.canonicalName .. " <span style=\"color:green;\">(" .. code .. ")</span>]]</code>"
end
local function dump(data, prefix)
if type(data) == "string" then
return format(data)
else
local result = ""
local branch = "├───"
local next_level = prefix .. "│ "
local current = ""
for i,val in ipairs(data) do
if i == #data then
branch = "└───"
next_level = prefix .. " "
end
if #val == 0 then
result = result .. prefix .. branch .. dump(val.name) .. "<br/>"
else
result = result .. "{{(!}} class=mw-collapsible style=border-collapse:collapse\n{{!}}"
result = result .. prefix .. branch .. dump(val.name)
result = result .. "\n{{!-}}\n{{!}}"
result = result .. dump(val, next_level)
result = result .. "\n{{!)}}\n"
end
end
return result
end
end
local function deep_sort(current)
local result = {}
local is_table = {}
for key,val in pairs(current) do
if type(key) == "number" then
table.insert(result, val)
else
is_table = true
table.insert(result, key)
end
end
table.sort(result, function(a,b)
return (scripts or error(a)).canonicalName < (scripts or error(b)).canonicalName
end)
local i = 2
while i<#result do
while scripts] == scripts] do
table.remove(result,i)
end
i = i + 1
end
for i=1,#result do
if is_table] then
local name = result
result = deep_sort(current])
result.name = name
else
result = {name = result}
end
end
return result
end
function p.show(frame)
local children = {}
local function find_ancestors(origin,key,val)
if val.parent then
return {val.parent}
end
end
for key,val in pairs(scripts) do
local ancestors = find_ancestors(key,key,val)
if ancestors then
for _, ancestor in ipairs(ancestors) do
if ancestor ~= key then
if children then
table.insert(children, key)
else
children = {key}
end
end
end
end
end
local function make_nested(data)
local make_nil = {}
for key,val in pairs(data) do
if type(key) == "number" then
if children then
data = make_nested(children)
table.insert(make_nil, key)
children = nil
end
else
data = make_nested(val)
end
end
for _,key in ipairs(make_nil) do
data = nil
end
return data
end
local nested = make_nested(children)
nested = deep_sort(nested)
local result = ""
for i=1,#nested do
result = result .. "\n\n\n{| class=mw-collapsible style=border-collapse:collapse\n|" .. format(nested.name) .. "\n|-\n|"
result = result .. dump(nested, " ")
result = result .. "\n|}"
end
return frame:preprocess(result)
end
return p