Module:Infobox story

From Sekaipedia
Revision as of 14:07, 17 October 2022 by ChaoticShadow (talk | contribs) (migrated to infoboxbuilder)

To generate {{Infobox story}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox story]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local InfoboxBuilder      = require('Module:InfoboxBuilder')
local DisplayFunctions    = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions')
local constants = require('Module:Constants')
local utils     = require('Module:Utilities')
local cicon     = require('Module:Character icon')._main

local p = {}
local categories = ""

local function formatList(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

local function formatCharacters(characters)
	local resArr = {}
	for i,v in ipairs(characters) do
		table.insert(resArr, cicon({ v, size = '30px' }))
	end
	
	return table.concat(resArr, " ")
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new()
	
	infobox:setName('Infobox story')
		:setParams{
			{ name = 'story name', default = mw.title.getCurrentTitle().text },
			{ name = 'type', pFunc = string.lower },
			{ name = 'image', dFunc = DisplayFunctions.generateImage('220px') },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'chapters' },
			{ name = 'key unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
			{ name = 'involved unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
			{ name = 'character', pFunc = ProcessingFunctions.convertStringToArray(','),dFunc = formatCharacters },
			{ name = 'translator', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
			{ name = 'proofreader', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
			{ name = 'source', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList }
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['type'] = {
				['main']  = 'Main stories',
				['event'] = 'Event stories',
			},
		})


	infobox
		:addHeader({ tag = 'argth', content = 'story name' })
		:addImage({
			{ tag = 'argtd', content = 'image' },
		})
		: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 = 'Story Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Chapters' },
			{ tag = 'argtd', content = 'chapters' }
		})
		:addRow(
			{
				{ tag = 'th', content = 'Key unit' },
				{ tag = 'argtd', content = 'key unit' }
			},
			{ hideIfEmpty = { 'key unit' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Unit(s) involved' },
				{ tag = 'argtd', content = 'involved unit' }
			},
			{ hideIfEmpty = { 'involved unit' } }
		)
		:addRow({
			{ tag = 'th', content = 'Character(s)' },
			{ tag = 'argtd', content = 'character' }
		})
		:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Translator(s)' },
				{ tag = 'argtd', content = 'translator' }
			},
			{ hideIfEmpty = { 'translator' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Proofreader(s)' },
				{ tag = 'argtd', content = 'proofreader' }
			},
			{ hideIfEmpty = { 'proofreader' } }
		)
		:addRow({
			{ tag = 'th', content = 'Source(s)' },
			{ tag = 'argtd', content = 'source' }
		})
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Stories]]" .. infobox:getCategories()
	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.