Module:auto cat: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local export = {}
local export = {}


local auto_categories = {
local submodules = {"languages", "rhymes", "topics"}
{match = "Rhymes:{{language}}/{{rhyme}}", parents = {"Rhymes:{{language}}"}},
local handlers = {}
{match = "Rhymes:{{language}}", parents = {"Rhymes"}},
 
{match = "{{language}} terms derived from {{source}}", parents = {"Terms derived from {{source}}", "{{language}} derived terms"}},
local function format_categories(categories)
{match = "{{language}} terms inherited from {{source}}", parents = {"Terms inherited from {{source}}", "{{language}} inherited terms"}},
local cats = ""
{match = "{{language}} terms borrowed from {{source}}", parents = {"Terms borrowed from {{source}}", "{{language}} borrowed terms"}},
for _, cat in ipairs(categories) do
{match = "{{language}} terms derived from the {{source}} root {{root}}", parents = {"{{language}} terms by {{source}} root", "Terms derived from the {{source}} root {{root}}"}}
cats = cats .. "[[" .. cat .. "]]"
}
end
return cats
end
 
function export.show(frame)
local title_obj = mw.title.getCurrentTitle()
if title_obj.nsText ~= "Category" then
error("{{auto cat}} can only be used on pages in the Category: namespace")
end
for _, m in ipairs(submodules) do
local handler = require(m).handler
if handler then table.insert(handlers, handler) end
end
for _, handler in ipairs(handlers) do
r_cats, r_match = handler(title_obj)
if r_match then
return format_categories(r_cats)
end
end
error("{{auto cat}} could not recognise the format of this category name")
end


return export
return export

Revision as of 10:20, 7 August 2023

local export = {}

local submodules = {"languages", "rhymes", "topics"}
local handlers = {}

local function format_categories(categories)
	local cats = ""
	for _, cat in ipairs(categories) do
		cats = cats .. "[[" .. cat .. "]]"
	end
	return cats
end

function export.show(frame)
	local title_obj = mw.title.getCurrentTitle()
	if title_obj.nsText ~= "Category" then
		error("{{auto cat}} can only be used on pages in the Category: namespace")
	end
	
	for _, m in ipairs(submodules) do
		local handler = require(m).handler
		if handler then table.insert(handlers, handler) end
	end
	for _, handler in ipairs(handlers) do
		r_cats, r_match = handler(title_obj)
		if r_match then
			return format_categories(r_cats)
		end
	end
	
	error("{{auto cat}} could not recognise the format of this category name")
end

return export