Module:Team appearances list/show
-- For testing, show results using data from [[Module:Team appearances list/data]].
local Collection = {}
Collection.__index = Collection
do
function Collection:add(item)
if item ~= nil then
self.n = self.n + 1
self[self.n] = item
end
end
function Collection:join(sep)
return table.concat(self, sep)
end
function Collection:sort(comp)
table.sort(self, comp)
end
function Collection.new()
return setmetatable({n = 0}, Collection)
end
end
local function get_page_content(page_title)
local t = mw.title.new(page_title)
if t then
local content = t:getContent()
if content then
if content:sub(-1) ~= '\n' then
content = content .. '\n'
end
return content
end
end
error('Could not read wikitext from "[[' .. page_title .. ']]".', 0)
end
local function make_data(modname)
-- Return a list of tables for each competition/team in the order used in
-- the data module, based on a hope that the data module is consistently
-- indented with one tab before competitions and two or more before teams,
-- and quotes (") are used for strings (not apostrophes).
local content = get_page_content(modname)
local lnum = 0
local current_games
local items = Collection.new()
for line in string.gmatch(content, '(.-)\n') do
lnum = lnum + 1
local indent, title = line:match('^(\t+)%["(.-)"%]')
if indent then
if indent == '\t' then
current_games = title
else
items:add({
competition = current_games,
team = title,
line = lnum,
})
end
end
end
return items
end
local function main(frame)
local title = frame.args[1]
if title == nil or title == '' then
return 'Error: Parameter 1 must specify name of data module'
end
local sandbox = title:find('sandbox', 1, true) and '/sandbox' or ''
local lister = require('Module:Team appearances list' .. sandbox)._main
local lines = Collection.new()
local current_games
for _, item in ipairs(make_data(title)) do
if current_games ~= item.competition then
current_games = item.competition
lines:add('==' .. current_games .. '==')
end
lines:add(item.team .. ' (line ' .. item.line .. ') ' .. lister(item))
end
return lines:join('\n')
end
return { main = main }
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.
- 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:
- 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.
- 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.
- 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.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.