Module:Infobox story: Difference between revisions

From Sekaipedia
Content added Content deleted
(allow multiple units)
mNo edit summary
Line 74: Line 74:
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'chapters' },
{ name = 'units', func = formatUnit },
{ name = 'units', func = formatUnits },
{ name = 'characters', func = formatCharacters },
{ name = 'characters', func = formatCharacters },
{ name = 'translators', func = formatSplit },
{ name = 'translators', func = formatSplit },

Revision as of 04:26, 4 September 2021

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


--------------------------
-- Module for [[Template:Infobox Story]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local builder   = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils     = require('Module:Utilities')
local icons     = require('Module:Icons')._main


local p = {}

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

local function formatSplit(val)
	if val then
		local split_vals = utils.split(val, ",")
		for i,v in ipairs(split_vals) do
			split_vals[i] = utils.trim(v)
		end
		
		return table.concat(split_vals, "<br>")
	end
	
	return nil
end

local function formatUnits(units)
	if units and units ~= '' then
		local split_units = mw.text.split(units, ',')
		local res_list = {}
		
		for i,v in ipairs(split_units) do
			local icon = icons({ v, size = '20px' })
			if icon then
				table.insert(res_list, string.format(
					"%s [[%s]]",
					icon,
					constants.get_unit(v)
				))
			end
		end
		
		return table.concat(res_list, '<br>')
	end
	
	return nil
end

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



function p.main(frame)
	local args = getArgs(frame)
	local infobox = builder.new()
	
	infobox:setName('Infobox Story')
		:setWidth("330px")
		:setParams{
			{ name = 'story name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'chapters' },
			{ name = 'units', func = formatUnits },
			{ name = 'characters', func = formatCharacters },
			{ name = 'translators', func = formatSplit },
			{ name = 'proofreaders', func = formatSplit },
			{ name = 'sources', func = formatSplit }
		}
		:setArgs(args)
		:setHeaderColors({
			['background-color'] = '#00cdba',
			['color'] = '#000'
		})

	infobox
		:addHeader({ tag = 'argth', content = 'story name' })
		:addImage({
			{ tag = 'argtd', content = 'image' },
		})
		:addRow({
			{ tag = 'th', content = 'Japanese', colspan = 12 },
			{ tag = 'argtd', content = 'japanese', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Romaji', colspan = 12 },
			{ tag = 'argtd', content = 'romaji', colspan = 18 }
		})
		:addHeader({ tag = 'th', content = 'Story Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Chapters', colspan = 12 },
			{ tag = 'argtd', content = 'chapters', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Units', colspan = 12 },
			{ tag = 'argtd', content = 'units', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Characters', colspan = 12 },
			{ tag = 'argtd', content = 'characters', colspan = 18 }
		})
		:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
		:addRow({
			{ tag = 'th', content = 'Translators', colspan = 12 },
			{ tag = 'argtd', content = 'translators', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Proofreaders', colspan = 12 },
			{ tag = 'argtd', content = 'proofreaders', colspan = 18 }
		})
		:addRow({
			{ tag = 'th', content = 'Sources', colspan = 12 },
			{ tag = 'argtd', content = 'sources', colspan = 18 }
		})

	return infobox:tostring()
end

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