Jump to content

Module:Tree chart/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
make same as parent
Line 1: Line 1:
require('strict')
--<nowiki>

local p = {}
local p = {}


Line 5: Line 6:


function p._main(cell_args)
function p._main(cell_args)
local ret = mw.html.create()
local ret = mw.html.create()
local top = ret:tag('tr')
local top = ret:tag('tr')
:css{ height = '1px',
:css{ height = '1px',
['text-align'] = 'center' }
['text-align'] = 'center' }
local bottom = ret:tag('tr')
local bottom = ret:tag('tr')
:css{ height = '1px',
:css{ height = '1px',
['text-align'] = 'center' }
['text-align'] = 'center' }
for _, v in ipairs(cell_args) do
for _, v in ipairs(cell_args) do
if type(v) == 'string' then
if type(v) == 'string' then
top:wikitext(cells[v].t)
top:wikitext(cells[v].t)
bottom:wikitext(cells[v].b)
bottom:wikitext(cells[v].b)
else
else
top:tag('td')
top:tag('td')
:attr{ colspan = v.colspan or cell_args.colspan or 6,
:attr{ colspan = v.colspan or cell_args.colspan or 6,
rowspan = v.rowspan or cell_args.rowspan or 2,
rowspan = v.rowspan or cell_args.rowspan or 2 }
:css{ padding = '0.2em',
class = 'ft-colored-box' }
border = (v.border or cell_args.border or '2') .. 'px solid black' }
:css{ padding = '0.2em',
border = (v.border or cell_args.border or '2') .. 'px solid' }
:cssText(v.boxstyle or cell_args.boxstyle)
:wikitext(v.text)
:cssText(v.boxstyle or cell_args.boxstyle)
end
:wikitext(v.text)
end
end
return tostring(ret)
end
return tostring(ret)
end
end


function p.main(frame)
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Tree chart', trim = false, removeBlanks = false})
local args = frame:getParent().args
local cell_args = {
local cell_args = {
colspan = args.colspan,
colspan = args.colspan,
rowspan = args.rowspan,
rowspan = args.rowspan,
border = args.border,
border = args.border,
boxstyle = args.boxstyle
boxstyle = args.boxstyle
}
}
for _, val in ipairs(args) do
for _, val in ipairs(args) do
local trimmedVal = val:match('^%s*(.-)%s*$')
local trimmedVal = val:match('^%s*(.-)%s*$')
if trimmedVal == '' then
if trimmedVal == '' then
trimmedVal = '$'
trimmedVal = '$'
end
end
if cells[trimmedVal] then
if cells[trimmedVal] then
table.insert(cell_args, trimmedVal)
table.insert(cell_args, trimmedVal)
else
else
-- Unnamed params behave weirdly
-- Unnamed params behave weirdly
-- white space at the front counts for param_{{{1}}}, but not whitespace at the end, so remove it
-- white space at the front counts for param_{{{1}}}, but not whitespace at the end, so remove it
local rightTrimmedVal = val:gsub('%s+$','')
local rightTrimmedVal = val:gsub('%s+$','')
table.insert(cell_args, {
text = args[trimmedVal] or ('{{{'..trimmedVal..'}}}'),
--Shortcut for coloring female, male, and unknown boxes
local style = args['boxstyle_'..rightTrimmedVal]
colspan = args['colspan_'..rightTrimmedVal],
rowspan = args['rowspan_'..rightTrimmedVal],
local content = args[trimmedVal] or ('{{{'..trimmedVal..'}}}')
border = args['border_'..rightTrimmedVal],
if style ~= nil then
style = string.lower(args['boxstyle_'..rightTrimmedVal])
boxstyle = args['boxstyle_'..rightTrimmedVal]
})
if style == 'f' then
end
style = 'background-color: #FFDDE4;'
end
content = content .. "&nbsp;♀"
elseif style == 'm' then
return p._main(cell_args)
style = 'background-color: #BDE3FF;'
content = content .. "&nbsp;♂"
elseif style == 'u' then
style = 'background-color: #CECECE;'
elseif style == 'i' then
style = 'background-color: #CECECE; font-style: italic;'
else
style = args['boxstyle_'..rightTrimmedVal]
end
end
table.insert(cell_args, {
text = content,
colspan = args['colspan_'..rightTrimmedVal],
rowspan = args['rowspan_'..rightTrimmedVal],
border = args['border_'..rightTrimmedVal],
boxstyle = style
})
end
end
return p._main(cell_args)
end
end



Revision as of 13:13, 30 April 2024

require('strict')

local p = {}

local cells = mw.loadData('Module:Tree chart/data/sandbox')

function p._main(cell_args)
	local ret = mw.html.create()
	local top = ret:tag('tr')
						:css{ height = '1px',
								['text-align'] = 'center' }
	local bottom = ret:tag('tr')
						:css{ height = '1px',
								['text-align'] = 'center' }
	for _, v in ipairs(cell_args) do
		if type(v) == 'string' then
			top:wikitext(cells[v].t)
			bottom:wikitext(cells[v].b)
		else
			top:tag('td')
				:attr{ colspan = v.colspan or cell_args.colspan or 6,
						rowspan = v.rowspan or cell_args.rowspan or 2 }
				:css{ padding = '0.2em',
						border = (v.border or cell_args.border or '2') .. 'px solid black' }
				:cssText(v.boxstyle or cell_args.boxstyle)
				:wikitext(v.text)
		end
	end
	return tostring(ret)
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Tree chart', trim = false, removeBlanks = false})
	local cell_args = {
		colspan = args.colspan,
		rowspan = args.rowspan,
		border = args.border,
		boxstyle = args.boxstyle
	}
	for _, val in ipairs(args) do
		local trimmedVal = val:match('^%s*(.-)%s*$')
		if trimmedVal == '' then
			trimmedVal = '$'
		end
		if cells[trimmedVal] then
			table.insert(cell_args, trimmedVal)
		else
			-- Unnamed params behave weirdly
			-- white space at the front counts for param_{{{1}}}, but not whitespace at the end, so remove it
			local rightTrimmedVal = val:gsub('%s+$','')
			table.insert(cell_args, {
				text = args[trimmedVal] or ('{{{'..trimmedVal..'}}}'),
				colspan = args['colspan_'..rightTrimmedVal],
				rowspan = args['rowspan_'..rightTrimmedVal],
				border = args['border_'..rightTrimmedVal],
				boxstyle = args['boxstyle_'..rightTrimmedVal]
			})
		end
	end
	
	return p._main(cell_args)
end

return p