Modul:category tree/templates

Vun Wiktionary
Dissen Vörlaag hef dokumentatsie neudig.
Maak de dokumentatsie veur dissen modul ovver t doel en gebroek op de dokumentatsieziede.

local export = {}

function export.exists(frame)
	local args = frame.args
	local template = args["template"]; if template == "" then template = nil end
	
	local info = {}
	info.code = args["code"]; if info.code == "" then info.code = nil end
	info.label = args["label"]; if info.label == "" then info.label = nil end
	info.sc = args["sc"]; if info.sc == "" then info.sc = nil end
	
	local submodule = require("Module:category tree/" .. template)
	
	local obj = submodule.new(info)
	
	return (obj ~= nil and "1" or "")
end

function export.get_item(frame)
	local args = frame.args
	local template = args["template"]; if template == "" then template = nil end
	local item = args[1]; if item == "" then item = nil end
	
	local info = {}
	info.code = args["code"]; if info.code == "" then info.code = nil end
	info.label = args["label"]; if info.label == "" then info.label = nil end
	info.sc = args["sc"]; if info.sc == "" then info.sc = nil end
	
	local submodule = require("Module:category tree/" .. template)
	
	local obj = submodule.new(info)
	
	if item:find("^umbrella_") then
		item = item:gsub("^umbrella_", "")
		obj = obj:getUmbrella()
	end
	
	if obj and obj[item] then
		ret = obj[item](obj)
	else
		error("The requested data item \"" .. item .. "\" is not recognized.")
	end
	
	if not ret then
		return ""
	else
		return ret
	end
end

return export