This documentation is transcluded from Module:Item/doc. Changes can be proposed in the talk page.
require('strict')
local Item = {}
local function sentenceCase(str)
return (str:gsub("^%l", string.upper))
end
-- @param categories table Plain text categories in array
local function convertCategories(categories)
local mapped = {}
for _, category in pairs(categories) do
if category ~= nil then
if string.sub(category, 1, 2) ~= '[[' then
category = string.format('[[Category:%s]]', category)
end
table.insert(mapped, category)
end
end
return table.concat(mapped)
end
-- @param frame table https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Frame_object
function Item.main(frame)
local args = require( 'Module:Arguments' ).getArgs( frame )
local infobox = require('Module:InfoboxNew'):new()
local categories = {}
local modules = {
weapon = 'Module:Item/Weapon',
-- backpack = 'Module:Item/Backpack',
-- core = 'Module:Item/Core',
-- implant = 'Module:Item/Implant',
-- attachment = 'Module:Item/Attachment',
-- valuable = 'Module:Item/Valuable',
-- salvage = 'Module:Item/Salvage',
}
infobox:renderImage(args['image'])
infobox:renderHeader({
title = args['name'],
subtitle = args['subtype'] or args['type']
})
if args['type'] then
local type = string.lower(args['type'])
if modules[type] then
categories = require(modules[type])._main(infobox, args)
end
end
if args['width'] and args['height'] then
infobox:renderSection({
title = "Dimensions",
content = require('Module:Dimensions')._main(nil, tonumber(args['width']), tonumber(args['height'])),
col = 1
})
end
return tostring(infobox:renderInfobox(nil, args['name'])) .. convertCategories(categories)
end
return Item