A modult a Modul:number list/show/doc lapon tudod dokumentálni
local export = {}
local m_number_list = require("Module:number list")
local function compare_numbers(a, b)
a, b = tonumber(a), tonumber(b)
return a < b
end
function export.print_table(language_code)
local module = require("Module:number list/data/" .. language_code)
local lang = require("Module:languages").getByCode(language_code)
local full_link = require("Module:links").full_link
local tag_text = require("Module:script utilities").tag_text
local function link(form)
return full_link({ lang = lang, term = form})
end
local function tag(form)
return tag_text(form, lang)
end
local form_types = m_number_list.get_number_types(language_code)
local numeral_index = 1
table.insert(form_types, numeral_index,
{key = "numeral", display = "Numeral"})
local number_type_indices = {}
for number, data in pairs(module.numbers) do
for i, form_type in pairs(form_types) do
if data then
number_type_indices = true
end
end
end
local numeral_config = module.numeral_config
if numeral_config then
number_type_indices = true
end
number_type_indices = require("Module:table").keysToList(number_type_indices)
local Array = require("Module:array")
local output = Array()
local function header(content)
output:insert(("! %s"):format(content))
end
local function cell(content)
output:insert(("| %s"):format(content))
end
local function row(content)
output:insert("|-\n")
if content then
cell(content)
end
end
output:insert('{| class="wikitable"')
-- Add headers.
header("Number")
for _, index in ipairs(number_type_indices) do
header(m_number_list.display_number_type(form_types))
end
for number, data in require("Module:table").sortedPairs(module.numbers, compare_numbers) do
local number_string
if type(number) == "number" then
number_string = ("%.0f"):format(number)
else
number_string = number
end
row(number)
local numeral
if numeral_config then
numeral = m_number_list.generate_decimal_numeral(numeral_config, number)
elseif data.numeral then
numeral = data.numeral
end
if numeral then
numeral = tag(numeral)
cell(numeral or "")
end
for _, i in ipairs(number_type_indices) do
if i ~= numeral_index then
local form = data.key]
cell(type(form) == "table" and Array(form):map(link):concat(", ")
or form and link(form)
or "")
end
end
end
output:insert('|}')
return output:concat("\n")
end
function export.table(frame)
local language_code
if frame then
language_code = frame.args
end
if not language_code then
language_code = mw.title.getCurrentTitle().fullText:match("Module:number list/data/(+)")
if not language_code then
error("No language code in title or in parameter 1.")
end
if language_code == "und" then
return
end
end
return export.print_table(language_code)
end
return export