Module:Collections
Jump to navigation
Jump to search
local p = {}
local lib = require('Module:Feature')
local Icon = require('Module:Icon')._main
local Icon_list = require('Module:Icon list').buildList
local category = mw.html.create()
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
removeBlanks = false,
checkboxes = false,
wrapper = { 'Template:Collections' }
})
return p._main(args)
end
function p._main(args)
local collectionType = args.colType or mw.title.getCurrentTitle().rootText
local _table = mw.html.create('table'):addClass('article-table tdc1 thc1 thc2 thc3 thc4 tdbg1 td100pxwid1 tablemedium')
local options = {
delim = args.delim or ';',
amount_delim = args.amount_delim or '*',
quality_delim = args.quality_delim or '/',
checkboxes = args.checkboxes or false
}
--headers
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Collection'):css{ width = '25%' }
tr:tag('th'):wikitext('Requires')
tr:tag('th'):wikitext('Rewards')
local i = '1'
while args[i .. '_name'] do
local tr = _table:tag('tr'):attr('id', args[i .. '_name'])
if options.checkboxes then
tr:attr("data-checklist", args[i .. '_name'])
end
tr:tag('td'):wikitext('[[File:', args[i .. '_name'], ' Collection.png|80px|link=]]<br />[[' .. collectionType .. '/', args[i .. '_name'],'|', args[i .. '_name'],']]')
options.str = args[i .. '_items']
local requiresColumn = p.createIconList(options, 2, 'Collection requires')
if options.checkboxes then
requiresColumn:addClass("collection-requires")
end
tr:tag('td'):node(requiresColumn)
options.str = args[i .. '_reward']
tr:tag('td'):node(p.createIconList(options, false, 'Collection rewards'))
i = tostring(tonumber(i)+1)
end
_table:node(require('Module:Namespace detect').main{main=category})
return _table
end
function p.createIconList(data, columns, catPrefix)
if not tostring(data.str) then return '' end
local itemDelim = data.delim
local countDelim = data.amount_delim
local checkable = data.checkboxes
local item_list = {}
-- mw.logObject(data) -- debug
for i, entry in ipairs(lib.split(data.str, itemDelim, {noTrim=true})) do
if not lib.isEmpty(entry) then
table.insert(item_list, entry)
if catPrefix then
local item_parts = lib.split(entry, countDelim) -- Get only name (not amount)
local name = item_parts[1]
category:wikitext('[[Category:', catPrefix, ' ', string.lower(name) ,']]')
end
end
end
return Icon_list(item_list, {})
end
return p