BryghtShadow (talk | contribs) (getArgs (by SublimeText.Mediawiker)) |
BryghtShadow (talk | contribs) mNo edit summary |
||
Line 5: | Line 5: | ||
function p.icon(frame) |
function p.icon(frame) |
||
− | + | local args = require('Module:Arguments').getArgs(frame, { |
|
− | + | parentFirst = true, |
|
− | + | wrappers = { |
|
− | + | 'Template:Memento/Icon', |
|
− | + | }, |
|
− | + | }) |
|
− | + | return p._icon(args) |
|
end |
end |
||
function p._icon(args) |
function p._icon(args) |
||
− | + | local iname = args[1] |
|
+ | if iname == nil then return nil end |
||
⚫ | |||
+ | local page = require('Module:CargoUtil').query{ |
||
⚫ | |||
+ | tables = 'Pages', |
||
⚫ | |||
+ | fields = 'iname', |
||
⚫ | |||
+ | where = { |
||
⚫ | |||
+ | 'type = "Memento"', |
||
⚫ | |||
+ | '_pageName = "'..iname..'" OR iname = "'..iname..'"', |
||
⚫ | |||
+ | }, |
||
− | 4, |
||
+ | limit = 1, |
||
⚫ | |||
+ | }[1] |
||
⚫ | |||
+ | if page then iname = page.iname end |
||
− | args['classes'], |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | } |
||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
+ | 4, |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | + | args['classes'], |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | } |
||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
+ | |||
⚫ | |||
+ | if args['size'] == 'small' then |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
end |
end |
||
Revision as of 17:01, 4 March 2020
Documentation for this module may be created at Module:Render/Memento/doc
local render_icon = require('Module:Render').icon
local model = require('Module:Data').model
local p = {}
function p.icon(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrappers = {
'Template:Memento/Icon',
},
})
return p._icon(args)
end
function p._icon(args)
local iname = args[1]
if iname == nil then return nil end
local page = require('Module:CargoUtil').query{
tables = 'Pages',
fields = 'iname',
where = {
'type = "Memento"',
'_pageName = "'..iname..'" OR iname = "'..iname..'"',
},
limit = 1,
}[1]
if page then iname = page.iname end
local data = args.data or model.query('ConceptCard','_pageName,server,rare,icon',{where='iname="'..iname..'"'})[1] or {rare=0}
-- TODO Get the correct server
local renderArgs = {
(data.icon == nil or data.icon == '') and 'ItemIcon,IT_UNKNOWN' or ('ConceptCardIcon,'..data.icon),
model.getLoc(data._pageName, 'name'),
data._pageName ~= nil and (args['link'] ~= 'none' and (mw.ext.cargo.query('Pages','_pageName',{where='type="Memento" and iname="'..iname..'"'})[1] or {_pageName = model.getLoc(data._pageName, 'name')})._pageName) or nil,
data.rare,
4,
64,
args['count'] ~= '' and args['count'] or nil,
args['classes'],
nil,
false,
}
local name = args['name'] ~= 'none' and (renderArgs[3] and renderArgs[3] ~= '' and ('[['..renderArgs[3]..'|'..renderArgs[2]..']]') or renderArgs[2]) or nil
if args['size'] == 'large' then
renderArgs[6] = 128
end
if args['size'] == 'small' then
renderArgs[6] = 24
renderArgs[9] = name and '<span>'..name..'</span>'
renderArgs[10] = true
elseif args['size'] == 'compact' then
renderArgs[9] = name and '<div class="item-count" style="font-size: 0.7em;overflow: hidden;right: 0">'..renderArgs[2]..'</div>'
else
renderArgs[9] = name and '<div style="width: '..renderArgs[6]..'px">'..name..'</div>'
end
return render_icon(unpack(renderArgs))
end
return p