Module:TreeChart
Appearance
You might want to बनाईं a documentation page for this Scribunto module. संपादक लोग एह मॉड्यूल के अभ्यासपन्ना (सैंडबाक्स) (बनाईं | मिरर करीं) आ टेस्टकेस (बनाईं) पन्ना पर अभ्यास भा प्रयोग (टेस्टिंग) क सकत बाटे। अनुरोध बा कि अगर श्रेणी जोड़े के होखे तब /doc उपपन्ना (सबपेज) पर जोड़ल जाय। एह मॉड्यूल के उपपन्ना (सबपेज) देखीं। |
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
cell_x.text = args[w] or '{{{'..w..'}}}'
cell_x.box = true
cell_x.colspan = args['colspan_'..w] or args['colspan_ '..w] or args.colspan or '6'
cell_x.rowspan = args['rowspan_'..w] or args['rowspan_ '..w] or args.rowspan or '2'
cell_x.thick = args['border_'..w] or args['border_ '..w] or args.border or '2'
cell_x.css = args['boxstyle_'..w] or args['boxstyle_ '..w] 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