Module:ListParser

-- (prevents literal interpretation of links or categories within the module code) -- Lua Templating for, and any other templates requiring items to be listed in a series. local p = {}

local itemTemplate = ' %s '

-- Usage: -- Ex: function p.Linkify(frame) local pages = frame.args[1] return p._linkify(pages) end

function p._linkify(pages) local result = {}

for pagename in mw.text.gsplit(pages, ',') do   pagename = mw.text.trim(pagename) if pagename ~= '' then result[#result+1] = string.format('%s', pagename) end end

return table.concat(result, ', ') end

-- Usage: -- Ex: -- Ex: function p.apply(frame) local wikitext = frame.args[1] local args = frame.args[2] return p._apply(frame, wikitext, args) end

-- Test: =p._apply(mw.getCurrentFrame, '%s', 'test,1,2,3') function p._apply(frame, wikitext, args) local result = {}

for arg in mw.text.gsplit(args, ',') do   arg = mw.text.trim(arg) if arg ~= '' then result[#result+1] = string.format(wikitext, arg) end end

return frame:preprocess( table.concat(result, '') ) end

-- Usage: -- Ex: function p.Adventurers(frame) local names = frame.args[1] return p._Adventurers(names) end

function p._Adventurers(names) local result = {}

for name in mw.text.gsplit(names, ',') do   name = mw.text.trim(name) if name ~= '' then result[#result+1] = string.format(itemTemplate, icon('Adventurer', name), name) end end

return table.concat(result, '') end

-- Usage: -- Ex: function p.Dragons(frame) local names = frame.args[1] return p._Dragons(names) end

function p._Dragons(names) local result = {}

for name in mw.text.gsplit(names, ',') do   name = mw.text.trim(name) if name ~= '' then result[#result+1] = string.format(itemTemplate, icon('Dragon', name), name) end end

return table.concat(result, '') end

-- Usage: -- Ex: function p.Wyrmprints(frame) local names = frame.args[1] return p._Wyrmprints(names) end

function p._Wyrmprints(names) local result = {}

for name in mw.text.gsplit(names, ',') do   name = mw.text.trim(name) if name ~= '' then result[#result+1] = string.format(itemTemplate, icon('Wyrmprint', name), name) end end

return table.concat(result, '') end

-- Usage: -- Ex: function p.Weapons(frame) local names = frame.args[1] return p._Weapons(names) end

function p._Weapons(names) local result = {}

for name in mw.text.gsplit(names, ',') do   name = mw.text.trim(name) if name ~= '' then result[#result+1] = string.format(itemTemplate, icon('Weapon', name), name) end end

return table.concat(result, '') end

-- Common templating functions

-- function icon(type, name) local frame = mw.getCurrentFrame return frame:expandTemplate{title='Icon', args={type, name, text=1}} end

return p --