Module:Ep

From Itora Wiki

Documentation for this module may be created at Module:Ep/doc

-- TODO This needs to be able to cope with campaign numbers, the CxEE format should be depricated

local p = {}
 
-- function to retrieve and format the episode name
function p.ep(frame)
    local reference = false
 
    local epSwitcher = require('Module:Ep/Switcher')
    local epName, CxEE = epSwitcher.epSwitcher(frame, reference)
    
    -- if there is no CxEE code, then just return  the episode name without any further formatting
    if not isnotempty(CxEE) then return epName end
 
    -- <small>(CxEE)</small>
    local small = mw.html.create('small')
    small
        :wikitext("(" .. CxEE .. ")")
 
    -- formatting with the various parameters of {{ep}}
    local text = frame.args["text"] or nil
    local nolink = frame.args["nolink"] or nil
    local after = frame.args["after"] or nil
    local bold = frame.args["bold"] or nil
    local plain = frame.args["plain"] or nil
    local hide = frame.args["hide"] or nil
 
    -- variable used when nolink or text are true for episodes with italics in the name
    local italEp
    if string.find(epName, "|") then italEp = split(epName, "|") end
 
    if isnotempty(text) and not isnotempty(nolink) and string.find(epName, "|") then epName = italEp[1] .. "|" .. text
    elseif isnotempty(text) and not isnotempty(nolink) then epName = epName .. "|" .. text
    elseif isnotempty(text) and isnotempty(nolink) then epName = text end
 
 
    if isnotempty(nolink) and string.find(epName, "|") then epName = italEp[2]
    elseif not isnotempty(nolink) then epName = "[[" .. epName .. "]]" end
 
    if isnotempty(after) then epName = epName .. after end
 
    if isnotempty(bold) then epName = "'''" .. epName .. "'''" end
 
 
    if not isnotempty(plain) then epName = "\"" .. epName .. "\"" end
 
    local fullEpName = epName .. " " .. tostring(small)
 
    if isnotempty(hide) then return epName
        else return fullEpName end
 
end
 
-- function to split a string at a specified character
function split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end
 
-- function to determine that a variable has a value
function isnotempty(s)
    return s ~= nil and s~= ''
end
 
return p