Difference between revisions of "Module:Infobox"

From Foundation - Wiki
Jump to navigation Jump to search
(Created page with "local com = require('Module:Common') local a = require('Module:Arguments') local p = {} local function mainBox(title) local result = mw.html.create('div') result:addClass('infobox') :tag('div') :class('infobox-title') :wikitext(com.modulePagename(title)) :done() return result end local function infoboxImage(image, defaultImage, caption, defaultCaption) local result = mw.html.create('div') result:addClass('infobox-image') if image or defaultImage then...")
 
Line 18: Line 18:
if image or defaultImage then
if image or defaultImage then
local file = '%[%File:'
local file = '%[%[File:'
if image then
if image then
file = file .. image
file = file .. image

Revision as of 17:20, 11 August 2022

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

local com = require('Module:Common')
local a = require('Module:Arguments')
local p = {}

local function mainBox(title)
	local result = mw.html.create('div')
	result:addClass('infobox')
		:tag('div')
		:class('infobox-title')
		:wikitext(com.modulePagename(title))
		:done()
	return result
end

local function infoboxImage(image, defaultImage, caption, defaultCaption)
	local result = mw.html.create('div')
	result:addClass('infobox-image')
	
	if image or defaultImage then
		local file = '%[%[File:'
		if image then
			file = file .. image
		else
			file = file .. defaultImage
		end
		
		file = file .. '|260px|frameless%]%]'
		local fileCaption = mw.html.create('span')
		
		if caption or defaultCaption then
			fileCaption:addClass('infoboxCaption')
				:wikitext(caption or defaultCaption)
		end
		
		result:wikitext(file)
			:node(fileCaption)
	else
		result = '[[Category:Image Needed]]'
	end
	
	return result
end

local function infoboxGroup(data, rows)
	local result
	if data then
		if rows then
			rows = 'data-rows-' .. rows
		end
		local result = mw.html.create('div')
		result:addClass('infobox-header')
			:tag('div')
				:addClass('infobox-row ' .. rows)
				:node(data)
	end
	
	return result
end

local function infoboxData(data, label, default)
	local result
	if data or default then
		result = mw.html.create('div')	
			:addClass('infobox-data-section')
		if label then
			result:tag('label')
				:addClass('infobox-label')
				:wikitext(label)
				:done()
			:tag('span')
				:addClass('infobox-data')
				:wikitext(data or default)
		end
	end
	return result
end

return p