This module depends on the following other modules: |
To generate {{Infobox character}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox character]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local p = {}
local categories = ""
local function formatImage(image_name)
return string.format("[[File:%s|315px]]", image_name)
end
local function formatUnit(unit)
if unit and unit ~= '' then
return string.format("[[File:%s|150px|link=%s]]",
constants.get_unit_image(unit),
constants.get_unit(unit))
end
return nil
end
local function formatColor(color)
return string.format(
"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px; border:1px solid;\"></span>",
color,
color
);
end
local function breakLine(arg)
if arg and arg ~= '' then
return table.concat(mw.text.split(arg, "\n"), "<br>")
else
return "<br>"
end
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new();
infobox:setName('Infobox character')
:setWidth("330px")
infobox:setParams{
{ name = 'character name', default = mw.title.getCurrentTitle().text },
{ name = 'character image', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'unit', func = formatUnit },
{ name = 'position' },
{ name = 'gender' },
{ name = 'birthday' },
{ name = 'height' },
{ name = 'school', func = breakLine },
{ name = 'hobbies', func = breakLine },
{ name = 'talents', func = breakLine },
{ name = 'dislikes', func = breakLine },
{ name = 'bad at', func = breakLine },
{ name = 'color', func = formatColor },
{ name = 'seiyuu', func = breakLine }
}
infobox
:setArgs(args)
if args['color'] and args['color'] ~= '' then
infobox:setHeaderBackgroundColor(args['color'])
end
infobox
:addHeader({ tag = 'argth', content = 'character name' })
:addImage{{ tag = 'argtd', content = 'character image' }}
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
}
)
: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'}, { subheader = true })
:addImage{{ tag = 'argtd', content = 'unit' }}
:addRow(
{
{ tag = 'th', content = 'Position', colspan = 12 },
{ tag = 'argtd', content = 'position', colspan = 18 }
},
{ hideIfEmpty = { 'position' } }
)
:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Gender', colspan = 12 },
{ tag = 'argtd', content = 'gender', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Birthday', colspan = 12 },
{ tag = 'argtd', content = 'birthday', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Height', colspan = 12 },
{ tag = 'argtd', content = 'height', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'School', colspan = 12 },
{ tag = 'argtd', content = 'school', colspan = 18 }
},
{ hideIfEmpty = { 'school' } }
)
:addRow(
{
{ tag = 'th', content = 'Hobbies', colspan = 12 },
{ tag = 'argtd', content = 'hobbies', colspan = 18 }
},
{ hideIfEmpty = { 'hobbies' } }
)
:addRow(
{
{ tag = 'th', content = 'Talents', colspan = 12 },
{ tag = 'argtd', content = 'talents', colspan = 18 }
},
{ hideIfEmpty = { 'talents' } }
)
:addRow(
{
{ tag = 'th', content = 'Dislikes', colspan = 12 },
{ tag = 'argtd', content = 'dislikes', colspan = 18 }
},
{ hideIfEmpty = { 'dislikes' } }
)
:addRow(
{
{ tag = 'th', content = 'Bad at', colspan = 12 },
{ tag = 'argtd', content = 'bad at', colspan = 18 }
},
{ hideIfEmpty = { 'bad at' } }
)
:addRow(
{
{ tag = 'th', content = 'Image Color', colspan = 12 },
{ tag = 'argtd', content = 'color', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Seiyuu', colspan = 12 },
{ tag = 'argtd', content = 'seiyuu', colspan = 18 }
}
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Characters]]" .. categories
end
return infobox:tostring() .. categories
end
return p