Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox costume: Difference between revisions

From Sekaipedia
Content added Content deleted
m (add mission pass row)
(using new builder)
Line 4:
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local builder = require('Module:InfoboxBuilder new')
 
local p = {}
local categories = ""
 
local function formatImage(image_name)
Line 13 ⟶ 12:
end
 
local function formatLink(to_linklink)
return '[[' .. to_linklink .. ']]'
end
 
local function formatAccessory(accessory)
local val = yesno(accessory, nil)
-- probably should not use == with bool, but this is more explicit
if valaccessory == true then
return '✓'
elseif valaccessory == false then
return '✗'
end
Line 29 ⟶ 27:
end
 
local function getAccessoryCssgetAccessoryClass(accessory)
local val = yesno(accessory, nil)
-- probably should not use == with bool, but this is more explicit
if valaccessory == true then
return {'true-cell'
elseif valaccessory == false then
['background-color'] = 'lightgreen',
return {'false-cell'
['font-weight'] = 'bold'
}
elseif val == false then
return {
['background-color'] = 'pink',
['font-weight'] = 'bold'
}
end
Line 47 ⟶ 38:
end
 
local function convertToBoolOrNil(val)
local val =return yesno(accessoryval, nil)
end
 
 
function p.main(frame)
local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } })
local infobox = builder.new()
infobox:setName('Infobox costume')
:setWidth("330px")
:setParams{
{ name = 'costume id' },
{ name = 'costume name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', funcdFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
Line 64 ⟶ 57:
{ name = 'designer' },
{ name = 'date' },
{ name = 'unlock' },
{ name = 'acquire' },
{ name = 'price' },
{ name = 'card', funcdFunc = formatLink },
{ name = 'pass' },
{ name = 'accessory', funcpFunc = convertToBoolOrNil, dFunc = formatAccessory },
{ name = 'unique accessory', funcpFunc = convertToBoolOrNil, dFunc = formatAccessory },
{ name = 'unique hair', funcpFunc = convertToBoolOrNil, dFunc = formatAccessory },
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['gender'] = {
['Ladies'] = 'Ladies\' costumes',
['Men'] = 'Men\'s costumes'
},
if yesno(rawArgs ['accessory'], nil)= then{
categories [true] = categories .. "[[Category:'Costumes with accessories]]"',
},
if yesno(rawArgs ['unique accessory'], nil)= then{
categories [true] = categories .. "[[Category:'Costumes with unique accessories]]"'
},
if yesno(rawArgs ['unique hair'], nil)= then{
categories [true] = categories .. "[[Category:'Costumes with unique hair]]"'
},
})
 
 
infobox
Line 81 ⟶ 92:
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
},
{ hideIfEmpty = { 'japanese' } }
Line 88 ⟶ 99:
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
Line 95 ⟶ 106:
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Gender', colspan = 12 },
{ tag = 'argtd', content = 'gender', colspan = 18 }
})
:addRow(
{
{ tag = 'th', content = 'Designer', colspan = 12 },
{ tag = 'argtd', content = 'designer', colspan = 18 }
},
{ hideIfEmpty = { 'designer' } }
Line 107 ⟶ 118:
:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true })
:addRow({
{ tag = 'th', content = 'Release date', colspan = 12 },
{ tag = 'argtd', content = 'date', colspan = 18 },
})
:addRow({
{ tag = 'th', content = 'AcquitionUnlock method(s)', colspan = 12 },
{ tag = 'argtd', content = 'acquireunlock', colspan = 18 },
})
:addRow({
{ tag = 'th', content = 'Acquition method(s)' },
{ tag = 'argtd', content = 'acquire' },
})
:addRow(
{
{ tag = 'th', content = 'Price', colspan = 12 },
{ tag = 'argtd', content = 'price', colspan = 18 }
},
{ hideIfEmpty = { 'price' } }
Line 123 ⟶ 138:
:addRow(
{
{ tag = 'th', content = 'Associated card', colspan = 12 },
{ tag = 'argtd', content = 'card', colspan = 18 }
},
{ hideIfEmpty = { 'card' } }
Line 130 ⟶ 145:
:addRow(
{
{ tag = 'th', content = 'Mission Pass', colspan = 12 },
{ tag = 'argtd', content = 'pass', colspan = 18 }
},
{ hideIfEmpty = { 'pass' } }
Line 142 ⟶ 157:
{ tag = 'th', content = 'Unique Hair' },
},
{ default_cssdefaultCss = { ['text-align'] = 'center' } }
)
:addRow(
{
{ tag = 'argtd', content = 'accessory', param_cssclassFunc = { getAccessoryCssgetAccessoryClass } },
{ tag = 'argtd', content = 'unique accessory', param_cssclassFunc = { getAccessoryCssgetAccessoryClass } },
{ tag = 'argtd', content = 'unique hair', param_cssclassFunc = { getAccessoryCssgetAccessoryClass } }
},
{ default_cssdefaultCss = { ['text-align'] = 'center' } }
)
 
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Costumes]]" .. categories
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
if yesno(rawArgs['accessory'], nil) then
categories = categories .. "[[Category:Costumes with accessories]]"
end
if yesno(rawArgs['unique accessory'], nil) then
categories = categories .. "[[Category:Costumes with unique accessories]]"
end
if yesno(rawArgs['unique hair'], nil) then
categories = categories .. "[[Category:Costumes with unique hair]]"
end
if rawArgs['gender'] == 'Ladies' then
categories = categories .. "[[Category:Ladies' costumes]]"
elseif rawArgs['gender'] == 'Men' then
categories = categories .. "[[Category:Men's costumes]]"
end
end
 

Revision as of 08:02, 22 January 2022

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


--------------------------
-- Module for [[Template:Infobox costume]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local yesno     = require('Module:Yesno')
local builder   = require('Module:InfoboxBuilder new')

local p = {}

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

local function formatLink(link)
	return '[[' .. link .. ']]'
end

local function formatAccessory(accessory)
	-- probably should not use == with bool, but this is more explicit
	if accessory == true then
		return '✓'
	elseif accessory == false then
		return '✗'
	end
	
	return nil
end

local function getAccessoryClass(accessory)
	-- probably should not use == with bool, but this is more explicit
	if accessory == true then
		return 'true-cell'
	elseif accessory == false then
		return 'false-cell'
	end
	
	return nil
end

local function convertToBoolOrNil(val)
	return yesno(val, nil)
end


function p.main(frame)
	local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } })
	local infobox = builder.new()
	
	infobox:setName('Infobox costume')
		:setParams{
			{ name = 'costume id' },
			{ name = 'costume name', default = mw.title.getCurrentTitle().text },
			{ name = 'thumbnail', dFunc = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'gender' },
			{ name = 'designer' },
			{ name = 'date' },
			{ name = 'unlock' },
			{ name = 'acquire' },
			{ name = 'price' },
			{ name = 'card', dFunc = formatLink },
			{ name = 'pass' },
			{ name = 'accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
			{ name = 'unique accessory', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
			{ name = 'unique hair', pFunc = convertToBoolOrNil, dFunc = formatAccessory },
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['gender'] = {
				['Ladies'] = 'Ladies\' costumes',
				['Men']    = 'Men\'s costumes'
			},
			['accessory'] = {
				[true] = 'Costumes with accessories',
			},
			['unique accessory'] = {
				[true] = 'Costumes with unique accessories'
			},
			['unique hair'] = {
				[true] = 'Costumes with unique hair'
			},
		})


	infobox
		:addHeader({ tag = 'argth', content = 'costume name' })
		:addImage({
			{ tag = 'argtd', content = 'thumbnail' },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Japanese' },
				{ tag = 'argtd', content = 'japanese' }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji' },
				{ tag = 'argtd', content = 'romaji' }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Gender' },
			{ tag = 'argtd', content = 'gender' }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Designer' },
				{ tag = 'argtd', content = 'designer' }
			},
			{ hideIfEmpty = { 'designer' } }
		)
		:addHeader({ tag = 'th', content = 'Acquisition Information'}, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Release date' },
			{ tag = 'argtd', content = 'date' },
		})
		:addRow({
			{ tag = 'th', content = 'Unlock method(s)' },
			{ tag = 'argtd', content = 'unlock' }
		})
		:addRow({
			{ tag = 'th', content = 'Acquition method(s)' },
			{ tag = 'argtd', content = 'acquire' },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Price' },
				{ tag = 'argtd', content = 'price' }
			},
			{ hideIfEmpty = { 'price' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Associated card' },
				{ tag = 'argtd', content = 'card' }
			},
			{ hideIfEmpty = { 'card' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Mission Pass' },
				{ tag = 'argtd', content = 'pass' }
			},
			{ hideIfEmpty = { 'pass' } }
		)
		:addHeader({ tag = 'th', content = 'Accessory & Hair Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Accessory' },
				{ tag = 'th', content = 'Unique Accessory' },
				{ tag = 'th', content = 'Unique Hair' },
			},
			{ defaultCss = { ['text-align'] = 'center'	} }
		)
		:addRow(
			{
				{ tag = 'argtd', content = 'accessory', classFunc = { getAccessoryClass } },
				{ tag = 'argtd', content = 'unique accessory', classFunc = { getAccessoryClass } },
				{ tag = 'argtd', content = 'unique hair', classFunc = { getAccessoryClass } }
			},
			{ defaultCss = { ['text-align'] = 'center' } }
		)
	
	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Costumes]]" .. 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.