Module:Infobox story: Difference between revisions

From Sekaipedia
Content added Content deleted
(migrated to infoboxbuilder)
No edit summary
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 new')
local DisplayFunctions = require('Module:InfoboxBuilderDisplayFunctions')
local DisplayFns = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions')
local ProcessingFns = require('Module:InfoboxBuilderProcessingFunctions')
local constants = require('Module:Constants')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local cicon = require('Module:Character icon')._main
local cicon = require('Module:Character icon')._main


local p = {}
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 function formatCharacters(characters)
local resArr = {}
local resArr = {}
for i,v in ipairs(characters) do
for _, character in ipairs(characters) do
table.insert(resArr, cicon({ v, size = '30px' }))
table.insert(resArr, cicon({ character, size = '30px' }))
end
end
Line 45: Line 28:
:setParams{
:setParams{
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'type', pFunc = string.lower },
{ name = 'type', fn = string.lower },
{ name = 'image', dFunc = DisplayFunctions.generateImage('220px') },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'chapters' },
{ name = 'key unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
{ name = 'key unit', fn = ProcessingFns.stringToArray(';') },
{ name = 'involved unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
{ name = 'involved unit', fn = ProcessingFns.stringToArray(';') },
{ name = 'character', pFunc = ProcessingFunctions.convertStringToArray(','),dFunc = formatCharacters },
{ name = 'character', fn = ProcessingFns.stringToArray(',') },
{ name = 'translator', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
{ name = 'translator', fn = ProcessingFns.stringToArray(',') },
{ name = 'proofreader', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
{ name = 'proofreader', fn = ProcessingFns.stringToArray(',') },
{ name = 'source', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList }
{ name = 'source', fn = ProcessingFns.stringToArray(',') }
}
}
:setArgs(args)
:setArgs(args)
Line 65: Line 48:
},
},
})
})



infobox
infobox
:addHeader({ tag = 'argth', content = 'story name' })
:addHeader({ tag = 'argth', content = 'story name' })
:addImage({
:addImage({
{ tag = 'argtd', content = 'image' },
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
})
})
:addRow(
:addRow(
Line 94: Line 76:
{
{
{ tag = 'th', content = 'Key unit' },
{ tag = 'th', content = 'Key unit' },
{
{ tag = 'argtd', content = 'key unit' }
tag = 'argtd',
content = 'key unit',
fn = DisplayFns.list('unbulleted')
}
},
},
{ hideIfEmpty = { 'key unit' } }
{ hideIfEmpty = { 'key unit' } }
Line 100: Line 86:
:addRow(
:addRow(
{
{
{
{ tag = 'th', content = 'Unit(s) involved' },
{ tag = 'argtd', content = 'involved unit' }
tag = 'argth',
content = 'involved unit',
fn = DisplayFns.pluralHeaders({ 'Unit involved', 'Units involved' })
},
{
tag = 'argtd',
content = 'involved unit',
fn = DisplayFns.list('unbulleted')
}
},
},
{ hideIfEmpty = { 'involved unit' } }
{ hideIfEmpty = { 'involved unit' } }
)
)
:addRow({
:addRow({
{
{ tag = 'th', content = 'Character(s)' },
{ tag = 'argtd', content = 'character' }
tag = 'argth',
content = 'character',
fn = DisplayFns.pluralHeaders({ 'Character', 'Characters' })
},
{
tag = 'argtd',
content = 'character',
fn = formatCharacters
}
})
})
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
:addRow(
:addRow(
{
{
{
{ tag = 'th', content = 'Translator(s)' },
{ tag = 'argtd', content = 'translator' }
tag = 'argth',
content = 'translator',
fn = DisplayFns.pluralHeader({ 'Translator', 'Translators' })
},
{
tag = 'argtd',
content = 'translator',
fn = DisplayFns.list('unbulleted')
}
},
},
{ hideIfEmpty = { 'translator' } }
{ hideIfEmpty = { 'translator' } }
Line 119: Line 129:
:addRow(
:addRow(
{
{
{
{ tag = 'th', content = 'Proofreader(s)' },
{ tag = 'argtd', content = 'proofreader' }
tag = 'argth',
content = 'proofreader',
fn = DisplayFns.pluralHeader({ 'Proofreader', 'Proofreaders' })
},
{
tag = 'argtd',
content = 'proofreader',
fn = DisplayFns.list('unbulleted')
}
},
},
{ hideIfEmpty = { 'proofreader' } }
{ hideIfEmpty = { 'proofreader' } }
)
)
:addRow({
:addRow({
{
{ tag = 'th', content = 'Source(s)' },
{ tag = 'argtd', content = 'source' }
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
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Stories]]" .. infobox:getCategories()
categories = "[[Category:Stories]]" .. infobox:getCategories()

Revision as of 02:47, 18 October 2022

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

local p = {}

local function formatCharacters(characters)
	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',
			},
		})

	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.pluralHeaders({ 'Unit involved', 'Units involved' })
				},
				{ 
					tag = 'argtd',
					content = 'involved unit', 
					fn = DisplayFns.list('unbulleted')
				}
			},
			{ hideIfEmpty = { 'involved unit' } }
		)
		:addRow({
			{ 
				tag = 'argth', 
				content = 'character',
				fn = DisplayFns.pluralHeaders({ '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.