Module:Charcat

-- -- Module for Template:Infobox Charcat

local getArgs  = require('Module:Arguments').getArgs local InfoboxBuilder = require('Module:InfoboxBuilder') local DisplayFns    = require('Module:DisplayFunctions') local ProcessingFns = require('Module:ProcessingFunctions') local constants = require('Module:Constants')

local p = {}

local function formatColor(color) if color and color ~= nil then return string.format(			"%s  ",			color,			color		); end end

local function formatHometown(list) if list == nil then return nil end return table.concat(list, ' ') 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' }, { name = 'Native' }, { name = 'romaji' }, { name = 'english' }, { name = 'position' }, { name = 'gender' }, { name = 'birthday' }, { name = 'height' }, { name = 'Hometown', fn = ProcessingFns.stringToArray('\n') }, { name = 'hobbies', fn = ProcessingFns.stringToArray('\n') }, { name = 'talents', fn = ProcessingFns.stringToArray('\n') }, { name = 'dislikes', fn = ProcessingFns.stringToArray('\n') }, { name = 'bad at', fn = ProcessingFns.stringToArray('\n') }, { name = 'color' }, }		:setArgs(args) :processArgs if args['color'] and args['color'] ~= '' then infobox:setHeaderBackgroundColor(args['color']) end

infobox :addHeader({ tag = 'argth', content = 'character name' }) :addImage :addRow(			{				{ tag = 'th', content = 'Native' },				{ tag = 'argtd', content = 'Native' }			}		) :addRow(			{				{ tag = 'th', content = 'Romaji' },				{ tag = 'argtd', content = 'romaji' }			}		) :addRow(			{				{ tag = 'th', content = 'English' },				{ tag = 'argtd', content = 'english' }			}		) :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 = 'Hometown' },				{ tag = 'argtd', content = 'Hometown', fn = formatHometown }			},			{ hideIfEmpty = { 'Hometown' } }		) :addRow(			{				{ tag = 'th', content = 'Hobbies' },				{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }			},			{ hideIfEmpty = { 'hobbies' } }		) :addRow(			{				{ tag = 'th', content = 'Talents' },				{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }			},			{ hideIfEmpty = { 'talents' } }		) :addRow(			{				{ tag = 'th', content = 'Dislikes' },				{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }			},			{ hideIfEmpty = { 'dislikes' } }		) :addRow(			{				{ tag = 'th', content = 'Bad at' },				{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }			},			{ hideIfEmpty = { 'bad at' } }		) :addRow(			{				{ tag = 'th', content = 'Image color' },				{ tag = 'argtd', content = 'color', fn = formatColor }			}		) local categories = "" if mw.title.getCurrentTitle.namespace == 0 then categories = "" .. categories end

return infobox:tostring .. categories end

return p