Module:nyms: Difference between revisions

From Laenkea
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...")
 
No edit summary
Line 2: Line 2:


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},
}


function export.make_nym_list(data)
function export.make_nym_list(data)
Line 8: Line 14:
table.insert(links, m_links.full_link{term = term, language = data.language})
table.insert(links, m_links.full_link{term = term, language = data.language})
end
end
local out = '<span class="nyms-toggle" data-label="' .. data.label .. '"></span>'
local out = '<span class="nyms-toggle" data-label="' .. mw.ustring.lower(data.label) .. '"></span>'
out = out .. '<dl><dd><span class="nyms">'
out = out .. '<dl><dd><span class="nyms">'
out = out .. '<span class="nyms-label">' .. data.label .. '</span>'
out = out .. '<span class="nyms-label">' .. data.label .. ':</span>'
out = out .. table.concat(links, ", ")
out = out .. table.concat(links, ", ")
out = out .. '</span></dd></dl>'
out = out .. '</span></dd></dl>'
return out
return out
end
function export.show_synonyms(frame)
local args = m_parameters.process(frame:getParent().args, params)
return export.make_nym_list{
label = "Synonyms",
language = args[1],
terms = args[2],
}
end
function export.show_antonyms(frame)
local args = m_parameters.process(frame:getParent().args, params)
return export.make_nym_list{
label = "Antonyms",
language = args[1],
terms = args[2],
}
end
end


return export
return export

Revision as of 11:28, 11 August 2023

Documentation for this module may be created at Module:nyms/documentation

local export = {}

local m_links = require("Module:links")
local m_parameters = require("Module:parameters")

local params = {
	[1] = {required = true},
	[2] = {list = true},
}

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="' .. mw.ustring.lower(data.label) .. '"></span>'
	out = out .. '<dl><dd><span class="nyms">'
	out = out .. '<span class="nyms-label">' .. data.label .. ':</span>'
	out = out .. table.concat(links, ", ")
	out = out .. '</span></dd></dl>'
	return out
end

function export.show_synonyms(frame)
	local args = m_parameters.process(frame:getParent().args, params)
	return export.make_nym_list{
		label = "Synonyms",
		language = args[1],
		terms = args[2],
	}
end

function export.show_antonyms(frame)
	local args = m_parameters.process(frame:getParent().args, params)
	return export.make_nym_list{
		label = "Antonyms",
		language = args[1],
		terms = args[2],
	}
end

return export