Module:Explode String: Difference between revisions
From Valheim Wiki
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
if not linkSuffix then | if not linkSuffix then | ||
linkSuffix = '' | linkSuffix = '' | ||
else | |||
linkSuffix = linkSuffix..' ' | |||
end | end | ||
Revision as of 21:50, 18 February 2021
Documentation for this module may be created at Module:Explode String/doc
local currentFrame
local trim = mw.text.trim
---Holds the arguments from the template call.
local args_table
local function toList(input, linkSuffix)
if not linkSuffix then
linkSuffix = ''
else
linkSuffix = linkSuffix..' '
end
-- Turns Fish,Kraken into
-- <ul>
-- <li>[[Fish (Creature) | Fish)]]</li>
-- <li>[[Kraken (Creature) | Kraken)]]</li>
-- </ul>
local ret = '<ul>'
for str in string.gmatch(input, '([^,]+)') do
ret = ret..'<li>[['..str..linkSuffix..'|'..str..']]</li>'
end
ret = ret..'</ul>'
return ret
end
---Return a trimmed version of the value of the template parameter with the specified `key`.
---Return `nil` if the parameter is empty or unset.
---@param key string|number
---@return string|nil
local function getArg(key)
local value = args_table[key]
if not value then
return nil
end
value = trim(value)
if value == '' then
return nil
end
return value
end
local p = {}
p.loop = function(frame)
args_table = frame:getParent().args
local ret = ''
ret = ret..(getArg('linksuffix') or '?')..(getArg('input') or 'Z')..(getArg('string') or '8')
mw.log(ret)
return toList(getArg('input'), getArg('linksuffix'))
end
return p