Module:List
From Another Eden Wiki
Documentation for this module may be created at Module:List/doc
local Util = require 'Module:Util'
local p = {}
--explode-like split function taken from LUA documentation
function split(d,p)
local t, ll
t={}
ll=0
if(#p == 1) then
return {p}
end
while true do
l = string.find(p, d, ll, true) -- find the next d in the string
if l ~= nil then -- if "not not" found then..
table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array.
ll = l + 1 -- save just after where we found it for searching next time.
else
table.insert(t, string.sub(p,ll)) -- Save what's left in our array.
break -- Break at end, as it should be, according to the lua manual.
end
end
return t
end
function all_trim(s)
return s:match( "^%s*(.-)%s*$" )
end
p._personalityList = function (args)
local output = mw.html.create('div')
-- Split the cell values
for i,arg in ipairs(args) do
local personalityValues = split(",", arg)
-- Loop through all personality values
for idx, personalityValue in ipairs(personalityValues) do
local div = output:tag('div')
:css('display', 'inline-block')
:css('white-space', 'nowrap')
:css('padding', '3px')
:css('border', '1px solid gray')
:css('margin', '2px')
:css('background', '#eee')
:wikitext(personalityValue)
end
end
return tostring(output)
end
p._materialList = function (args, frame)
local output = mw.html.create('div')
-- Split the cell values
for i,arg in ipairs(args) do
local materialNames = split(",", arg)
-- Loop through all materials
for idx, materialName in ipairs(materialNames) do
if materialName ~= "None" and materialName ~= nil then
local material = Util.getMaterial(materialName)
local link = '[[' .. materialName .. ']]'
if material ~= nil and material.Type == "Grasta" then
link = '[[' .. material.page .. '|' .. material.Name .. ']]'
end
local div = output:tag('div')
:css('white-space', 'nowrap')
:wikitext(frame:expandTemplate{ title = "Material icon", args={all_trim(materialName)}} .. link)
else
local div = output:tag('div')
:wikitext(frame:expandTemplate{ title = "*", args={}} .. " None")
end
end
end
return tostring(output)
end
p._attributeList = function (args, frame)
local output = mw.html.create('div')
output:css('white-space', 'nowrap')
-- Split the cell values
for i,arg in ipairs(args) do
local attributes = split(",", arg)
-- Loop through all attribute values
for idx, attribute in ipairs(attributes) do
local div = output:tag('div')
:css('display', 'inline-block')
:wikitext(frame:expandTemplate{ title = "Skill type icon", args={all_trim(attribute), all_trim(attribute), size="44px"}})
end
end
return tostring(output)
end
p._categoryList = function (args, frame)
local output = mw.html.create('div')
-- Split the cell values
for i,arg in ipairs(args) do
local categoryValues = split(",", arg)
-- Loop through all category values
for idx, categoryValue in ipairs(categoryValues) do
local type = ' '
if frame.args.type ~= nil then
type = frame.args.type
end
local div = output:tag('div')
:css('display', 'inline-block')
:css('white-space', 'nowrap')
:css('padding', '3px')
:css('border', '1px solid gray')
:css('margin', '2px')
:css('background', '#eee')
--:css('cursor', 'pointer')
:wikitext(frame:expandTemplate{ title = "Category with link", args={link=all_trim(categoryValue .. ' ' .. type), name=categoryValue, type=frame.args.type, addCategory=frame.args.addCategory}})
end
end
return tostring(output)
end
p.personalityList = function (frame)
local getArgs = require 'Module:Arguments'.getArgs
return p._personalityList(getArgs(frame, {wrappers = 'Template:Personality list'}))
end
p.attributeList = function (frame)
local getArgs = require 'Module:Arguments'.getArgs
return p._attributeList(getArgs(frame, {wrappers = 'Template:Attribute list'}), frame)
end
p.materialList = function (frame)
local getArgs = require 'Module:Arguments'.getArgs
return p._materialList(getArgs(frame, {wrappers = 'Template:Material list'}), frame)
end
p.categoryList = function (frame)
local getArgs = require 'Module:Arguments'.getArgs
return p._categoryList(getArgs(frame, {wrappers = 'Template:Category list'}), frame)
end
return p