Module:Side box/sandbox
Appearance
From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Side box (diff).
See also the companion subpage for test cases (run).
See also the companion subpage for test cases (run).
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Warning This Lua module is used on approximately 1,260,000 pages, or roughly 2% of all pages .
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
This module implements the {{side box }} template.
Usage from wikitext
[edit ]This module cannot be used directly from wikitext. It can only be used through the {{side box }} template. Please see the template page for documentation.
Usage from Lua modules
[edit ]To use this module from other Lua modules, first load the module.
localmSideBox=require('Module:Side box')
You can then generate a side box using the _main function.
mSideBox._main(args)
The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{side box }} template documentation.
The above documentation is transcluded from Module:Side box/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Add categories to the /doc subpage. Subpages of this module.
localyesno=require('Module:Yesno') localp={} localfunctionmakeData(args) localdata={} -- Main table classes data.classes={} ifyesno(args.metadata)~=falsethen table.insert(data.classes,'metadata') end ifargs.positionandargs.position:lower()=='left'then table.insert(data.classes,'side-box-left') else table.insert(data.classes,'side-box-right') end ifargs.collapsiblethen table.insert(data.classes,'mw-collapsible') ifargs.collapsible=="collapsed"then table.insert(data.classes,'mw-collapsed') end data.collapsible=true end table.insert(data.classes,args.class) -- Image ifargs.imageandargs.image~='none'then data.image=args.image end -- we have to check to see if a downstream use has plainlist like -- Template:Sister_project. also it's the default. wikitext is :( ifargs.textclass=='plainlist'ornotargs.textclassthen data.textclass='plainlist' data.plainlist_templatestyles='Plainlist/styles.css' else data.textclass=args.textclass end -- Copy over data that does not need adjusting localargsToCopy={ -- aria qualities 'role', 'labelledby', -- Styles 'style', 'textstyle', 'templatestyles', -- Above row 'above', 'abovestyle', -- Body row 'text', 'imageright', -- Below row 'below', } fori,keyinipairs(argsToCopy)do data[key]=args[key] end returndata end localfunctionrenderSidebox(data) -- Renders the sidebox HTML. -- Table root localroot=mw.html.create('div') root:attr('role',data.role) :attr('aria-labelledby',data.labelledby) :addClass('side-box') fori,classinipairs(data.classesor{})do root:addClass(class) end ifdata.stylethen root:cssText(data.style) end localframe=mw.getCurrentFrame() ifdata.plainlist_templatestylesthen root:wikitext(frame:extensionTag{ name='templatestyles',args={src=data.plainlist_templatestyles} }) end -- The "above" row ifdata.abovethen localabove=root:newline():tag('div') above:addClass('side-box-abovebelow') :newline() :wikitext(data.above) ifdata.textstylethen above:cssText(data.textstyle) end ifdata.abovestylethen above:cssText(data.abovestyle) end end -- The body row localbody=root:newline():tag('div') body:addClass('side-box-flex') :addClass(data.collapsibleand'mw-collapsible-content') :newline() ifdata.imagethen body:tag('div') :addClass('side-box-image') :wikitext(data.image) end localtext=body:newline():tag('div') text:addClass('side-box-text') :addClass(data.textclass) ifdata.textstylethen text:cssText(data.textstyle) end text:wikitext(data.text) ifdata.imagerightthen body:newline():tag('div') :addClass('side-box-imageright') :wikitext(data.imageright) end -- The below row ifdata.belowthen localbelow=root:newline():tag('div') below :addClass('side-box-abovebelow') :wikitext(data.below) ifdata.textstylethen below:cssText(data.textstyle) end end root:newline() localtemplatestyles='' ifdata.templatestylesthen templatestyles=frame:extensionTag{ name='templatestyles',args={src=data.templatestyles} } end returnframe:extensionTag{ name='templatestyles',args={src='Module:Side box/styles.css'} }..templatestyles..tostring(root) end functionp._main(args) localdata=makeData(args) returnrenderSidebox(data) end functionp.main(frame) localorigArgs=frame:getParent().args localargs={} fork,vinpairs(origArgs)do v=v:match('%s*(.-)%s*$') ifv~=''then args[k]=v end end returnp._main(args) end returnp