www.fgks.org   »   [go: up one dir, main page]

Jump to content

Module:TreeChart

विकिपीडिया से
imported>The Mol Man के द्वारा 18:51, 15 दिसंबर 2014 के बदलाव
मॉड्यूल बिबरनलेख[बनाईं]
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