Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.

Used by Template:Scope Classification; see the template page for more information.


local yesno = require('Module:Yesno')

local p = {}

local fields = {
	'domain',
	'essence',
	'framework'
}
local field_values = {
	{
		{ 'empirical', '[[Amaranth Legacy:Scope Classification#Empirical Domain|Empirical]]' },
		{ 'hybrid', '[[Amaranth Legacy:Scope Classification#Hybrid Domain|Hybrid]]' },
		{ 'mythic', '[[Amaranth Legacy:Scope Classification#Mythic Domain|Mythic]]' }
	},
	{
		{ 'empirical',  '[[Amaranth Legacy:Scope Classification#Empirical Essence|Empirical]]' },
		{ 'hybrid',  '[[Amaranth Legacy:Scope Classification#Hybrid Essence|Hybrid]]' },
		{ 'mythic',  '[[Amaranth Legacy:Scope Classification#Mythic Essence|Mythic]]' }
	},
	{
		{ 'overarching',  '[[Amaranth Legacy:Scope Classification#Overarching Framework|Overarching]]' },
		{ 'focused',  '[[Amaranth Legacy:Scope Classification#Focused Framework|Focused]]' },
		{ 'esoteric',  '[[Amaranth Legacy:Scope Classification#Esoteric Framework|Esoteric]]' }
	}
}

local function capitalize(str)
	return (str:gsub("^%l", string.upper))
end

local function generateCategoryLink(field, value)
	return '[[Category:META: Scope Classification: ' .. capitalize(field) .. ': ' .. capitalize(value) .. ']]\n'
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame:getParent())

	-- table and table headers
	local table = mw.html.create('table'):addClass('template-scope_classification')
		:tag('tr')
			:tag('th')
				:wikitext('[[Amaranth Legacy:Scope Classification#Domain|Domain]]')
			:done()
			:tag('th')
				:wikitext('[[Amaranth Legacy:Scope Classification#Essence|Essence]]')
			:done()
			:tag('th')
				:wikitext('[[Amaranth Legacy:Scope Classification#Framework|Framework]]')
			:done()
		:done()
	local categories = ''

	-- table fields row
	local row = mw.html.create('tr')
	for index, values in ipairs(field_values) do
		local field = fields[index]
		-- create the data cell
		local td = row:tag('td')
		if args[field .. '_diremption'] then
			-- add to the categories
			categories = categories .. generateCategoryLink(field, 'diremption')
			-- there are multiple possible values
			td:wikitext("''[[Amaranth Legacy:Scope Classification#Diremption|Diremption]]:''"):newline()
			for _, value in ipairs(values) do
				if yesno(args[field ..  '_' .. value[1]] or false) then
					-- add to the categories
					categories = categories .. generateCategoryLink(field, value[1])
					-- append the content to the wikitext list
					td:wikitext('*' .. value[2]):newline()
				end
			end
		else
			-- there is only one value
			for _, value in ipairs(values) do
				if yesno(args[field ..  '_' .. value[1]] or false) then
					-- add to the categories
					categories = categories .. generateCategoryLink(field, value[1])
					-- set the content to the wikitext
					td:wikitext(value[2])
					-- stop
					break
				end
			end
		end
	end
	table:node(row)

	if not yesno(args['add_categories'] or true) then
		categories = ''
	end

	return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Scope Classification/styles.css' } }
		.. tostring(table)
		.. '\n' .. categories
end

return p