Documentation for this module may be created at Module:Card Grid/doc
local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local p = {}
local function cargoQuery(param_args)
local tables = 'Cards'
local fields = [[
_pageName,
rarity,
thumbnail,
thumbnail_trained,
card_name,
card_character
]]
local args = {
where = param_args.where,
orderBy = param_args.orderBy or 'Cards.card_id DESC',
groupBy = 'Cards._pageID'
}
return cargo.query( tables, fields, args )
end
function p.main(frame)
local args = getArgs(frame)
return p._main({
where = args['where'],
orderBy = args['orderBy']
})
end
function p._main(query_args, options)
local results = cargoQuery(query_args)
local show_name = false
local show_label = false
if options then
show_name = options.show_name or show_name
show_label = options.show_label or show_label
end
local root = mw.html.create('div')
:addClass('card-grid')
if #results > 0 then
for k,v in ipairs(results) do
local file = '[[File:' .. v.thumbnail .. '|center|130px]]'
if v.rarity and
v.rarity ~= '' and
(tonumber(v.rarity) == 3 or tonumber(v.rarity) == 4) then
file = file .. '[[File:' .. v.thumbnail_trained .. '|center|130px]]'
end
local box = root:tag('div')
:addClass('card-grid-item')
box:tag('div')
:css({
['display'] = 'flex',
})
:wikitext(file)
:done()
box:tag('div')
:wikitext(string.format('<b>[[%s|%s]]</b>', v._pageName, v.card_name))
:done()
if show_name then
box:tag('div')
:wikitext(string.format('[[%s]]', v.card_character))
:done()
end
end
end
local frame = mw.getCurrentFrame()
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Template:Card grid/styles.css' }
} .. tostring(root)
end
return p