ข้ามไปเนื้อหา

มอดูล:category tree/templates

จาก วิกิพจนานุกรม พจนานุกรมเสรี

local export = {}

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

function export.get_item(frame)
	local params = {
		[1] = {required = true},
		["template"] = {required = true},
		["code"] = {},
		["label"] = {},
		["sc"] = {},
	}
	
	local args = require("Module:parameters").process(frame.args, params)
	
	local info = {code = args["code"], label = args["label"], sc = args["sc"]}
	local submodule = require("Module:category tree/" .. args["template"])
	local obj = submodule.new(info)
	
	local item = args[1]
	
	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