This module depends on the following other modules: |
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 InfoboxBuilder = require('Module:InfoboxBuilder')
local p = {}
local function splitStringWithDelim(delim)
return function(str)
if str == nil then
return nil
end
local list = mw.text.split(str, delim)
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
end
local function formatImage(image_name)
return string.format("[[File:%s|128px]]", image_name)
end
local function formatLink(link)
return '[[' .. link .. ']]'
end
local function formatBoolean(bool)
if bool == true then
return 'Yes'
elseif bool == false then
return 'No'
end
return nil
end
local function formatList(list)
if #list < 2 then
return list[1]
end
local ul = mw.html.create('ul')
for i=1,#list do
ul:tag('li')
:wikitext(list[i])
end
return tostring(ul)
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 = InfoboxBuilder.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 = 'acquire', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'price' },
{ name = 'card', dFunc = formatLink },
{ name = 'pass' },
{ name = 'gacha' },
{ 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 = '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' } }
)
:addRow(
{
{ tag = 'th', content = 'Gacha' },
{ tag = 'argtd', content = 'gacha' }
},
{ hideIfEmpty = { 'gacha' } }
)
: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]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p