Content added Content deleted
(added accessory information) |
(import yesno) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local yesno = require('Module:Yesno') |
|||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder') |
||
Revision as of 00:26, 19 October 2021
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 builder = require('Module:InfoboxBuilder')
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|128px]]", image_name)
end
local function formatLink(to_link)
return '[[' .. to_link .. ']]'
end
local function formatAccessory(accessory)
local val = yesno(accessory, nil)
-- probably should not use == with bool, but this is more explicit
if val == true then
return '✓'
elseif val == false then
return '✗'
end
return nil
end
local function getAccessoryCss(accessory)
local val = yesno(accessory, nil)
-- probably should not use == with bool, but this is more explicit
if val == true then
return {
['background-color'] = 'lightgreen',
['font-weight'] = 'bold'
}
elseif val == false then
return {
['background-color'] = 'pink',
['font-weight'] = 'bold'
}
end
return nil
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox Costume')
:setWidth("330px")
:setParams{
{ name = 'costume id' },
{ name = 'costume name', default = mw.title.getCurrentTitle().text },
{ name = 'thumbnail', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'designer' },
{ name = 'price' },
{ name = 'card', func = formatLink },
{ name = 'accessory', func = formatAccessory },
{ name = 'unique accessory', func = formatAccessory },
}
:setArgs(args)
:setHeaderColors({
['background-color'] = '#00cdba',
['color'] = '#000'
})
infobox
:addHeader({ tag = 'argth', content = 'costume name' })
:addImage({
{ tag = 'argtd', content = 'thumbnail' },
})
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Designer', colspan = 12 },
{ tag = 'argtd', content = 'designer', colspan = 18 }
},
{ hideIfEmpty = { 'designer' } }
)
:addRow(
{
{ tag = 'th', content = 'Price', colspan = 12 },
{ tag = 'argtd', content = 'price', colspan = 18 }
},
{ hideIfEmpty = { 'price' } }
)
:addRow(
{
{ tag = 'th', content = 'Associated Card', colspan = 12 },
{ tag = 'argtd', content = 'card', colspan = 18 }
},
{ hideIfEmpty = { 'card' } }
)
:addHeader({ tag = 'th', content = 'Accessory Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Accessory' },
{ tag = 'th', content = 'Unique Accessory' }
},
{ default_css = { ['text-align'] = 'center' } }
)
:addRow(
{
{ tag = 'argtd', content = 'accessory', param_css = { getAccessoryCss } },
{ tag = 'argtd', content = 'unique accessory', param_css = { getAccessoryCss } }
},
{ default_css = { ['text-align'] = 'center' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Costumes]]" .. categories
end
return infobox:tostring() .. categories
end
return p