Module:TSLoader: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 12: Line 12:
if not static.TSLoader.loadedTS then
if not static.TSLoader.loadedTS then
static.TSLoader.loadedTS = {}
static.TSLoader.loadedTS = {}
end
local pagename = mw.title.getCurrentTitle()
if not static.TSLoader.loadedTS[ pagename ] then
static.TSLoader.loadedTS[ pagename ] = {}
end
end
if not name:find( '^%w*:' ) then
if not name:find( '^%w*:' ) then
Line 17: Line 21:
end
end
name = name:sub( 1, 1 ):upper() .. name:sub( 2 )
name = name:sub( 1, 1 ):upper() .. name:sub( 2 )
if static.TSLoader.loadedTS[ name ] == true then
if static.TSLoader.loadedTS[ pagename ][ name ] == true then
return ''
return ''
end
end
static.TSLoader.loadedTS[ name ] = true
static.TSLoader.loadedTS[ pagename ][ name ] = true
return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = name } }
return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = name } }
end
end

Revision as of 14:57, 16 May 2024

This module implements {{TSLoader}}.

When invoked from a module, please use p.call( name ), where name represents the page name of template styles you want to load, if under Template: namespace, the prefix can be omitted.

Dependencies

lzh:Module:TSLoader pt:Módulo:TSLoader ru:Модуль:TemplateStyles zh:Module:TSLoader


local p = {}

local static = require( 'Module:Static' )
if not static.TSLoader then
	static.TSLoader = {}
end

function p.call( name )
	if not name then
		return nil
	end
	if not static.TSLoader.loadedTS then
		static.TSLoader.loadedTS = {}
	end
	local pagename = mw.title.getCurrentTitle()
	if not static.TSLoader.loadedTS[ pagename ] then
		static.TSLoader.loadedTS[ pagename ] = {}
	end
	if not name:find( '^%w*:' ) then
		name = 'Template:' .. name:sub( 1, 1 ):upper() .. name:sub( 2 )
	end
	name = name:sub( 1, 1 ):upper() .. name:sub( 2 )
	if static.TSLoader.loadedTS[ pagename ][ name ] == true then
		return ''
	end
	static.TSLoader.loadedTS[ pagename ][ name ] = true
	return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = name } }
end

function p.main( f )
	local args = f
	local frame = mw.getCurrentFrame()
	if f == frame then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	return p.call( args[ 1 ] )
end

return p