Module:Infobox item: Difference between revisions

From Sekaipedia
Content added Content deleted
m (ChaoticShadow moved page Module:Infobox Item to Module:Infobox item without leaving a redirect)
mNo edit summary
Line 1: Line 1:
--------------------------
--------------------------
-- Module for [[Template:Infobox Material]]
-- Module for [[Template:Infobox item]]
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local builder = require('Module:InfoboxBuilder')


Line 12: Line 13:


function p.main(frame)
function p.main(frame)
local args = frame:getParent().args
local args = getArgs(frame)
local infobox = builder.new();
local infobox = builder.new();
infobox:setName('Infobox Item')
infobox:setName('Infobox item')
:setWidth("330px")
:setWidth("330px")
:setParams{
:setParams{

Revision as of 21:59, 18 November 2021

To generate {{Infobox item}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox item]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local builder   = require('Module:InfoboxBuilder')

local p = {}
local categories = ""

local function formatImage(image_name)
	return string.format("[[File:%s|128px]]", image_name)
end

function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new();
	
	infobox:setName('Infobox item')
		:setWidth("330px")
		:setParams{
			{ name = 'item name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'description' },
			{ name = 'date' }
		}
		:setArgs(args)

	infobox
		:addHeader({ tag = 'argth', content = 'item name' })
		:addImage(
			{
				{ tag = 'argtd', content = 'image' },
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'English', colspan = 12 },
				{ tag = 'argtd', content = 'english', colspan = 18 }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader({ tag = 'th', content = 'Item Description' }, { subheader = true })
		:addRow(
			{
				{ tag = 'argtd', content = 'description', colspan = 30,
					css = { ['text-align'] = 'center' }
				}
			}
		)
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Items]]" .. categories
	end

	return infobox:tostring() .. categories
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.