Module:nyms: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local export = {} local m_links = require("Module:links") function export.make_nym_list(data) local links = {} for _, term in ipairs(data.terms) do table.insert(links, m_links.full_link{term = term, language = data.language}) end local out = '<span class="nyms-toggle" data-label="' .. data.label .. '"></span>' out = out .. '<dl><dd><span class="nyms">' out = out .. '<span class="nyms-label">' .. data.label .. '</span>' out = out .. table.concat(links, ", ") o...") |
TheNightAvl (talk | contribs) No edit summary |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local m_inline = require("Module:inline") | |||
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 params = { | |||
[1] = {required = true}, | |||
[2] = {list = true}, | |||
["t"] = {list = true, allow_holes = true}, | |||
["pos"] = {list = true, allow_holes = true}, | |||
} | |||
function export.make_nym_list(data) | function export.make_nym_list(data) | ||
local links = {} | local links = {} | ||
for | local plural = "" | ||
table.insert(links, m_links.full_link{term = | for i, term in ipairs(data.terms) do | ||
local i_term, i_args = m_inline.parse(term) | |||
table.insert( | |||
links, | |||
m_links.full_link{ | |||
term = i_term, | |||
language = data.language, | |||
gloss = i_args["t"] or data.glosses[i], | |||
pos = i_args["pos"] or data.pos[i], | |||
} | |||
) | |||
end | end | ||
table.sort(links, function(a, b) return a < b end) | |||
if #links > 1 then plural = "s" end | |||
return '<span class="nyms" data-label="' .. data.label .. 's"><span class="nyms-label">' .. data.label:gsub("^%l", string.upper) .. plural .. ':</span> ' .. table.concat(links, ", ") .. '</span>' | |||
end | |||
return | function export.show(frame) | ||
local args = m_parameters.process(frame:getParent().args, params) | |||
return export.make_nym_list{ | |||
label = frame.args[1], | |||
language = m_languages.get_by_code(args[1]), | |||
terms = args[2], | |||
pos = args["pos"], | |||
glosses = args["t"], | |||
} | |||
end | end | ||
return export | return export |
Latest revision as of 19:47, 10 March 2024
Documentation for this module may be created at Module:nyms/documentation
local export = {}
local m_inline = require("Module:inline")
local m_languages = require("Module:languages")
local m_links = require("Module:links")
local m_parameters = require("Module:parameters")
local params = {
[1] = {required = true},
[2] = {list = true},
["t"] = {list = true, allow_holes = true},
["pos"] = {list = true, allow_holes = true},
}
function export.make_nym_list(data)
local links = {}
local plural = ""
for i, term in ipairs(data.terms) do
local i_term, i_args = m_inline.parse(term)
table.insert(
links,
m_links.full_link{
term = i_term,
language = data.language,
gloss = i_args["t"] or data.glosses[i],
pos = i_args["pos"] or data.pos[i],
}
)
end
table.sort(links, function(a, b) return a < b end)
if #links > 1 then plural = "s" end
return '<span class="nyms" data-label="' .. data.label .. 's"><span class="nyms-label">' .. data.label:gsub("^%l", string.upper) .. plural .. ':</span> ' .. table.concat(links, ", ") .. '</span>'
end
function export.show(frame)
local args = m_parameters.process(frame:getParent().args, params)
return export.make_nym_list{
label = frame.args[1],
language = m_languages.get_by_code(args[1]),
terms = args[2],
pos = args["pos"],
glosses = args["t"],
}
end
return export