Content added Content deleted
(import yesno) |
No edit summary |
||
(34 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
-------------------------- |
-------------------------- |
||
-- Module for [[Template:Infobox |
-- Module for [[Template:Infobox costume]] |
||
------------------------ |
------------------------ |
||
local getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local |
local DisplayFns = require('Module:DisplayFunctions') |
||
local ProcessingFns = require('Module:ProcessingFunctions') |
|||
local p = {} |
local p = {} |
||
local categories = "" |
|||
local function |
local function getAccessoryClass(accessory) |
||
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 |
-- probably should not use == with bool, but this is more explicit |
||
if |
if accessory == true then |
||
return ' |
return 'true-cell' |
||
elseif |
elseif accessory == false then |
||
return ' |
return 'false-cell' |
||
end |
end |
||
return nil |
return nil |
||
end |
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) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame, { wrappers = { 'Template:Infobox costume' } }) |
||
local infobox = |
local infobox = InfoboxBuilder.new() |
||
infobox:setName('Infobox |
infobox:setName('Infobox costume') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = 'costume id' }, |
{ name = 'costume id' }, |
||
{ name = 'costume name', default = mw.title.getCurrentTitle().text }, |
{ name = 'costume name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'thumbnail' |
{ name = 'thumbnail' }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'gender' }, |
|||
{ name = 'designer' }, |
{ name = 'designer' }, |
||
{ name = ' |
{ name = 'date' }, |
||
{ name = ' |
{ name = 'acquire', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = ' |
{ name = 'price', fn = ProcessingFns.stringToArray(';') }, |
||
{ name = ' |
{ name = 'card' }, |
||
{ name = 'card id' }, |
|||
{ name = 'pass' }, |
|||
{ name = 'gacha' }, |
|||
{ name = 'accessory', fn = ProcessingFns.stringToBoolOrNil }, |
|||
{ name = 'unique accessory', fn = ProcessingFns.stringToBoolOrNil }, |
|||
{ name = 'unique hair', fn = ProcessingFns.stringToBoolOrNil }, |
|||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setHeaderColors({ |
|||
:setCategoryMap({ |
|||
['background-color'] = '#00cdba', |
|||
[' |
['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 |
infobox |
||
:addHeader({ tag = 'argth', content = 'costume name' }) |
:addHeader({ tag = 'argth', content = 'costume name' }) |
||
:addImage({ |
:addImage({ |
||
{ tag = 'argtd', content = 'thumbnail' }, |
{ tag = 'argtd', content = 'thumbnail', fn = DisplayFns.image('128px') }, |
||
}) |
}) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 87: | Line 78: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
) |
) |
||
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Costume Information' }, { subheader = true }) |
||
:addRow({ |
|||
{ tag = 'th', content = 'Gender' }, |
|||
{ tag = 'argtd', content = 'gender' } |
|||
}) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Designer' |
{ tag = 'th', content = 'Designer' }, |
||
{ tag = 'argtd', content = 'designer' |
{ tag = 'argtd', content = 'designer' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'designer' } } |
{ hideIfEmpty = { 'designer' } } |
||
) |
) |
||
:addHeader({ tag = 'th', content = 'Acquisition Information' }, { subheader = true }) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Release date' }, |
|||
{ tag = 'argtd', content = 'date' }, |
|||
}) |
|||
:addRow({ |
|||
{ |
|||
tag = 'argth', |
|||
content = 'acquire', |
|||
fn = DisplayFns.pluralHeader({ 'Acquition method', 'Acquition methods'}) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'acquire', |
|||
fn = DisplayFns.list('unbulleted') |
|||
}, |
|||
}) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Price' |
{ tag = 'th', content = 'Price' }, |
||
{ tag = 'argtd', content = 'price', |
{ tag = 'argtd', content = 'price', fn = DisplayFns.list('unbulleted') } |
||
}, |
}, |
||
{ hideIfEmpty = { 'price' } } |
{ hideIfEmpty = { 'price' } } |
||
Line 109: | Line 121: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Associated |
{ tag = 'th', content = 'Associated card' }, |
||
{ tag = 'argtd', content = 'card', |
{ tag = 'argtd', content = 'card', fn = DisplayFns.link } |
||
}, |
}, |
||
{ hideIfEmpty = { 'card' } } |
{ hideIfEmpty = { 'card' } } |
||
) |
) |
||
:addRow( |
|||
:addHeader({ tag = 'th', content = 'Accessory Information' }, { subheader = true }) |
|||
{ |
|||
{ 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( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Accessory' }, |
{ tag = 'th', content = 'Accessory' }, |
||
{ tag = 'th', content = 'Unique Accessory' } |
{ tag = 'th', content = 'Unique Accessory' }, |
||
{ tag = 'th', content = 'Unique Hair' }, |
|||
}, |
}, |
||
{ |
{ defaultCss = { ['text-align'] = 'center' } } |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ |
|||
{ tag = 'argtd', content = 'accessory', param_css = { getAccessoryCss } }, |
|||
tag = 'argtd', |
|||
content = 'accessory', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getAccessoryClass } |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'unique accessory', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getAccessoryClass } |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'unique hair', |
|||
fn = DisplayFns.checkAndX, |
|||
classFns = { getAccessoryClass } |
|||
} |
|||
}, |
}, |
||
{ |
{ defaultCss = { ['text-align'] = 'center' } } |
||
) |
) |
||
local categories = "" |
|||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Costumes]]" .. |
categories = "[[Category:Costumes]]" .. infobox:getCategories() |
||
end |
end |
||
Latest revision as of 03:02, 3 November 2022
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 InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local p = {}
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
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' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'gender' },
{ name = 'designer' },
{ name = 'date' },
{ name = 'acquire', fn = ProcessingFns.stringToArray(',') },
{ name = 'price', fn = ProcessingFns.stringToArray(';') },
{ name = 'card' },
{ name = 'card id' },
{ name = 'pass' },
{ name = 'gacha' },
{ name = 'accessory', fn = ProcessingFns.stringToBoolOrNil },
{ name = 'unique accessory', fn = ProcessingFns.stringToBoolOrNil },
{ name = 'unique hair', fn = ProcessingFns.stringToBoolOrNil },
}
: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', fn = DisplayFns.image('128px') },
})
: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 = 'argth',
content = 'acquire',
fn = DisplayFns.pluralHeader({ 'Acquition method', 'Acquition methods'})
},
{
tag = 'argtd',
content = 'acquire',
fn = DisplayFns.list('unbulleted')
},
})
:addRow(
{
{ tag = 'th', content = 'Price' },
{ tag = 'argtd', content = 'price', fn = DisplayFns.list('unbulleted') }
},
{ hideIfEmpty = { 'price' } }
)
:addRow(
{
{ tag = 'th', content = 'Associated card' },
{ tag = 'argtd', content = 'card', fn = DisplayFns.link }
},
{ 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',
fn = DisplayFns.checkAndX,
classFns = { getAccessoryClass }
},
{
tag = 'argtd',
content = 'unique accessory',
fn = DisplayFns.checkAndX,
classFns = { getAccessoryClass }
},
{
tag = 'argtd',
content = 'unique hair',
fn = DisplayFns.checkAndX,
classFns = { 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