Module:Param Parse: Difference between revisions

Cleaning up module, and adding episode
No edit summary
(Cleaning up module, and adding episode)
Line 5:
 
local param = {}
 
 
-- Standardized "name" function
function param.name(arg)
return string.match(arg or '', '%S') and arg or nil
end
 
 
Line 16 ⟶ 10:
function param.has_content(arg, default)
-- Return arg if any non-whitespace character is found
return string.match(arg or '', '%S') and arg or defaultnil
end
 
 
-- Create a standardized release function, since so many pages use it
-- Turns release and update into a single parameter
function param.release_update(release, update)
if not Infobox.isDefined(release) then
return nil
end
if string.lower(release) == 'no' then
return 'N/A'
end
if not Infobox.isDefined(update) then
return string.format('%s (Update unknown)',release)
end
if string.lower(update) == 'no' then
return release
end
return string.format('%s ([[Update:%s|Update]])', release, update)
end
 
Line 43 ⟶ 18:
if img and img:find('%S') then
return img
else
return nil
end
return nil
end
 
 
-- Strip the brackets from the param
function param.image_smw(img)
local _img =return string.match(img, "File:.-%.png")
return _img
end
 
Line 60 ⟶ 30:
num = string.gsub(num or '',',','')
return tonumber(num)
end
 
 
-- Episode
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
function param.nameepisode(argepisode)
if valid_episodes[episode] then
return '[[File:'..episode..' episode icon.png|18px]]'
end
return releasenil
end
function param.episode_smw(episode)
if valid_episodes[episode] then
return 'N/A'episode
end
return nil
end