Module:InfoboxItem
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxItem/doc
local p = {}
function p.renderInfobox(frame)
local args = frame.args
local parent = frame:getParent()
if parent then
args = parent.args
end
local html = [[
<table class="infobox no-parenthesis-style infobox-item">
<tr>
<th colspan="20" class="infobox-header">]] .. (args.itemName or "") .. [[</th>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
-- Image section
if args.image and args.image ~= "" then
html = html .. [[
<tr>
<td colspan="20" class="infobox-image inventory-image infobox-full-width-content">]] .. "[[File:" .. args.image .. "|center|32px]]" .. [[</td>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
end
-- Also Called section
if args.alsoCalled and args.alsoCalled ~= "" then
html = html .. [[
<tr>
<th colspan="7">Also called</th>
<td colspan="13">]] .. args.alsoCalled .. [[</td>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
end
-- Requirements section - only show if at least one requirement exists
local hasRequirements = false
local reqFields = {"strength", "attack", "prayer", "defence", "magic", "ranged"}
for _, field in ipairs(reqFields) do
if args[field] and args[field] ~= "" then
hasRequirements = true
break
end
end
if hasRequirements then
html = html .. [[
<tr>
<th colspan="20" class="infobox-subheader">Requirements</th>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
-- Add each requirement that has a value
for _, field in ipairs(reqFields) do
if args[field] and args[field] ~= "" then
html = html .. [[
<tr>
<th colspan="7">]] .. field:gsub("^%l", string.upper) .. [[</th>
<td colspan="13">]] .. args[field] .. [[</td>
</tr>]]
end
end
html = html .. [[
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
end
-- Properties section - only show if at least one property exists
local hasProperties = false
local propFields = {"tradeable", "tier", "equipable", "stackable", "noteable", "examineText"}
for _, field in ipairs(propFields) do
if args[field] and args[field] ~= "" then
hasProperties = true
break
end
end
if hasProperties then
html = html .. [[
<tr>
<th colspan="20" class="infobox-subheader">Properties</th>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
-- Add each property that has a value
for _, field in ipairs(propFields) do
if args[field] and args[field] ~= "" then
local displayName = field
if field == "examineText" then
displayName = "Examine text"
else
displayName = field:gsub("^%l", string.upper)
end
html = html .. [[
<tr>
<th colspan="7">]] .. displayName .. [[</th>
<td colspan="13">]] .. args[field] .. [[</td>
</tr>]]
end
end
-- Add extra padding after examine text if it exists
if args.examineText and args.examineText ~= "" then
html = html .. [[
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
end
end
-- Values section - only show if at least one value exists
local hasValues = false
local valueFields = {"value", "highAlch", "lowAlch", "weight"}
for _, field in ipairs(valueFields) do
if args[field] and args[field] ~= "" then
hasValues = true
break
end
end
if hasValues then
html = html .. [[
<tr>
<th colspan="20" class="infobox-subheader">Values</th>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>]]
-- Add each value that has a value
for _, field in ipairs(valueFields) do
if args[field] and args[field] ~= "" then
local displayName = field
if field == "highAlch" then
displayName = "High alch"
elseif field == "lowAlch" then
displayName = "Low alch"
else
displayName = field:gsub("^%l", string.upper)
end
html = html .. [[
<tr>
<th colspan="7">]] .. displayName .. [[</th>
<td colspan="13">]] .. args[field] .. [[</td>
</tr>]]
end
end
end
-- Final padding and closing
html = html .. [[
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>
<tr>
<td colspan="20" class="infobox-padding"></td>
</tr>
<tr>
<td colspan="20" class="infobox-full-width-content">
</div>
</td>
</tr>
</table>]]
return html
end
return p