Module talk:Icon: Difference between revisions

From Terra Invicta Official Wiki
Llamageddon (talk | contribs)
Posting my lua attempt for review instead of breaking things
 
Llamageddon (talk | contribs)
mNo edit summary
Line 23: Line 23:


[[User:76561197970425841|76561197970425841]] ([[User talk:76561197970425841|talk]]) 07:44, 8 December 2025 (UTC)
[[User:76561197970425841|76561197970425841]] ([[User talk:76561197970425841|talk]]) 07:44, 8 December 2025 (UTC)
: After testing with the bodyIcon template, it seems that the final if argument is redundant as <code>mw.text.trim(size)</code> just works. I thought the '=' would cause problems if left in... [[User:76561197970425841|76561197970425841]] ([[User talk:76561197970425841|talk]]) 08:09, 8 December 2025 (UTC)

Revision as of 08:09, 8 December 2025

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)

After testing with the bodyIcon template, it seems that the final if argument is redundant as mw.text.trim(size) just works. I thought the '=' would cause problems if left in... Llamageddon (talk) 08:09, 8 December 2025 (UTC)