(I'm just gonna try this one more time.) Tag: sourceedit |
(Undo revision 322465 by Vogel100 (talk) Nope) Tag: sourceedit |
||
Line 23: | Line 23: | ||
-- writeSeason, writeEpisode, and writeSidenote |
-- writeSeason, writeEpisode, and writeSidenote |
||
-- They are then put together and returned |
-- They are then put together and returned |
||
ā | + | function writeAll( arg ) |
|
local seasoncode = "" |
local seasoncode = "" |
||
local episodecode = "" |
local episodecode = "" |
||
Line 57: | Line 57: | ||
end |
end |
||
ā | + | function writeSeason( season ) |
|
if not seasons[season] and t[season] then |
if not seasons[season] and t[season] then |
||
seasons[season] = true |
seasons[season] = true |
||
Line 66: | Line 66: | ||
end |
end |
||
ā | + | function writeEpisode( episode ) |
|
return '*' .. t[episode] |
return '*' .. t[episode] |
||
end |
end |
||
ā | + | function writeSidenote( sidenote ) |
|
if t[sidenote] then |
if t[sidenote] then |
||
return ' <sup>(' .. t[sidenote] .. ')</sup>' |
return ' <sup>(' .. t[sidenote] .. ')</sup>' |
Revision as of 20:29, 19 July 2015
Documentation for this module may be created at Module:Appear/doc
local p = {}
-- Create a table t to hold the data from Module:Appear/data
local t = mw.loadData( 'Module:Appear/data' )
-- Create a table to see which seasons have been written and which haven't
local seasons = {}
-- Sends the arguments given to the template to the write function
-- and returns everything put together into a string
function p.main( frame )
local text = ""
for i, v in ipairs( frame:getParent().args ) do
if v ~= '' then
if i ~= 1 then
text = text .. '\n'
end
text = text .. writeAll( v )
end
end
return text
end
-- Splits the argument into pieces and sends the right pieces to
-- writeSeason, writeEpisode, and writeSidenote
-- They are then put together and returned
function writeAll( arg )
local seasoncode = ""
local episodecode = ""
local sidenotecode = ""
local first = arg:sub( 1, 1 )
if tonumber( first ) then
seasoncode = first
episodecode = arg:sub( 1, 3 )
sidenotecode = arg:sub( 4 )
elseif first == 'a' then
seasoncode = arg:sub( 4 )
episodecode = arg
elseif first == 'i' then
episodecode = 'intro'
elseif first == 's' then
seasoncode = 'short'
episodecode = arg:sub( 1, 7 )
sidenotecode = arg:sub( 8 )
else
local lowerIndex = arg:find( '%l' )
seasoncode = 'game'
if lowerIndex then
episodecode = arg:sub( 1, lowerIndex - 1 )
sidenotecode = arg:sub( lowerIndex )
else
episodecode = arg
end
end
local season = writeSeason( seasoncode )
local episode = writeEpisode( episodecode )
local sidenote = writeSidenote( sidenotecode )
return season .. episode .. sidenote
end
function writeSeason( season )
if not seasons[season] and t[season] then
seasons[season] = true
return '===' .. t[season] .. '===\n'
else
return ''
end
end
function writeEpisode( episode )
return '*' .. t[episode]
end
function writeSidenote( sidenote )
if t[sidenote] then
return ' <sup>(' .. t[sidenote] .. ')</sup>'
else
return ''
end
end
return p