Module:ItemInfoGenerator

local generator = {}

local ItemDatabase = require("Module:ItemDatabase")

local function getDisplayName(internalName) return ItemDatabase.DISPLAY_NAMES[internalName] or internalName end

local function makeHeader(text) return ..text.. end

local function makeLabelWithValue(label, value, doMargin) return  ..label.. ..value.. end

local function makeRarityContainer(rarityLabel, color, innerHTML) return    ..rarityLabel..     ..innerHTML.. end

function generator.makeLargeItemInfobox(frame) local itemName = frame.args.itemName or frame:getParent:getTitle local itemData = ItemDatabase.ITEM_DATA[itemName]

if not itemData then return error('No data found in Module:ItemDatabase for item "'..itemName..'"') end

local htmlText = {<div style="   width: 23em;    border: 3px solid } htmlText[2] = makeHeader(itemName) htmlText[3] = "" --create labels for Mastery Level, Legendary Name, etc.   for _, stat in ipairs(ItemDatabase.STAT_ORDER) do        if itemData[stat] then htmlText[#htmlText + 1] = makeLabelWithValue(getDisplayName(stat), itemData[stat], true) end end

htmlText[#htmlText + 1] = makeSmallHeader("Stats")

--create labels for stats for _, rarity in ipairs(ItemDatabase.RARITY_ORDER) do       local innerHTML = {}

local rarityData = itemData.STATS[rarity] if rarityData then for _, PrimaryOrSecondary in ipairs{"Primary", "Secondary"} do               local data = rarityData[PrimaryOrSecondary]

if data then innerHTML[#innerHTML + 1] = makeSmallHeader(PrimaryOrSecondary)

local passedFirstLabel = false for statName, statValue in pairs(data) do                       innerHTML[#innerHTML + 1] = makeLabelWithValue(getDisplayName(statName), statValue, passedFirstLabel) passedFirstLabel = true end end end htmlText[#htmlText + 1] = makeRarityContainer(rarity, ItemDatabase.RARITY_COLORS[rarity], table.concat(innerHTML)) end end

htmlText[#htmlText + 1] = " " return table.concat(htmlText) end

function generator.getDescription(frame) local itemName = frame.args.itemName or frame:getParent:getTitle local itemData = ItemDatabase.ITEM_DATA[itemName] if not itemData then return error('No item data found for item "'..itemName..'"') end return itemData.description end

return generator