Module:Infobox Item

-- -- Module for Template:Infobox Item

local p = {}

local onmain = require('Module:Mainonly').on_main local yesno = require('Module:Yesno') local paramtest = require('Module:Paramtest') local infobox = require('Module:Infobox') local cleanimg = require('Module:Clean image').clean local commas = require('Module:Addcommas')._add

-- Main function called with invokes function p.main(frame) local args = frame:getParent.args local ret = infobox.new(args)

ret:defineParams{ { name = 'vanchor', func = { name = 'has_content', params = { 'version' }, flag = 'p' } }, { name = 'image', func = { name = imgarg, params = { 'image' }, flag = { 'd' } } }, { name = 'name', func = 'name' }, { name = 'description', func = 'has_content' }, { name = 'lore', func = { name = yesnoparam, params = { 'lore' } } }, { name = 'section', func = 'has_content' }, { name = 'value', func = 'has_content' }, { name = 'cost', func = 'has_content' }, { name = 'id', func = { name = iddisp, params = { 'id' }, flag = 'p' } }, }

ret:setMaxButtons(6) ret:create ret:cleanParams ret:customButtonPlacement(true)

ret:defineLinks({ links = {{ 'Template:%s/doc', 'Infobox' },		{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })

ret:defineName('Infobox Item') ret:addButtonsCaption

-- PARAMETER: image ret:addRow{ { tag = 'argd', content = 'image', class='infobox-image', colspan = '2' } }	-- PARAMETER: name ret:addRow{ { tag = 'argh', content = 'name', class='infobox-header', colspan = '2' } }	-- PARAMETER: section ret:addRow{ { tag = 'th', content = 'Section' }, { tag = 'argd', content = 'section' } }	-- PARAMETER: lore ret:addRow{ { tag = 'th', content = 'Lore' }, { tag = 'argd', content = 'lore' } }	-- PARAMETER: value ret:addRow{ { tag = 'th', content = 'Value' }, { tag = 'argd', content = 'value' } }	-- PARAMETER: cost ret:addRow{ { tag = 'th', content = 'Cost' }, { tag = 'argd', content = 'cost' } }	-- PARAMETER: description :addRow{ { tag = 'th', content = 'Description', class = 'infobox-subheader', colspan = '2' } }

{ tag = 'argd', content = 'description', colspan = '2', css = { ['max-width'] = '300px', ['text-align'] = 'center' } } }	ret:addRow{ { tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '2' }, meta = {addClass = 'advanced-data'} }

-- PARAMETER: id	:addRow{ { tag = 'th', content = 'ID' }, { tag = 'argd', content = 'id' }, meta = {addClass = 'advanced-data'} }	ret:finish if onmain then local a1 = ret:param('all') local a2 = ret:categoryData ret:wikitext(addcategories(a1, a2)) end return ret:tostring end

function imgarg(arg) if infobox.isDefined(arg) then return cleanimg{ file = arg, width = 300, height = 300 } end return nil end

function yesnoparam(p) if infobox.isDefined(p) then local b = yesno(p) if b then return 'Yes' elseif not b then return 'No' else return nil end end return nil end

function iddisp(id) if infobox.isDefined(id) then if id:lower ~= 'no' then local r = string.gsub(id, ', *', ', ') return r		elseif id:lower == 'no' then return 'None' end end return nil end

function addcategories(args, catargs) local ret = { 'Items' } local cat_map = { -- Added if the parameter has content defined = { },		-- Added if the parameter has no content notdefined = { image = 'Needs image', },	}	-- Run and add mapped categories for n, v in pairs(cat_map.defined) do		if catargs[n] and catargs[n].one_defined then table.insert(ret,v) end end for n, v in pairs(cat_map.notdefined) do		if catargs[n] and catargs[n].all_defined == false then table.insert(ret,v) end end -- value if not catargs.value.all_defined then table.insert(ret,'Needs value') end -- cost if not catargs.cost.all_defined then table.insert(ret,'Needs cost') end -- description if not catargs.description.all_defined then table.insert(ret,'Needs description') end -- ids if not catargs.id.all_defined then table.insert(ret,'Needs ID') end

-- combine table and format category wikicode for i, v in ipairs(ret) do		if (v ~= '') then ret[i] = string.format('', v)		end end

return table.concat(ret, '') end

return p