モジュール:Fightstatstop3

モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

Template:Fightstatstop3の内部モジュール。

使用法[編集]

{{#invoke:Fightstatstop3|main}}

local p = {}

-- エラー
function p.error ( message )
	return '<strong class="error">エラー:' ..message ..'</strong>'
end

-- check result
function p.chk_result( array )
	local result = '<td style="text-align: center; font-weight: bold; white-space: nowrap; background: #'
	if array == '勝利' or array == '勝' or array == '勝ち' or array == 'won' or array == '☆' then
		return result ..'cfc;">勝利</td>'
	elseif  array == '敗北' or array == '敗' or array == '負' or array == 'lose' or array == '★' then
		return result ..'fcc;">敗北</td>'
	elseif  array == '引き分け' or array == '引分' or array == '分' or array == 'draw' or array == '△' then
		return result ..'ccf;">引分</td>'
	else
		return '<td>' ..array ..'</td>'
	end
end

-- 本体
function p.main( frame )
	local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:Fightstatstop3', removeBlanks = false })

	-- テーブル外枠 + 目次
	local tbl = '<table class="wikitable" style="font-size: 90%; background: #fff; clear: both;">'
			..'<tr style="background: #ddf; font-weight: bold; text-align: center;">'
	-- [1]日付 / [2]結果 / [3]時間 / [4]内容 / [5]国籍 + [6]対戦相手([7]所属) / [8]開催地 / [9]備考 / [10]出典
	local toc = { '日付', '結果', '時間', '内容', '対戦相手', '開催地', '備考', '出典', }
	for i = 1, 8 do
		tbl = tbl ..'<td>' ..toc[i] ..'</td>'
	end
	tbl = tbl ..'</tr>'

	local array = {}
	local all = 1
	local line = ''
	local temp = ''

	for row, val in pairs( args ) do
		temp = ''
		for cell = 1, 10 do
			array[cell] = args[all] or ''
			all = all + 1
			temp = temp ..array[cell]
		end

		if temp == '' then break end

		if array[7] ~= '' then
			array[7] = '<span style="font-size: 90%;">(' ..array[7] ..')</span>'
		end

		-- colspan check
		if string.lower(array[2]) == 'colspan' then
			line = line .. '<tr><td colspan="8" style="background: #eef; font-weight: bold; font-size: 100%;">' ..array[1] ..'</td></tr>'
		else
			line = line ..'<tr>'
				..'<td style="white-space: nowrap;">' ..array[1] ..'</td>'
				..p.chk_result( array[2] )
				..'<td style="white-space: nowrap;">' ..array[3] ..'</td>'
				..'<td style="white-space: nowrap;">' ..array[4] ..'</td>'
				..'<td style="white-space: nowrap;">' ..array[5] ..array[6] ..array[7] ..'</td>'
				..'<td>' ..array[8] ..'</td>'
				..'<td>' ..array[9] ..'</td>'
				..'<td>' ..array[10] ..'</td>'
				..'</tr>'
		end

		for cell = 1, 10 do
			array[cell] = ''
		end
	end

	return tbl ..line ..'<tr><td colspan="8" style="background: #ddf; font-size: 80%; text-align: right;">[[Template:Fightstatstop3|テンプレート]]</td></tr></table>'
end

return p