Module:columns: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
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 m_inline = require("Module:inline") | |||
local params = { | local params = { | ||
Line 11: | Line 12: | ||
["t"] = {list = true, allow_holes = true}, | ["t"] = {list = true, allow_holes = true}, | ||
["pos"] = {list = true, allow_holes = true}, | ["pos"] = {list = true, allow_holes = true}, | ||
["columns"] = {type = "int", default = 2, | ["a"] = {list = true, allow_holes = true}, | ||
["nohere"] = {type = "boolean"}, | |||
["columns"] = {type = "int", default = 2}, | |||
["cols"] = {alias_of = "columns"}, | |||
["anchor"] = {alias_of = "a"}, | |||
} | } | ||
function export.create_list(data) | function export.create_list(data) | ||
if not data.terms then error("{{columns}} must be supplied with a list of terms") end | if not data.terms then error("{{columns}} must be supplied with a list of terms") end | ||
table.sort(data.terms, function(a, b) return a.term < b.term end) | |||
local out = '<div class="ul-columns" data-column-count="' .. data.columns .. '">' | local out = '<div class="ul-columns" data-column-count="' .. data.columns .. '">' | ||
for _, term in ipairs(terms) do | for _, term in ipairs(data.terms) do | ||
out = out .. '\n* ' .. m_links.full_link{term = term.term, language = data.language, alt = term.alt, gloss = | out = out .. '\n* ' .. m_links.full_link{term = term.term, language = data.language, alt = term.alt, gloss = term.gloss, pos = term.pos, anchor = term.anchor} | ||
end | end | ||
return out .. '\n</div>' | return out .. '\n</div>' | ||
Line 30: | Line 35: | ||
local i = 1 | local i = 1 | ||
while args[2][i] do | while args[2][i] do | ||
table.insert(terms, { | local i_term, i_args = m_inline.parse(args[2][i]) | ||
if not (args.nohere and i_term == mw.title.getCurrentTitle().text) then | |||
table.insert(terms, { | |||
term = i_term, | |||
alt = args["alt"][i] or i_args["alt"], | |||
gloss = args["t"][i] or i_args["t"], | |||
pos = args["pos"][i] or i_args["pos"], | |||
anchor = args["a"][i] or i_args["a"] or i_args["anchor"], | |||
}) | |||
end | |||
i = i + 1 | i = i + 1 | ||
end | end |
Latest revision as of 11:26, 5 April 2024
Documentation for this module may be created at Module:columns/documentation
local export = {}
local m_languages = require("Module:languages")
local m_links = require("Module:links")
local m_parameters = require("Module:parameters")
local m_inline = require("Module:inline")
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},
["a"] = {list = true, allow_holes = true},
["nohere"] = {type = "boolean"},
["columns"] = {type = "int", default = 2},
["cols"] = {alias_of = "columns"},
["anchor"] = {alias_of = "a"},
}
function export.create_list(data)
if not data.terms then error("{{columns}} must be supplied with a list of terms") end
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(data.terms) do
out = out .. '\n* ' .. m_links.full_link{term = term.term, language = data.language, alt = term.alt, gloss = term.gloss, pos = term.pos, anchor = term.anchor}
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[2][i] do
local i_term, i_args = m_inline.parse(args[2][i])
if not (args.nohere and i_term == mw.title.getCurrentTitle().text) then
table.insert(terms, {
term = i_term,
alt = args["alt"][i] or i_args["alt"],
gloss = args["t"][i] or i_args["t"],
pos = args["pos"][i] or i_args["pos"],
anchor = args["a"][i] or i_args["a"] or i_args["anchor"],
})
end
i = i + 1
end
return export.create_list{
terms = terms,
language = language,
columns = args["columns"],
}
end
return export