Module:Infobox character: Difference between revisions

From Sekaipedia
Content added Content deleted
(migrated to infoboxbuilder)
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 3: Line 3:
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFunctions = require('Module:InfoboxBuilderDisplayFunctions')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local constants = require('Module:Constants')
local constants = require('Module:Constants')


Line 11: Line 11:


local function formatUnit(unit)
local function formatUnit(unit)
if unit and unit ~= '' then
if unit and unit ~= nil then
return string.format("[[File:%s|150px|link=%s]]",
return string.format("[[File:%s|150px|link=%s]]",
constants.get_unit_image(unit),
constants.get_unit_image(unit),
Line 21: Line 21:


local function formatColor(color)
local function formatColor(color)
if color and color ~= nil then
return string.format(
return string.format(
"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px; border:1px solid;\"></span>",
"%s <span style=\"height: 10px; width: 10px; background: %s; display: inline-block;margin-left: 5px; border:1px solid;\"></span>",
color,
color
color,
color
);
);
end
end
end


local function displayList(list)
local function formatSchool(list)
if #list < 2 then
if list == nil then return nil end
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)
return table.concat(list, '<br>')
end
end


Line 51: Line 44:
:setParams{
:setParams{
{ name = 'character name', default = mw.title.getCurrentTitle().text },
{ name = 'character name', default = mw.title.getCurrentTitle().text },
{ name = 'character image', dFunc = DisplayFunctions.generateImage('315px') },
{ name = 'character image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'english' },
{ name = 'unit', dFunc = formatUnit },
{ name = 'unit' },
{ name = 'position' },
{ name = 'position' },
{ name = 'gender' },
{ name = 'gender' },
{ name = 'birthday' },
{ name = 'birthday' },
{ name = 'height' },
{ name = 'height' },
{ name = 'school', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList },
{ name = 'school', fn = ProcessingFns.stringToArray('\n') },
{ name = 'hobbies', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList },
{ name = 'hobbies', fn = ProcessingFns.stringToArray('\n') },
{ name = 'talents', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList },
{ name = 'talents', fn = ProcessingFns.stringToArray('\n') },
{ name = 'dislikes', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList },
{ name = 'dislikes', fn = ProcessingFns.stringToArray('\n') },
{ name = 'bad at', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList },
{ name = 'bad at', fn = ProcessingFns.stringToArray('\n') },
{ name = 'color', dFunc = formatColor },
{ name = 'color' },
{ name = 'seiyuu', pFunc = ProcessingFunctions.convertStringToArray('\n'), dFunc = displayList }
{ name = 'seiyuu', fn = ProcessingFns.stringToArray('\n') }
}
}
:setArgs(args)
:setArgs(args)
Line 77: Line 70:
infobox
infobox
:addHeader({ tag = 'argth', content = 'character name' })
:addHeader({ tag = 'argth', content = 'character name' })
:addImage{{ tag = 'argtd', content = 'character image' }}
:addImage{{
tag = 'argtd',
content = 'character image',
fn = DisplayFns.image('315px')
}}
:addRow(
:addRow(
{
{
Line 97: Line 94:
)
)
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
:addHeader({ tag = 'th', content = 'Unit'}, { subheader = true })
:addImage{{ tag = 'argtd', content = 'unit' }}
:addImage{{
tag = 'argtd',
content = 'unit',
fn = formatUnit
}}
:addRow(
:addRow(
{
{
Line 127: Line 128:
{
{
{ tag = 'th', content = 'School' },
{ tag = 'th', content = 'School' },
{ tag = 'argtd', content = 'school' }
{ tag = 'argtd', content = 'school', fn = formatSchool }
},
},
{ hideIfEmpty = { 'school' } }
{ hideIfEmpty = { 'school' } }
Line 134: Line 135:
{
{
{ tag = 'th', content = 'Hobbies' },
{ tag = 'th', content = 'Hobbies' },
{ tag = 'argtd', content = 'hobbies' }
{ tag = 'argtd', content = 'hobbies', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'hobbies' } }
{ hideIfEmpty = { 'hobbies' } }
Line 141: Line 142:
{
{
{ tag = 'th', content = 'Talents' },
{ tag = 'th', content = 'Talents' },
{ tag = 'argtd', content = 'talents' }
{ tag = 'argtd', content = 'talents', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'talents' } }
{ hideIfEmpty = { 'talents' } }
Line 148: Line 149:
{
{
{ tag = 'th', content = 'Dislikes' },
{ tag = 'th', content = 'Dislikes' },
{ tag = 'argtd', content = 'dislikes' }
{ tag = 'argtd', content = 'dislikes', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'dislikes' } }
{ hideIfEmpty = { 'dislikes' } }
Line 155: Line 156:
{
{
{ tag = 'th', content = 'Bad at' },
{ tag = 'th', content = 'Bad at' },
{ tag = 'argtd', content = 'bad at' }
{ tag = 'argtd', content = 'bad at', fn = DisplayFns.list('unbulleted') }
},
},
{ hideIfEmpty = { 'bad at' } }
{ hideIfEmpty = { 'bad at' } }
Line 162: Line 163:
{
{
{ tag = 'th', content = 'Image color' },
{ tag = 'th', content = 'Image color' },
{ tag = 'argtd', content = 'color' }
{ tag = 'argtd', content = 'color', fn = formatColor }
}
}
)
)
Line 168: Line 169:
{
{
{ tag = 'th', content = 'Seiyuu' },
{ tag = 'th', content = 'Seiyuu' },
{ tag = 'argtd', content = 'seiyuu' }
{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') }
}
}
)
)

Latest revision as of 15:32, 19 October 2022

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')
local DisplayFns     = require('Module:DisplayFunctions')
local ProcessingFns  = require('Module:ProcessingFunctions')
local constants = require('Module:Constants')

local p = {}

local function formatUnit(unit)
	if unit and unit ~= nil 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)
	if color and color ~= nil then
		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
end

local function formatSchool(list)
	if list == nil then return nil end
	
	return table.concat(list, '<br>')
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 = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'unit' },
			{ name = 'position' },
			{ name = 'gender' },
			{ name = 'birthday' },
			{ name = 'height' },
			{ name = 'school', 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' },
			{ name = 'seiyuu', fn = ProcessingFns.stringToArray('\n') }
		}
		: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',
			fn = DisplayFns.image('315px')
		}}
		: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',
			fn = formatUnit
		}}
		: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', fn = formatSchool }
			},
			{ hideIfEmpty = { 'school' } }
		)
		: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 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Seiyuu' },
				{ tag = 'argtd', content = 'seiyuu', fn = DisplayFns.list('unbulleted') }
			}
		)
		
	local categories = ""
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Characters]]" .. categories
	end

	return infobox:tostring() .. categories
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.