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

{{Table2}}の内部モジュール。

使用法

編集
{{#invoke:Table2|main}}

local p = {}

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

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

	local array = {}
	local cellstyle = ''
	local rowstyle = ''
	local temp = ''
	local toc = ''
	local number = tonumber( args.number ) or 0
	local max_col = tonumber( args['列'] ) or tonumber( args.cols )  or 1
	if max_col == '' or max_col == 0 then
		max_col = 1
	end

	local line = ''
	local tocline = ''
	local endflag = ''

	-- toc check
	if number ~= 0 then
		tocline = tocline ..'<th></th>'
	end
	for i = 1, max_col do
		temp = 'th' ..i
		toc = args[temp] or ''
		endflag = endflag ..toc
		tocline = tocline ..'<th>' ..toc ..'</th>'
	end
	if endflag ~= '' then
		line = line ..'<tr>' ..tocline ..'</tr>'
	end

	local cell = 1
	for row, val in pairs ( args ) do
		endflag = ''
		for col = 1, max_col do
			array[col] = args[cell] or ''
			endflag = endflag ..array[col]

			-- cellstyle check
			cellstyle = 'cell' ..row ..'-' ..col
			style = args[cellstyle] or ''
			if style ~= '' then
				array[col] = '<td style="' ..style ..'">' ..array[col] ..'</td>'
			else
				array[col] = '<td>' ..array[col] ..'</td>'
			end
			cell = cell + 1
		end
		if endflag == '' then break end

		-- rowstyle check
		rowstyle = 'row' ..row
		style = args[rowstyle] or ''
		if style ~= '' then
			line = line ..'\n<tr style="' ..style ..'">\n'
		else
			line = line ..'\n<tr>\n'
		end

		-- row number check
		if number > 0 then
			line = line ..'<td style="text-align: right;">' ..tonumber(row + ( number-1)) ..'. </td>'
		end

		-- add line + cell
		for col = 1, max_col do
			line = line ..array[col]
		end
		line = line ..'\n</tr>\n'
	end
	return line
end

return p