Module:VgData

local getArgs = require('Module:Arguments').getArgs
local p = {}

--	pull arguments from Invoke and process them appropriately
function p.main(frame)
	args = getArgs(frame)
	ct = tostring(frame.args["ct"])
	all = not(not(frame.args["all"]))
	col = frame.args["col"] or 3
	ver = tostring(frame.args["ver"]) or "none"
	
	if ct == "platform" then
		page = "VgPlatforms"
		caption = "Video game platforms"
	elseif ct == "genre" then
		page = "VgGenres"
		caption = "Video game genres"
	else
		return "Table type not found"
	end
	max = 0
	for i, j in ipairs(args) do
		max = max + 1
	end
	return p.import()
end

--	get the specific table block, and iterate each row (lines starting with |)
function p.import()
	content = mw.title.makeTitle( 'Template', page ):getContent()
	if ct == "genre" then
		if ver == nil or ver == "none" then
			twiki = content:match("<%!%-%- "..ct.."%-%->(.-)<%!%-%- /"..ct.."%-%->")	
		else
			twiki = content:match("<%!%-%- "..ver.."%-%->(.-)<%!%-%- /"..ver.."%-%->")	
		end
	else
		twiki = content:match("<%!%-%- "..ct.."%-%->(.-)<%!%-%- /"..ct.."%-%->")
	end

	if all == true then
		args = {}
	end
	input = {}
	for row in twiki:gmatch("%|(.-)\n") do
		cells = {}

		temp = row:gsub("|","\t",1)		--	split on cell separators (converts first "|" to \t and splits on that)
		for cell in temp:gmatch("[^\t]+") do
			table.insert(cells, mw.text.trim(cell))
		end
		if all == true then
			table.insert(args, cells[1])
			max = max + 1
		end
		input[cells[1]] = cells[2]
	end
	return p.out(input)
end

--	filter input data based on args and create a new table
function p.out(input)
	output = "<table class=\"wikitable\" style=\"width:100%;background:#ffffff;font-size:85%\"><caption>"..caption.."</caption>"
	coloutput = ""
	key = 1
	while key <= max do
		coloutput = "<tr>"
		for l=1,col do
			if key <= max then
				if input[args[key]] == nil then
					coloutput = coloutput.."<td style=background:#EAECF0><b>"..args[key].."</b></td><td>".."Term not found".."</td>"	
				else
					coloutput = coloutput.."<td style=background:#EAECF0><b>"..args[key].."</b></td><td>"..input[args[key]].."</td>"
				end
			else
				coloutput = coloutput.."<td style=background:#EAECF0></td><td></td>"
			end
			key = key + 1
		end
		output = output..coloutput.."</tr>"
	end
	output = output.."</table>"
	return output
end


return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.