Module:Infobox item: Difference between revisions

From Sekaipedia
Content added Content deleted
(created infobox item module)
 
No edit summary
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
--------------------------
--------------------------
-- Module for [[Template:Infobox Material]]
-- Module for [[Template:Infobox item]]
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')

local p = {}
local p = {}
local categories = ""

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


function p.main(frame)
function p.main(frame)
local args = frame:getParent().args
local args = getArgs(frame)
local infobox = builder.new();
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox Item')
infobox:setName('Infobox item')
:setWidth("330px")
:setParams{
:setParams{
{ name = 'item name', default = mw.title.getCurrentTitle().text },
{ name = 'item name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
Line 25: Line 23:
}
}
:setArgs(args)
:setArgs(args)
:processArgs()
:setHeaderColors({
['background-color'] = '00cdba',
['color'] = '#fff'
})


infobox
infobox
:addHeader({ tag = 'argth', content = 'item name' })
:addHeader({ tag = 'argth', content = 'item name' })
:addImage(
:addImage({
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('128px') },
{
})
{ tag = 'argtd', content = 'image' },
:addRow({
}
{ tag = 'th', content = 'Japanese' },
)
{ tag = 'argtd', content = 'japanese' }
})
:addRow({
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
})
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'argtd', content = 'english' }
}
},
{ hideIfEmpty = { 'english' } }
)
: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 }
}
)
:addHeader(
{ tag = 'th', content = 'Unit' },
{ hideIfEmpty = { 'unit' } }
)
:addHeader({ tag = 'th', content = 'Item Information' })
:addRow(
{
{ tag = 'th', content = 'Description', colspan = 12 },
{ tag = 'argtd', content = 'description', colspan = 18 }
}
)
)
:addHeader({ tag = 'th', content = 'Item Description' }, { subheader = true })
:addRow({
{ tag = 'argtd', content = 'description', css = { ['text-align'] = 'center' } }
})
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Items]]" .. categories
categories = "[[Category:Items]]" .. categories

Latest revision as of 15:20, 19 October 2022

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


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

local p = {}

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

	infobox
		:addHeader({ tag = 'argth', content = 'item name' })
		:addImage({
			{ tag = 'argtd', content = 'image', fn = DisplayFns.image('128px') },
		})
		:addRow({
			{ tag = 'th', content = 'Japanese' },
			{ tag = 'argtd', content = 'japanese' }
		})
		:addRow({
			{ tag = 'th', content = 'Romaji' },
			{ tag = 'argtd', content = 'romaji' }
		})
		:addRow(
			{
				{ tag = 'th', content = 'English' },
				{ tag = 'argtd', content = 'english' }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader({ tag = 'th', content = 'Item Description' }, { subheader = true })
		:addRow({
			{ tag = 'argtd', content = 'description', css = { ['text-align'] = 'center' } }
		})
	
	local categories = ""
	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.