Module talk:Icon

From Terra Invicta Official Wiki
Revision as of 07:45, 8 December 2025 by Llamageddon (talk | contribs) (Posting my lua attempt for review instead of breaking things)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Updating template:icon to use wikitext image syntax

I wanted to make the icon template accept the size input without needing explicit use of 'size=' parameter. I also wanted to make sure it was compatible with all previous instances that used this syntax. Would the following alteration to the code work for that? I'm not optimistic that it can't be simplified, or that I haven't made any logical or syntactical mistakes...:

	local size = sizearg
	local bgcolor = frame.args['bgcolor']
	if not bgcolor or mw.text.trim(bgcolor) == '' then
		bgcolor = 'transparent'	
		local sizearg = frame.args[2]
	else
		local sizearg = frame.args[3]
	end
	
	if not size or mw.text.trim(size) == '' then
		size = '20px'	
	end
	if size == smatch '^size=' or smatch '^size =' then
		size = mw.text.trim(" ^.*= ")
	end
	
	local retstart = '<span style="background-color: ' .. bgcolor .. '; display: inline-block;">[[File:'
	local retmid = '|' .. size .. '|'
	local retend = ']]</span>'

Llamageddon (talk) 07:44, 8 December 2025 (UTC)