Module:Param Parse: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
mNo edit summary
Line 4: Line 4:
-- <nowiki>
-- <nowiki>


local param = {}
local parse = {}




-- Standardized "has content" function
-- Standardized "has content" function
function param.has_content(arg)
function parse.has_content(arg)
-- Return arg if any non-whitespace character is found
-- Return arg if any non-whitespace character is found
return string.match(arg or '', '%S') and arg or nil
return string.match(arg or '', '%S') and arg or nil
Line 15: Line 15:


-- Standardized image function
-- Standardized image function
function param.image(img)
function parse.image(img)
if img and img:find('%S') then
if img and img:find('%S') then
return img
return img
Line 21: Line 21:
return nil
return nil
end
end
function param.image_smw(img)
function parse.image_smw(img)
return string.match(img, "File:.-%.png")
return string.match(img, "File:.-%.png")
end
end
Line 27: Line 27:


-- Standardized numbers
-- Standardized numbers
function param.number(num)
function parse.number(num)
num = string.gsub(num or '',',','')
num = string.gsub(num or '',',','')
return tonumber(num)
return tonumber(num)
Line 35: Line 35:
-- Episode
-- Episode
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
function param.episode(episode)
function parse.episode(episode)
if valid_episodes[episode] then
if valid_episodes[episode] then
return '[[File:'..episode..' episode icon.png|18px]] [['..episode..']]'
return '[[File:'..episode..' episode icon.png|18px]] [['..episode..']]'
Line 41: Line 41:
return nil
return nil
end
end
function param.episode_smw(episode)
function parse.episode_smw(episode)
if valid_episodes[episode] then
if valid_episodes[episode] then
return episode
return episode
Line 48: Line 48:
end
end


return param
return parse


-- </nowiki>
-- </nowiki>