モジュール:Infobox/sandbox

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

ここに呼び出す説明文 『 モジュール:Infobox/sandbox/doc 』 が作成されていません。

local p = {}

function row(header, label, data, headerstyle, labelstyle, datastyle)
	if header ~= '' then
		return '<tr><th colspan="2" style="'..headerstyle..'">'..header..'</th></tr>'
		
	elseif data ~= '' then
		if label ~= '' then
			labelstyle = 'text-align:left; width:max-content; max-width:7em;'..labelstyle
			datastyle = 'word-break:break-word;'..datastyle
			return '<tr><th style="'..labelstyle..'">'..label..'</th><td style="'..datastyle..'">'..data..'</td></tr>'
		else
			datastyle = 'text-align:center;'..datastyle
			return '<tr><td colspan="2" style="'..datastyle..'">'..data..'</td></tr>'
		end
		
	else
		return ''
	end
end


function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Infobox'})
	local line = ''
	
	local bodystyle = args['bodystyle'] or ''
	local title = args['title'] or ''
	local titlestyle = args['titlestyle'] or ''
	if args['child'] == 'yes' then
		line = line..'<b>'..title..'</b></td></tr>'
	else
		bodystyle = 'width:300px; border:1px solid #aaa; background:#fff; float:right; clear:right; margin:0 0 1em 1em; font-size:small;'..bodystyle
		titlestyle = 'font-size:125%; font-weight:bold;'..titlestyle
		line = line..'<table style="'..bodystyle..'"><caption style="'..titlestyle..'">'..title..'</caption>'
	end
	
	local header = args['above'] or ''
	local headerstyle = args['abovestyle'] or ''
	headerstyle = 'font-size:125%;'..headerstyle
	line = line..row(header, '', '', headerstyle, '', '')
	
	local data = args['subheader'] or args['subheader1'] or ''
	local datastyle = args['subheaderstyle'] or args['subheaderstyle1'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local data = args['subheader2'] or ''
	local datastyle = args['subheaderstyle'] or args['subheaderstyle2'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local data = args['image'] or args['image1'] or ''
	local datastyle = args['imagestyle'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local data = args['caption'] or args['caption1'] or ''
	local datastyle = args['captionstyle'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local data = args['image2'] or ''
	local datastyle = args['imagestyle'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local data = args['caption2'] or ''
	local datastyle = args['captionstyle'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local headerstyle = args['headerstyle'] or ''
	local labelstyle = args['labelstyle'] or ''
	local datastyle = args['datastyle'] or ''
	for i = 1, 100 do
		local header = args['header'..i] or ''
		local label = args['label'..i] or ''
		local data = args['data'..i] or ''
		
		line = line..row(header, label, data, headerstyle, labelstyle, datastyle)
	end
	
	local data = args['below'] or ''
	local datastyle = args['belowstyle'] or ''
	line = line..row('', '', data, '', '', datastyle)
	
	local name = args['name'] or args['tnavbar'] or ''
	if name ~= '' then
		local data = frame:preprocess('{{Tnavbar|'..name..'|plain=1}}')
		local datastyle = 'text-align:right;'
		line = line..row('', '', data, '', '', datastyle)
	end
	
	if args['child'] == 'yes' then
		line = line..'<tr><td colspan="2">'
	else
		line = line..'</table>'
	end
	
	return line
end

return p