Module:Fairycode

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 12:30, 15 October 2024 (Created page with "local p = {} -- {{Fairycode}} entrance function p.code(frame) local args = frame:getParent().args mw.logObject(args) local code = args[1] return p._code(code) end -- Module entrance function p._code(code) assert(code, 'No fairycode provided') local first = string.upper( string.sub(code, 1, 1) ) local second = string.upper( string.sub(code, 2, 2) ) local third = string.upper( string.sub(code, 3, 3) ) if first == '' or second == '' or third == '' then er..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Fairycode/doc. [edit] [history] [purge]
Module:Fairycode's function code is invoked by Template:Fairycode.

Implements {{Fairycode}}.


local p = {}

-- {{Fairycode}} entrance
function p.code(frame)
	local args = frame:getParent().args
	
	mw.logObject(args)
	local code = args[1]
	
	return p._code(code)
end

-- Module entrance
function p._code(code)
	assert(code, 'No fairycode provided')
	
	local first = string.upper( string.sub(code, 1, 1) )
	local second = string.upper( string.sub(code, 2, 2) )
	local third = string.upper( string.sub(code, 3, 3) )
	
	if first == '' or second == '' or third == '' then error('Missing one or more code letters') end
	
	local formattedCode = string.format('<span class="fairycode"><b>%s</b><b>%s</b><b>%s</b></span>', first, second, third)
	
	return formattedCode
end

return p