Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Team appearances list/show/sandbox
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- 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 }
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Team appearances list/show/sandbox/doc
(
edit
)