Module:Navpills

From Seven Sages of Rome
Revision as of 15:03, 6 August 2024 by Noeth (talk | contribs) (Created page with "local mArguments --initialize lazily local getArgNums = require('Module:Common').getArgNums local p = {} --Implements {{Navpills}} from the frame function p.navpills( frame ) mArguments = require( 'Module:Arguments' ) return p._navpills( mArguments.getArgs( frame ) ) end function p._navpills( args ) if not args then return 'Missing arguments' end local html = mw.html.create( 'div' ):addClass( 'template-navpills' ):attr( 'role', 'navigation' ) for i, _ in i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Navpills/doc

local mArguments --initialize lazily
local getArgNums = require('Module:Common').getArgNums
local p = {}


--Implements {{Navpills}} from the frame
function p.navpills( frame )
	mArguments = require( 'Module:Arguments' )
	return p._navpills( mArguments.getArgs( frame ) )
end


function p._navpills( args )
	if not args then
		return 'Missing arguments'
	end

	local html = mw.html.create( 'div' ):addClass( 'template-navpills' ):attr( 'role', 'navigation' )
	
	for i, _ in ipairs( getArgNums( 'page', args ) ) do
		if not args[ 'page' .. i ] then return end
		local num = tostring( i )
		local navpill = mw.html.create('div'):addClass('template-navpill')

		if args[ 'image' .. i ] then
			navpill:tag('div'):addClass('template-navpill-background')
				:wikitext( string.format( '[[File:%s|x48px|link=]]', args[ 'image' .. num ] ) )
		end

		navpill:wikitext( string.format( '[[%s|%s]]', args[ 'page' .. num ], args[ 'text' .. num ] or args[ 'page' .. num ] ) )
		html:node(navpill)
	end

	return mw.getCurrentFrame():extensionTag{
		name = 'templatestyles', args = { src = 'Module:Navpills/styles.css' }
	} .. tostring( html )
end

return p