Module:Infobox story

From Sekaipedia

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

local p = {}

local function formatCharacters(characters)
	if characters == nil then return nil end
	
	local resArr = {}
	for _, character in ipairs(characters) do
		table.insert(resArr, cicon({ character, 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', fn = string.lower },
			{ name = 'image' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'chapters' },
			{ name = 'key unit', fn = ProcessingFns.stringToArray(';') },
			{ name = 'involved unit', fn = ProcessingFns.stringToArray(';') },
			{ name = 'character', fn = ProcessingFns.stringToArray(',') },
			{ name = 'translator', fn = ProcessingFns.stringToArray(',') },
			{ name = 'proofreader', fn = ProcessingFns.stringToArray(',') },
			{ name = 'source', fn = ProcessingFns.stringToArray(',') }
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['type'] = {
				['main']  = 'Main Stories',
				['event'] = 'Event stories',
				['special'] = 'Special Stories',
			},
		})

	infobox
		:addHeader({ tag = 'argth', content = 'story name' })
		:addImage({
			{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
		})
		: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', 
					fn = DisplayFns.list('unbulleted') 
				}
			},
			{ hideIfEmpty = { 'key unit' } }
		)
		:addRow(
			{
				{ 
					tag = 'argth',
					content = 'involved unit',
					fn = DisplayFns.pluralHeader({ 'Unit involved', 'Units involved' })
				},
				{ 
					tag = 'argtd',
					content = 'involved unit', 
					fn = DisplayFns.list('unbulleted')
				}
			},
			{ hideIfEmpty = { 'involved unit' } }
		)
		:addRow({
			{ 
				tag = 'argth', 
				content = 'character',
				fn = DisplayFns.pluralHeader({ 'Character', 'Characters' })
			},
			{ 
				tag = 'argtd', 
				content = 'character',
				fn = formatCharacters 
			}
		})
		:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
		:addRow(
			{
				{ 
					tag = 'argth', 
					content = 'translator',
					fn = DisplayFns.pluralHeader({ 'Translator', 'Translators' })
				},
				{
					tag = 'argtd', 
					content = 'translator', 
					fn = DisplayFns.list('unbulleted') 
				}
			},
			{ hideIfEmpty = { 'translator' } }
		)
		:addRow(
			{
				{ 
					tag = 'argth',
					content = 'proofreader',
					fn = DisplayFns.pluralHeader({ 'Proofreader', 'Proofreaders' })
				},
				{ 
					tag = 'argtd',
					content = 'proofreader',
					fn = DisplayFns.list('unbulleted')
				}
			},
			{ hideIfEmpty = { 'proofreader' } }
		)
		:addRow({
			{ 
				tag = 'argth',
				content = 'source',
				fn = DisplayFns.pluralHeader({ 'Source', 'Sources' })
			},
			{ 
				tag = 'argtd',
				content = 'source',
				fn = DisplayFns.list('unbulleted')
			}
		})
	
	local categories = ""
	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.