Modul:category tree/scriptcatboiler

This module implements {{scriptcatboiler}}. The documentation here describes how the module works, and how to add, modify or remove information from the category tree. For information on how to use the template itself, see its documentation.

Data modules

ännern

The information on each label for this template is contained in Module:category tree/scriptcatboiler/data.

The following values are recognised in this data module:

parents
A table listing one or more parent labels of this label.
  • An item in the table can be either a single string, or a table containing two elements called name and sort. In the latter case, name value specifies the parent label name, while the sort value specifies the sort key to use to sort it in that category.
  • If a parent label begins with Category: it is interpreted as a raw category name, rather than as a label name. It can still have its own sort key as usual.
fundamental
The "fundamental" category name, which is the parent category that all umbrella categories are collected in.
sortparentumbrella
The sort key used to sort the umbrella category within the fundamental category. This generally defaults to the display name, but can be overridden with something like ** for root categories to make them easier to find.
description
A plain English description for the label.

Special template-like parameters can be used inside the parents and description values. These are replaced by the equivalent text.

{{{scname}}}
The name of the script that the category belongs to.
{{{sccat}}}
The name of the script's main category, which adds "script" to the regular name.

local export = {}
 
local labels = require("Module:category tree/scriptcatboiler/data")
 
 
-- Category object
 
local Category = {}
Category.__index = Category
 
 
function Category.new(info)
	local self = setmetatable({}, Category)
	assert(type(info) == "table", "The \"info\" parameter must be a table.")
	self._info = {}
 
	for key, val in pairs(info) do
		if key == "code" then
			self._info.code = val
			self._sc = require("Module:scripts").getByCode(val) or error("The script code \"" .. val .. "\" is not valid.")
		elseif key == "label" then
			self._info.label = val
			self._data = labels[self._info.label]
		else
			error("The parameter \"" .. key .. "\" was not recognized.")
		end
	end
 
	-- Check if the label exists
	if not self._info.label then
		error("No label was specified.")
	elseif not self._data then
		return nil
	end
 
	if self._info.label == "ROOT" and not self._sc then
		return nil
	end
 
	return self
end
 
export.new = Category.new
 
 
function Category:getBreadcrumbName()
	if self._info.label == "ROOT" then
		return self._sc:getCategoryName()
	else
		return self._info.label
	end
end
 
 
function Category:getBild()
	local Bild = self._data["Bild"]
 
	if Bild then
		return 
			"[[Image:" .. Bild .. "|left|100px]]"
    else
		return
    end
end
 
 
function Category:getDataModule()
	return "Module:category tree/scriptcatboiler/data"
end
 
 
function Category:canBeEmpty()
	return self._info.label == "ROOT"
end
 
 
function Category:getCategoryName()
	if self._sc then
		local ret = nil
 
		if self._info.label ~= "ROOT" then
			if self._info.label == "spraken" then
				return "Spraken in " .. self._sc:getCategoryName()
			elseif self._info.label == "teken" then
				return self._sc:getCategoryName() .. "teken"
			else
				ret = " " .. self._info.label
			end
		end
 
		return mw.getContentLanguage():ucfirst(self._sc:getCategoryName() .. (ret or ""))
	else
		return mw.getContentLanguage():ucfirst(self._info.label .. " bi Schrift")
	end
end
 
 
function Category:getDescription()
	if self._sc then
		local ret = self._data["description"]
 
		if ret then
			if ret:find("{{{code}}}") then ret = ret:gsub("{{{code}}}", self._sc:getCode()) end
			if ret:find("{{{scname}}}") then ret = ret:gsub("{{{scname}}}", self._sc:getCanonicalName()) end
			if ret:find("{{{sccat}}}") then ret = ret:gsub("{{{sccat}}}", self._sc:getCategoryName()) end
		end
 
		return ret
	else
		return "Categories with " .. self._info.label .. " of various specific scripts."
	end
end
 
 
function Category:getParents()
	if self._sc then
		local parents = self._data["parents"]
 
		if not parents or #parents == 0 then
			return nil
		end
 
		local ret = {}
 
		for key, parent in ipairs(parents) do
			local parent = mw.clone(parent)
 
			if type(parent) == "table" then
				parent.sort = parent.sort:gsub("{{{scname}}}", self._sc:getCanonicalName())
				parent.sort = parent.sort:gsub("{{{sccat}}}", self._sc:getCategoryName())
			else
				parent = {name = parent, sort = self._info.label}
			end
 
			if parent.name:find("^Kategorie:") then
				parent.name = parent.name:gsub("{{{scname}}}", self._sc:getCanonicalName())
				parent.name = parent.name:gsub("{{{sccat}}}", self._sc:getCategoryName())
			else
				local pinfo = mw.clone(self._info)
				pinfo.label = parent.name
				parent.name = Category.new(pinfo)
			end
 
			table.insert(ret, parent)
		end
 
		return ret
	else
		if self._data["fundamental"] then
			return {{name = "Kategorie:" .. self._data["fundamental"], sort = self._data["sortparentumbrella"] or self._info.label}}
		else
			return nil
		end
	end
end
 
 
function Category:getChildren()
	local children = self._data["children"]
 
	if not self._sc or not children or #children == 0 then
		return nil
	end
 
	local ret = {}
 
	for _, child in ipairs(children) do
		child = mw.clone(child)
 
		if type(child) ~= "table" then
			child = {name = child, sort = child}
		end
 
		local cinfo = mw.clone(self._info)
		cinfo.label = child.name
		child.name = Category.new(cinfo)
 
		table.insert(ret, child)
	end
 
	return ret
end
 
 
function Category:getUmbrella()
	if not self._sc then
		return nil
	end
 
	local uinfo = mw.clone(self._info)
	uinfo.code = nil
	return Category.new(uinfo)
end
 
 
return export