Note: in order to make the test cases work, the Sandbox CSS classes have "-sand" appended to their names. If you wish to update the CSS, copy the contents of each class from Module:Portal bar/sandbox/styles.css to Module:Portal bar/styles.css, but do not alter the class names, nor just copy-paste the entire CSS file. For the current difference in CSS between Sandbox and Main, see here.
-- This module implements {{portal bar}}.require('strict')-- determine whether we're being called from a sandboxlocalisSandbox=mw.getCurrentFrame():getTitle():find('sandbox',1,true)localsandbox=isSandboxand'/sandbox'or''localportalModule=require('Module:Portal'..sandbox)localgetImageName=portalModule._imagelocalcheckPortals=portalModule._checkPortalslocalprocessPortalArgs=portalModule._processPortalArgslocalyesno=require('Module:Yesno')localgetArgs=require('Module:Arguments').getArgslocalp={}localfunctionsandboxVersion(s)returnisSandboxands.."-sand"orsend-- Builds the portal bar used by {{portal bar}}.functionp._main(portals,args)-- check for sensible argsargs=type(args)=="table"andargsor{}-- Normalize argumentsforkey,defaultinpairs({border=true,redlinks=false,tracking=true})doifargs[key]==nilthenargs[key]=defaultendargs[key]=yesno(args[key],default)endlocalnav=mw.html.create('div'):addClass(sandboxVersion('portal-bar')):addClass('noprint metadata noviewer'):attr('role','navigation'):attr('aria-label','Portals'):addClass(sandboxVersion(args.borderand'portal-bar-bordered'or'portal-bar-unbordered'))localtrackingCat=''-- Allow any number of portalsargs.minPortals=0args.maxPortals=-1-- Check to see whether there are redlinks, filter out unless args.redlink is trueportals,trackingCat=checkPortals(portals,args)nav:wikitext(trackingCat)if#portals==0thenreturntrackingCatendlocalrelated=yesno(args.related)ifrelatedthennav:addClass(sandboxVersion('portal-bar-related'))elselocalheader=nav:tag('span')header:addClass(sandboxVersion('portal-bar-header'))header:wikitext('[[Wikipedia:Contents/Portals|Portal]]')if#portals>1thenheader:wikitext('s')endheader:wikitext(':')endlocalcontainer=nav:tag('ul')container:addClass(sandboxVersion('portal-bar-content'))ifrelatedthencontainer:addClass(sandboxVersion('portal-bar-content-related'))endlocalsize=relatedand'27x25px'or'21x19px'for_,portalinipairs(portals)docontainer:tag('li'):addClass(sandboxVersion('portal-bar-item')):wikitext(string.format('<span class="nowrap">[[File:%s|%s]] </span>[[Portal:%s|%s]]',getImageName(portal,true),size,portal,portal))endlocalstyleFile='Module:Portal bar'..sandbox..'/styles.css'returnmw.getCurrentFrame():extensionTag{name='templatestyles',args={src=styleFile}}..tostring(nav)end-- Processes external arguments and sends them to the other functions.functionp.main(frame)localorigArgs=getArgs(frame)localportals,args=processPortalArgs(origArgs)returnp._main(portals,args)endreturnp