Module:VgData/sandbox

require('strict')

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

--	pull arguments from Invoke and process them appropriately
function p.main(frame)
	local args = getArgs(frame)
	args.ct = tostring(frame.args["ct"])
	args.all = not(not(frame.args["all"]))
	args.col = frame.args["col"] or 3
	args.ver = tostring(frame.args["ver"]) or "none"
	
	local page
	local caption
	if args.ct == "platform" then
		page = "VgPlatforms"
		caption = "Video game platforms"
	elseif args.ct == "genre" then
		page = "VgGenres"
		caption = "Video game genres"
	elseif args.ct == "release" then
		page = "VgRelease"
		caption = "Types of releases"
		args.col = 1
	else
		return "Table type not found"
	end

	local max = 0
	for i, j in ipairs(args) do
		max = max + 1
	end
	return p.import(args, page, caption, max)
end

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

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

		local 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 args.all == true then
			table.insert(args, cells[1])
			max = max + 1
		end
		input[cells[1]] = cells[2]
	end
	return p.out(args, caption, max, input)
end

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