Module:Param Parse: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
(Cleaning up module, and adding episode)
Line 5: Line 5:


local param = {}
local param = {}


-- Standardized "name" function
function param.name(arg)
return string.match(arg or '', '%S') and arg or nil
end




Line 16: Line 10:
function param.has_content(arg, default)
function param.has_content(arg, default)
-- 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 default
return string.match(arg or '', '%S') and arg or nil
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
end


Line 43: Line 18:
if img and img:find('%S') then
if img and img:find('%S') then
return img
return img
else
return nil
end
end
return nil
end
end


-- Strip the brackets from the param
function param.image_smw(img)
function param.image_smw(img)
local _img = string.match(img, "File:.-%.png")
return string.match(img, "File:.-%.png")
return _img
end
end


Line 60: Line 30:
num = string.gsub(num or '',',','')
num = string.gsub(num or '',',','')
return tonumber(num)
return tonumber(num)
end


-- Episode
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
function param.episode(episode)
if valid_episodes[episode] then
return '[[File:'..episode..' episode icon.png|18px]]'
end
return nil
end
function param.episode_smw(episode)
if valid_episodes[episode] then
return episode
end
return nil
end
end