Module:Infobox: Difference between revisions

From Vintage Story Wiki
mNo edit summary
mNo edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
function p.infobox( f )
function p.infobox( f )
local args = f.args
local args = require( 'Module:ProcessArgs' ).merge( true )
local width = args.width or '250px'
local titleObject = mw.title.getCurrentTitle()
local titleObject = mw.title.getCurrentTitle()
local title = args.title or titleObject.baseText
local title = args.title or titleObject.baseText
local size = args.imagesize or '180px'
local subtitle = ''
local imageString = '[[File:' .. args.image .. '.png|180px]]' -- forcing 180px as it can't seem to use the size variable
if args.subtitle then
subtitle = '<span style="font-size:15px"><b><i>"' .. args.subtitle .. '"</i></b></span>'
end
local imageSize = args.imagesize or '180px'
local imageString
local images = {}
local images = {}
if args.images then
if args.images then
imageString = ''
imageString = ''
for image in mw.text.gsplit( args.images, '%s*;%s*' ) do
for image in mw.text.gsplit( args.images, '%s*;%s*' ) do
table.insert(images, '<span>[[File:' .. image .. '.png|64px]]</span>')
if image:match('(.*).png') or image:match('(.*).jpg') or image:match('(.*).svg') then table.insert(images, '<span>[[File:' .. image .. '|64px]]</span>')
else
table.insert(images, '<span>[[File:' .. image .. '.png|64px]]</span>')
end
end
end
for i, l in pairs(images) do
for i, l in pairs(images) do
if not i == 0 and i % 4 == 1 then
if not i == 0 and i % 3 == 0 then
imageString = imageString .. '\n'
imageString = imageString .. '\n'
end
end
imageString = imageString .. l
imageString = imageString .. l
end
end
elseif args.image then
local image = args.image
if image:match('(.*).png') or image:match('(.*).jpg') or image:match('(.*).svg') then imageString = '[[File:' .. image .. '|' .. imageSize  .. ']]'
else
imageString = '[[File:' .. image .. '.png|' .. imageSize .. ']]'
end
else
imageString = ''
end
end
local html = {
local html = {
'<div style="margin: auto; padding: 4px;  border-color: #382b1e; border-width: 3px; border-style: solid; {{#if: {{{align|}}}|{{{align}}}|float:right}}; margin: auto; width: 250px; border-radius: 4px; background-color: #e0cfbb;">',
'<div style="margin: 0 1em 1em; padding: 4px;  border-color: #382b1e; border-width: 3px; border-style: solid; {{#if: {{{align|}}}|{{{align}}}|float:right}}; width:' .. width .. '; border-radius: 4px; background-color: #e0cfbb;">',
'<table style="border-spacing: 2px; width: 100%;">',
'<table style="border-spacing: 2px; width: 100%;">',
'<tr><th colspan="2" style="background: rgb(91,76,62); background: linear-gradient(to bottom, rgba(91,76,62,1) 0px, rgba(91,76,62,0) 5px, rgba(56,43,30,0) calc(100% - 5px), rgba(56,43,30,1) 100%), linear-gradient(to right, rgba(91,76,62,1) 0px, rgba(69,52,36,1) 5px, rgba(69,52,36,1) 50%, rgba(69,52,36,1) calc(100% - 5px), rgba(56,43,30,1) 100%);}}">',
'<tr><th colspan="2" style="background: rgb(91,76,62); background: linear-gradient(to bottom, rgba(91,76,62,1) 0px, rgba(91,76,62,0) 5px, rgba(56,43,30,0) calc(100% - 5px), rgba(56,43,30,1) 100%), linear-gradient(to right, rgba(91,76,62,1) 0px, rgba(69,52,36,1) 5px, rgba(69,52,36,1) 50%, rgba(69,52,36,1) calc(100% - 5px), rgba(56,43,30,1) 100%);}}">',
'<big><b><span style="color: #e0cfbb">' .. title .. '</span></b></big></th></tr>',
'<big><b><span style="color: #e0cfbb">' .. title .. '</span></b></big></th></tr>',
'<tr><td colspan="2" style="margin:auto; text-align:center;">' .. imageString .. '</td></tr>',
'<tr><td colspan="2" style="margin:auto; text-align:center;">'.. subtitle .. imageString .. '</td></tr>',
args.rows,
args.rows,
'</table>',
'</table>',

Latest revision as of 18:59, 31 August 2022

Documentation for this module may be created at Module:Infobox/doc

local p = {}
function p.infobox( f )
	local args = require( 'Module:ProcessArgs' ).merge( true )
	local width = args.width or '250px'
	local titleObject = mw.title.getCurrentTitle()
	local title = args.title or titleObject.baseText
	local subtitle = ''
	if args.subtitle then
		 subtitle = '<span style="font-size:15px"><b><i>"' .. args.subtitle .. '"</i></b></span>'
	end
	local imageSize = args.imagesize or '180px'
	local imageString
	local images = {}
	if args.images then
		imageString = ''
		for image in mw.text.gsplit( args.images, '%s*;%s*' ) do
			if image:match('(.*).png') or image:match('(.*).jpg') or image:match('(.*).svg') then table.insert(images, '<span>[[File:' .. image .. '|64px]]</span>') 
			else
				table.insert(images, '<span>[[File:' .. image .. '.png|64px]]</span>')
			end
		end
		for i, l in pairs(images) do
			if not i == 0 and i % 3 == 0 then
				imageString = imageString .. '\n'
			end
			imageString = imageString .. l
		end
	elseif args.image then
		local image = args.image
		if image:match('(.*).png') or image:match('(.*).jpg') or image:match('(.*).svg') then imageString = '[[File:' .. image .. '|' .. imageSize  .. ']]'
		else
			imageString = '[[File:' .. image .. '.png|' .. imageSize .. ']]'
		end
	else
		imageString = ''
	end
	
	local html = {
		'<div style="margin: 0 1em 1em; padding: 4px;  border-color: #382b1e; border-width: 3px; border-style: solid; {{#if: {{{align|}}}|{{{align}}}|float:right}}; width:' .. width .. '; border-radius: 4px; background-color: #e0cfbb;">',
			'<table style="border-spacing: 2px; width: 100%;">',
				'<tr><th colspan="2" style="background: rgb(91,76,62); background: linear-gradient(to bottom, rgba(91,76,62,1) 0px, rgba(91,76,62,0) 5px, rgba(56,43,30,0) calc(100% - 5px), rgba(56,43,30,1) 100%), linear-gradient(to right, rgba(91,76,62,1) 0px, rgba(69,52,36,1) 5px, rgba(69,52,36,1) 50%, rgba(69,52,36,1) calc(100% - 5px), rgba(56,43,30,1) 100%);}}">',
					'<big><b><span style="color: #e0cfbb">' .. title .. '</span></b></big></th></tr>',
				'<tr><td colspan="2" style="margin:auto; text-align:center;">'.. subtitle .. imageString .. '</td></tr>',
				args.rows,
			'</table>',
		'</div>'
	}
	
	return table.concat( html, '\n' )
end

return p