Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox story: Difference between revisions

From Sekaipedia
Content added Content deleted
m (makes involved unit optional)
(migrated to infoboxbuilder)
Line 3: Line 3:
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder new')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFunctions = require('Module:InfoboxBuilderDisplayFunctions')
local ProcessingFunctions = require('Module:InfoboxBuilderProcessingFunctions')
local constants = require('Module:Constants')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local utils = require('Module:Utilities')
Line 10: Line 12:
local p = {}
local p = {}
local categories = ""
local categories = ""

local function splitStringWithDelim(delim)
return function(str)
if str == nil then
return nil
end
local list = mw.text.split(str, delim)
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
end

local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end


local function formatList(list)
local function formatList(list)
Line 57: Line 40:
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local infobox = builder.new()
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox story')
infobox:setName('Infobox story')
Line 63: Line 46:
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'type', pFunc = string.lower },
{ name = 'type', pFunc = string.lower },
{ name = 'image', dFunc = formatImage },
{ name = 'image', dFunc = DisplayFunctions.generateImage('220px') },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'chapters' },
{ name = 'key unit', pFunc = splitStringWithDelim(';'), dFunc = formatList },
{ name = 'key unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
{ name = 'involved unit', pFunc = splitStringWithDelim(';'), dFunc = formatList },
{ name = 'involved unit', pFunc = ProcessingFunctions.convertStringToArray(';'), dFunc = formatList },
{ name = 'character', pFunc = splitStringWithDelim(','),dFunc = formatCharacters },
{ name = 'character', pFunc = ProcessingFunctions.convertStringToArray(','),dFunc = formatCharacters },
{ name = 'translator', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'translator', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
{ name = 'proofreader', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'proofreader', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList },
{ name = 'source', pFunc = splitStringWithDelim(','), dFunc = formatList }
{ name = 'source', pFunc = ProcessingFunctions.convertStringToArray(','), dFunc = formatList }
}
}
:setArgs(args)
:setArgs(args)
Line 110: Line 93:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Key Unit' },
{ tag = 'th', content = 'Key unit' },
{ tag = 'argtd', content = 'key unit' }
{ tag = 'argtd', content = 'key unit' }
},
},
Line 117: Line 100:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Involved Unit(s)' },
{ tag = 'th', content = 'Unit(s) involved' },
{ tag = 'argtd', content = 'involved unit' }
{ tag = 'argtd', content = 'involved unit' }
},
},

Revision as of 14:07, 17 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')
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.