Module:XImg

From AEGIS
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:XImg/doc. Changes can be proposed in the talk page.
Function list
L 3 — XImg.main

local XImg = {}

function XImg.main(frame)
	local returnValue = ''
	
	local parentFrame = frame:getParent()
	local parentArgs = parentFrame.args
	
    if parentArgs.image == nil then
		return hatnote( mw.ustring.format(
				'A required field (%s) is missing!',
				'image'
			),
			{ icon = 'WikimediaUI-Error.svg', extraclasses = 'error' }
		)
    end
	
	local width = ''
	local frame = ''
	local rounded = ''
	local align = ''
	local title = ''
	
	if parentArgs.width ~= nil then
		width = mw.ustring.format(
			' style="width:%s"',
			parentArgs.width
			)
	end
	if parentArgs.frame ~= nil then
		if string.lower(parentArgs.frame) ~= 'no' then
			frame = ' frame'
		end
	end
	
	if parentArgs.rounded ~= nil then
		if string.lower(parentArgs.rounded) ~= 'no' then
			frame = ' rounded'
		end
	end
	
	if parentArgs.align ~= nil then
		if string.lower(parentArgs.align) == 'left' then
			align = ' alignleft'
		end
		if string.lower(parentArgs.align) == 'right' then
			align = ' alignright'
		end
		if string.lower(parentArgs.align) == 'center' then
			align = ' aligncenter'
		end
		if string.lower(parentArgs.align) == 'floatleft' then
			align = ' floatleft'
		end
		if string.lower(parentArgs.align) == 'floatright' then
			align = ' floatright'
		end
	end
	
	if parentArgs.title ~= nil then
		title = mw.ustring.format(
			'<div class="externalimage-title">%s</div>',
			parentArgs.title
			)
	end
	
	returnValue = mw.ustring.format(
		'<div class="externalimage-container%s%s%s"%s>%s%s</div>',
		frame,
		rounded,
		align,
		width,
		title,
		parentArgs.image
		)
	
	return returnValue
	
	
end

return XImg