Module:TreeChart
Appearance
local p = {}
local cells = mw.loadData('Module:Sandbox/The Mol Man/data')
function p.main(frame)
local args = frame:getParent().args
local cell_args = {}
for i, v in ipairs(args) do
local w = mw.text.trim(v)
if not w:find('%S') then
w = '$'
end
local cell_x = { }
if cells[w] then
cell_x.name = w
else
-- Unnamed params behave weirdly
-- white space at the front counts, but not whitespace at the end
local w2 = v:gsub('^(.*) +$','%1')
cell_x.text = (args[w] or '{{{'..w..'}}}')
cell_x.box = true
cell_x.colspan = args['colspan_'..w2] or args.colspan or '6'
cell_x.rowspan = args['rowspan_'..w2] or args.rowspan or '2'
cell_x.thick = args['border_'..w2] or args.border or '2'
cell_x.css = args['boxstyle_'..w2] or args.boxstyle or ''
end
table.insert(cell_args,cell_x)
end
return p._main(cell_args)
end
function p._main(cell_args)
local ret = mw.html.create('tr')
:css({ ['height'] = '1px',
['text-align'] = 'center' })
local ret2 = mw.html.create('tr')
:css({ ['height'] = '1px',
['text-align'] = 'center' })
for i, v in ipairs(cell_args) do
if v.box then
make_box(ret,v)
else
make_cell(ret,v.name,'t')
make_cell(ret2,v.name,'b')
end
end
return tostring(ret) .. tostring(ret2)
end
function make_cell(builder,name,key)
local props = cells[name][key]
if not props then
return
end
for i, v in ipairs(props) do
builder:tag(v.tag,{selfClosing=true})
:css(v.style or {})
:attr(v.attr or {})
end
end
function make_box(builder,tbl)
builder:tag('td')
:attr('colspan',tbl.colspan)
:attr('rowspan',tbl.rowspan)
:css({ ['padding'] = '0.2em',
['border'] = tbl.thick .. 'px solid black' })
:cssText(tbl.css)
:wikitext(tbl.text)
:done()
end
return p