Module:gender and number doc
Appearance
- මෙම module සතුව උපදෙස් උප පිටුවක් නොපවතියි. Please නිර්මාණය කරන්න.
- ප්රයෝජනවත් සබැඳි: උප පිටු ලැයිස්තුව • සබැඳි • transclusions • testcases • sandbox
--[=[
This module contains functions to display user-readable tables of the contents of [[Module:gender and number/data]].
Author: Benwing2
]=]
local export = {}
local data = require("Module:gender and number/data")
local function make_code(text)
return "<code>" .. text .. "</code>"
end
-- Sort codes first by type, using the order specified below in `type_order`, then by code.
local type_order = {"gender", "number", "animacy", "virility", "aspect", "other"}
local type_to_index = {}
for i, typ in ipairs(type_order) do
type_to_index[typ] = i
end
local function get_type_index(typ)
return type_to_index[typ] or 50
end
function export.gender_and_number_table(frame)
local alldata = {}
-- Convert table of codes to a list of information.
for code, desc in pairs(data.codes) do
local obj = {
code = make_code(code),
type = desc.type,
display = desc.display,
cat = desc.cat and make_code(desc.cat) or "—",
}
table.insert(alldata, obj)
end
table.sort(alldata, function(obj1, obj2)
local typind1 = get_type_index(obj1.type)
local typind2 = get_type_index(obj2.type)
if typind1 == typeind2 then
return obj1.code < obj2.code
else
return typind1 < typind2
end
end)
-- Convert to wikitable.
local parts = {}
table.insert(parts, '{|class="wikitable"')
table.insert(parts, "! Code !! Type !! Display form !! Category")
local last_type = nil
for _, obj in ipairs(alldata) do
table.insert(parts, "|-" .. (obj.type ~= last_type and ' style="border-top: 3px solid blue;"' or ""))
local sparts = {}
table.insert(sparts, obj.code)
table.insert(sparts, obj.type)
table.insert(sparts, obj.display)
table.insert(sparts, obj.cat)
table.insert(parts, "| " .. table.concat(sparts, " || "))
last_type = obj.type
end
table.insert(parts, "|}")
return table.concat(parts, "\n")
end
function export.combinations_table(frame)
local alldata = {}
-- Convert table of combination codes to a list of information.
for code, desc in pairs(data.combinations) do
local codes = desc.codes
for i, indiv_code in ipairs(codes) do
codes[i] = make_code(indiv_code)
end
local obj = {
code = make_code(code),
codes = table.concat(codes, ", "),
addl_display = desc.display or "—",
cat = desc.cat and make_code(desc.cat) or "—",
}
table.insert(alldata, obj)
end
-- Sort codes by code.
table.sort(alldata, function(obj1, obj2) return obj1.code < obj2.code end)
-- Convert to wikitable.
local parts = {}
table.insert(parts, '{|class="wikitable"')
table.insert(parts, "! Combination !! Individual codes !! Additional display text !! Category")
for _, obj in ipairs(alldata) do
table.insert(parts, "|-")
local sparts = {}
table.insert(sparts, obj.code)
table.insert(sparts, obj.codes)
table.insert(sparts, obj.addl_display)
table.insert(sparts, obj.cat)
table.insert(parts, "| " .. table.concat(sparts, " || "))
end
table.insert(parts, "|}")
return table.concat(parts, "\n")
end
function export.multicode_table(frame)
local alldata = {}
-- Convert table of multicode categories to a list of information.
for type, cat in pairs(data.multicode_cats) do
local obj = {
type = make_code(type),
cat = make_code(cat),
}
table.insert(alldata, obj)
end
-- Sort by type.
table.sort(alldata, function(obj1, obj2) return get_type_index(obj1.type) < get_type_index(obj2.type) end)
-- Convert to wikitable.
local parts = {}
table.insert(parts, '{|class="wikitable"')
table.insert(parts, "! Type !! Category when multiple codes of that type are present")
for _, obj in ipairs(alldata) do
table.insert(parts, "|-")
local sparts = {}
table.insert(sparts, obj.type)
table.insert(sparts, obj.cat)
table.insert(parts, "| " .. table.concat(sparts, " || "))
end
table.insert(parts, "|}")
return table.concat(parts, "\n")
end
return export