Content added Content deleted
m (ChaoticShadow moved page Module:Infobox Character to Module:Infobox character without leaving a redirect) |
(using new builder) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder new') |
||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local p = {} |
local p = {} |
||
⚫ | |||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
Line 32: | Line 30: | ||
end |
end |
||
local function |
local function splitList(str) |
||
if |
if str == nil then |
||
⚫ | |||
return table.concat(mw.text.split(arg, "\n"), "<br>") |
|||
else |
|||
⚫ | |||
end |
end |
||
⚫ | |||
local list = mw.text.split(str, '\n') |
|||
for i=1,#list do |
|||
list[i] = mw.text.trim(list[i]) |
|||
end |
|||
⚫ | |||
return list |
|||
end |
end |
||
local function displayList(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 |
|||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local infobox = |
local infobox = InfoboxBuilder.new(); |
||
infobox:setName('Infobox character') |
infobox:setName('Infobox character') |
||
⚫ | |||
:setWidth("330px") |
|||
{ name = 'character name', default = mw.title.getCurrentTitle().text }, |
|||
⚫ | |||
{ name = 'character |
{ name = 'character image', dFunc = formatImage }, |
||
{ name = ' |
{ name = 'japanese' }, |
||
{ name = ' |
{ name = 'romaji' }, |
||
{ name = ' |
{ name = 'english' }, |
||
{ name = ' |
{ name = 'unit', dFunc = formatUnit }, |
||
{ name = ' |
{ name = 'position' }, |
||
{ name = ' |
{ name = 'gender' }, |
||
{ name = ' |
{ name = 'birthday' }, |
||
{ name = ' |
{ name = 'height' }, |
||
{ name = ' |
{ name = 'school', pFunc = splitList, dFunc = displayList }, |
||
{ name = ' |
{ name = 'hobbies', pFunc = splitList, dFunc = displayList }, |
||
{ name = ' |
{ name = 'talents', pFunc = splitList, dFunc = displayList }, |
||
{ name = ' |
{ name = 'dislikes', pFunc = splitList, dFunc = displayList }, |
||
{ name = ' |
{ name = 'bad at', pFunc = splitList, dFunc = displayList }, |
||
{ name = ' |
{ name = 'color', dFunc = formatColor }, |
||
{ name = ' |
{ name = 'seiyuu', pFunc = splitList, dFunc = displayList } |
||
} |
|||
{ name = 'seiyuu', func = breakLine } |
|||
⚫ | |||
⚫ | |||
infobox |
|||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
if args['color'] and args['color'] ~= '' then |
if args['color'] and args['color'] ~= '' then |
||
Line 80: | Line 95: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'English' |
{ tag = 'th', content = 'English' }, |
||
{ tag = 'argtd', content = 'english' |
{ tag = 'argtd', content = 'english' } |
||
} |
} |
||
) |
) |
||
Line 100: | Line 115: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Position' |
{ tag = 'th', content = 'Position' }, |
||
{ tag = 'argtd', content = 'position' |
{ tag = 'argtd', content = 'position' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'position' } } |
{ hideIfEmpty = { 'position' } } |
||
Line 108: | Line 123: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Gender' |
{ tag = 'th', content = 'Gender' }, |
||
{ tag = 'argtd', content = 'gender' |
{ tag = 'argtd', content = 'gender' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Birthday' |
{ tag = 'th', content = 'Birthday' }, |
||
{ tag = 'argtd', content = 'birthday' |
{ tag = 'argtd', content = 'birthday' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Height' |
{ tag = 'th', content = 'Height' }, |
||
{ tag = 'argtd', content = 'height' |
{ tag = 'argtd', content = 'height' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'School' |
{ tag = 'th', content = 'School' }, |
||
{ tag = 'argtd', content = 'school' |
{ tag = 'argtd', content = 'school' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'school' } } |
{ hideIfEmpty = { 'school' } } |
||
Line 133: | Line 148: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Hobbies' |
{ tag = 'th', content = 'Hobbies' }, |
||
{ tag = 'argtd', content = 'hobbies' |
{ tag = 'argtd', content = 'hobbies' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'hobbies' } } |
{ hideIfEmpty = { 'hobbies' } } |
||
Line 140: | Line 155: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Talents' |
{ tag = 'th', content = 'Talents' }, |
||
{ tag = 'argtd', content = 'talents' |
{ tag = 'argtd', content = 'talents' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'talents' } } |
{ hideIfEmpty = { 'talents' } } |
||
Line 147: | Line 162: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Dislikes' |
{ tag = 'th', content = 'Dislikes' }, |
||
{ tag = 'argtd', content = 'dislikes' |
{ tag = 'argtd', content = 'dislikes' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'dislikes' } } |
{ hideIfEmpty = { 'dislikes' } } |
||
Line 154: | Line 169: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Bad at' |
{ tag = 'th', content = 'Bad at' }, |
||
{ tag = 'argtd', content = 'bad at' |
{ tag = 'argtd', content = 'bad at' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'bad at' } } |
{ hideIfEmpty = { 'bad at' } } |
||
Line 161: | Line 176: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Image Color' |
{ tag = 'th', content = 'Image Color' }, |
||
{ tag = 'argtd', content = 'color' |
{ tag = 'argtd', content = 'color' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Seiyuu' |
{ tag = 'th', content = 'Seiyuu' }, |
||
{ tag = 'argtd', content = 'seiyuu' |
{ tag = 'argtd', content = 'seiyuu' } |
||
} |
} |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Characters]]" .. categories |
categories = "[[Category:Characters]]" .. categories |
Revision as of 05:18, 7 January 2022
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 InfoboxBuilder = require('Module:InfoboxBuilder new')
local constants = require('Module:Constants')
local p = {}
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 splitList(str)
if str == nil then
return nil
end
local list = mw.text.split(str, '\n')
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
local function displayList(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
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox character')
:setParams{
{ name = 'character name', default = mw.title.getCurrentTitle().text },
{ name = 'character image', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'unit', dFunc = formatUnit },
{ name = 'position' },
{ name = 'gender' },
{ name = 'birthday' },
{ name = 'height' },
{ name = 'school', pFunc = splitList, dFunc = displayList },
{ name = 'hobbies', pFunc = splitList, dFunc = displayList },
{ name = 'talents', pFunc = splitList, dFunc = displayList },
{ name = 'dislikes', pFunc = splitList, dFunc = displayList },
{ name = 'bad at', pFunc = splitList, dFunc = displayList },
{ name = 'color', dFunc = formatColor },
{ name = 'seiyuu', pFunc = splitList, dFunc = displayList }
}
:setArgs(args)
:processArgs()
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' },
{ tag = 'argtd', content = 'japanese' }
}
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
}
)
:addRow(
{
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english' }
}
)
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
:addImage{{ tag = 'argtd', content = 'unit' }}
:addRow(
{
{ tag = 'th', content = 'Position' },
{ tag = 'argtd', content = 'position' }
},
{ hideIfEmpty = { 'position' } }
)
:addHeader({ tag = 'th', content = 'Profile' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Gender' },
{ tag = 'argtd', content = 'gender' }
}
)
:addRow(
{
{ tag = 'th', content = 'Birthday' },
{ tag = 'argtd', content = 'birthday' }
}
)
:addRow(
{
{ tag = 'th', content = 'Height' },
{ tag = 'argtd', content = 'height' }
}
)
:addRow(
{
{ tag = 'th', content = 'School' },
{ tag = 'argtd', content = 'school' }
},
{ hideIfEmpty = { 'school' } }
)
:addRow(
{
{ tag = 'th', content = 'Hobbies' },
{ tag = 'argtd', content = 'hobbies' }
},
{ hideIfEmpty = { 'hobbies' } }
)
:addRow(
{
{ tag = 'th', content = 'Talents' },
{ tag = 'argtd', content = 'talents' }
},
{ hideIfEmpty = { 'talents' } }
)
:addRow(
{
{ tag = 'th', content = 'Dislikes' },
{ tag = 'argtd', content = 'dislikes' }
},
{ hideIfEmpty = { 'dislikes' } }
)
:addRow(
{
{ tag = 'th', content = 'Bad at' },
{ tag = 'argtd', content = 'bad at' }
},
{ hideIfEmpty = { 'bad at' } }
)
:addRow(
{
{ tag = 'th', content = 'Image Color' },
{ tag = 'argtd', content = 'color' }
}
)
:addRow(
{
{ tag = 'th', content = 'Seiyuu' },
{ tag = 'argtd', content = 'seiyuu' }
}
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Characters]]" .. categories
end
return infobox:tostring() .. categories
end
return p