Module:Ep/sandbox

local p = {} -- function to retrieve and format the episode name function p.ep(frame) -- convert the input into the standardized epCode local ep = frame.args[1] local epMatcher = require('Module:Ep/Matcher/sandbox') local epCode = epMatcher.matchCode(ep) -- error message if code doesn't exist if epCode == '0x00' then local errorMsg = "Undefined Episode " local namespace = mw.title.getCurrentTitle.namespace if namespace == 0 then errorMsg = errorMsg + "" else errorMsg = errorMsg + "Category:Ep calls to undefined episodes" end return errorMsg end -- get the title and pagename for that epCode local epInfo = require('Module:Ep/Info/sandbox') local epName = epInfo.title(epCode) local pageName = epInfo.pagename(epCode) -- (epCode) local small = mw.html.create('small') small :wikitext("(" .. epCode .. ")")   -- formatting with the various parameters of     local text = frame.args["text"] or nil local nolink = frame.args["nolink"] or nil local plain = frame.args["plain"] or nil local hide = frame.args["hide"] or nil local noshow = frame.args["noshow"] or nil local epValue if pageName:find("Talks Machina Special") and not isempty(noshow) then epName = split(pageName, ': ')[2] elseif pageName:find("Talks Machina") and not isempty(noshow) then epName = pageName:gsub('Talks Machina ', '#') elseif pageName == epName or not isempty(noshow) then epValue = pageName end if pageName ~= epName and not epValue then epValue = pageName .. '|' .. epName end if not isempty(text) and isempty(nolink) then epValue = pageName .. "|" .. text elseif not isempty(text) and not isempty(nolink) then epValue = text end

if not isempty(nolink) and isempty(text) then epValue = epValue else epValue = "" .. epValue .. "" end

if isempty(plain) then epValue = "\"" .. epValue .. "\"" end local fullEpValue = epValue .. " " .. tostring(small) if not isempty(hide) then return epValue else return fullEpValue end end --function to determine if a string is empty function isempty(s) return s == nil or s == '' 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 return p