Module:ItemSlot: Difference between revisions
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
function p.render(frame) | function p.render(frame) | ||
local args = frame.args | local args = frame:getParent().args | ||
local itemParam = args.item or "" | |||
local | local tooltipParam = args.tooltip | ||
local | |||
local output = {} | local output = {} | ||
-- Split by comma | -- Split items by comma | ||
for filename in string.gmatch( | for filename in string.gmatch(itemParam, '([^,]+)') do | ||
filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces | filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces | ||
| Line 19: | Line 17: | ||
local imgTag | local imgTag | ||
if | if args.link and args.link ~= "" then | ||
imgTag = string.format('[[File:%s|link=%s]]', filename, | imgTag = string.format('[[File:%s|link=%s]]', filename, args.link) | ||
else | else | ||
imgTag = string.format('[[File:%s]]', filename) | imgTag = string.format('[[File:%s]]', filename) | ||
| Line 29: | Line 27: | ||
local result = table.concat(output, "") | local result = table.concat(output, "") | ||
local tooltipText = | local tooltipText = tooltipParam | ||
if | if not tooltipText or tooltipText == "" then | ||
tooltipText = itemParam | |||
end | |||
if tooltipText ~= "" then | |||
result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>' | result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>' | ||
end | end | ||
Revision as of 05:15, 27 November 2025
Documentation for this module may be created at Module:ItemSlot/doc
local p = {}
function p.render(frame)
local args = frame:getParent().args
local itemParam = args.item or ""
local tooltipParam = args.tooltip
local output = {}
-- Split items by comma
for filename in string.gmatch(itemParam, '([^,]+)') do
filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces
if not filename:lower():match("%.png$") then
filename = filename .. ".png"
end
local imgTag
if args.link and args.link ~= "" then
imgTag = string.format('[[File:%s|link=%s]]', filename, args.link)
else
imgTag = string.format('[[File:%s]]', filename)
end
table.insert(output, imgTag)
end
local result = table.concat(output, "")
local tooltipText = tooltipParam
if not tooltipText or tooltipText == "" then
tooltipText = itemParam
end
if tooltipText ~= "" then
result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
end
return '<div class="item-slot">' .. result .. '</div>'
end
return p