2,788
edits
(Created page with "local export = {} local html = mw.html.create local m_languages = require("Module:languages") local m_links = require("Module:links") local m_parameters = require("Module:parameters") function export.create_list(data) if not data.language then error("no language was provided to columns.create_list") end end") |
No edit summary |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local m_languages = require("Module:languages") | local m_languages = require("Module:languages") | ||
local m_links = require("Module:links") | local m_links = require("Module:links") | ||
local m_parameters = require("Module:parameters") | local m_parameters = require("Module:parameters") | ||
local params = { | |||
[1] = {required = true}, | |||
[2] = {list = true, allow_holes = true}, | |||
["alt"] = {list = true, allow_holes = true}, | |||
["t"] = {list = true, allow_holes = true}, | |||
["pos"] = {list = true, allow_holes = true}, | |||
["columns"] = {type = "int", default = 2, aliases = {"cols"}}, | |||
} | |||
function export.create_list(data) | function export.create_list(data) | ||
local terms = table.sort(data.terms, function(a, b) return a.term > b.term end) | |||
local out = '<div class="ul-columns" data-column-count="' .. data.columns .. '">' | |||
for _, term in ipairs(terms) do | |||
out = out .. '\n* ' .. m_links.full_link{term = term.term, language = data.language, alt = term.alt, gloss = text.gloss, pos = text.pos} | |||
end | |||
return out .. '\n</div>' | |||
end | |||
function export.show(frame) | |||
local args = m_parameters.process(frame:getParent().args, params) | |||
local language = m_languages.get_by_code(args[1]) | |||
local terms = {} | |||
local i = 1 | |||
while args[i + 1] do | |||
table.insert(terms, { | |||
term = args[2][i], | |||
alt = args["alt"][i], | |||
gloss = args["t"][i], | |||
pos = args["pos"][i], | |||
}) | |||
i = i + 1 | |||
end | |||
return export.create_list{ | |||
terms = terms, | |||
language = language, | |||
columns = args["columns"], | |||
} | |||
end | end | ||
return export |