Modul:category tree/classifier cat

A modult a Modul:category tree/classifier cat/doc lapon tudod dokumentálni

local export = {}

-- Category object

local Category = {}
Category.__index = Category


function Category.new_main(frame)
	local params = {
		[1] = {required = true},
		[2] = {required = true},
		[3] = {required = true},
	}
	
	args = require("Module:parameters").process(frame:getParent().args, params)
	
	return Category.new({lang = args[1], pos = args[2], classifier = args[3]})
end


function Category.new(info)
	for key, val in pairs(info) do
		if not (key == "lang" or key == "pos" or key == "classifier") then
			error("The parameter \"" .. key .. "\" was not recognized. "
				.."Recognized parameters are \"lang\", \"pos\", and \"classifier\".")
		end
	end
	
	if not info.lang then
		error("No current language code was specified.")
	end
	
	if not info.pos then
		error("No part of speech was specified.")
	end
	
	if not info.classifier then
		error("No classifier was specified.")
	end
	
	local self = setmetatable({}, Category)
	self._info = info

	self._lang = type(info.lang) == "table" and info.lang.getCode and info.lang
		or require("Module:languages").getByCode(info.lang, true)
	
	return self
end

export.new = Category.new
export.new_main = Category.new_main


function Category:getInfo()
	return self._info
end


function Category:getBreadcrumbName()
	return self._info.classifier
end


function Category:getDataModule()
	return "Module:category tree/classifier cat"
end


function Category:canBeEmpty()
	return false
end


function Category:isHidden()
	return false
end


function Category:getCategoryName()
	return self._lang:getCanonicalName() .. " " .. self._info.pos .. " classified by " .. self._info.classifier
end


function Category:getDescription()
	local linktext
	if self._lang:getCode() == "zh" then
		linktext = require("Module:zh").link(nil, nil, { self._info.classifier, tr = "-" }, self._info.classifier)
	else
		linktext = require("Module:links").full_link { term = self._info.classifier, lang = self._lang }
	end
	return self._lang:makeCategoryLink() .. " " .. self._info.pos .. " using " .. linktext .. " as their classifier."
end


function Category:getParents()
	local categories = {}
	
	table.insert(categories,
		{name = require("Module:category tree/poscatboiler").new{code = self._lang:getCode(), label = self._info.pos .. " by classifier"},
			sort = self._lang:getCode() == "zh" and require("Module:zh-sortkey").makeSortKey(self._info.classifier) or self._info.classifier
		})

	return categories
end


function Category:getChildren()
	return nil
end


function Category:getUmbrella()
	return nil
end


return export

-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: