Jump to content

Module:ko-attest/data/table

From Wiktionary, the free dictionary


local export = {}

local works_data = mw.loadData("Module:ko-attest/data").works
local ko = require("Module:languages").getByCode("ko")
local tag_text = require("Module:script utilities").tag_text
local concat = table.concat

function export.make()
	local rows = {}
	for k, v in pairs(works_data) do
		if type(v) == "table" then
			local row = {}
			rows[#rows + 1] = row
			
			row[1] = v.year
			row[2] = tag_text(k, ko)			
			row[3] = {}
			if v.aliases then
				for _, alias in ipairs(v.aliases) do
					row[3][#row[3] + 1] = alias
				end
			end
			row[3] = tag_text(concat(row[3], ", "), ko)
			row[4] = v.url and "Yes" or "No"
			row[5] = (v.url and v.url.page) and "Yes" or "No"
		end
	end
	
	table.sort(rows, function (a, b) return a[1] < b[1] end)
	
	for i = 1,#rows do
		rows[i] = concat(rows[i], " || ")
	end
	rows = concat(rows, "\n|-\n| ")
	
	return "{| class=\"wikitable sortable mw-collapsible mw-collapsed\"\n"
		.. "! colspan=5 | List of work presets\n"
		.. "|-\n"
		.. "! Year !! Work !! Aliases !! URL !! Images\n"
		.. "|-\n"
		.. "|" .. rows .. "\n"
		.. "|-\n"
		.. "! colspan=5 | Generated from [[Module:ko-attest/data]] via [[Module:ko-attest/data/table]]\n"
		.. "|}"
end

return export