Jump to content
Wikipedia The Free Encyclopedia

Module:110521sgl

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]

Usage

[edit ]

{{#invoke:110521sgl|main}}

This module works the same way as Module:Babel, with the sole difference being that Babel accepts arguments x such that "User x" is the name of a template, while this module can take any template name as argument. It offers the versatility seen in Template:Babel-N without sacrificing the nice table formatting Template:Babel provides. It's corresponding template is User:110521sgl/UserlessBabel.

The above documentation is transcluded from Module:110521sgl/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.

 --[[
 The 110521sgl module, Based on the Babel module.
 This module is meant to emulate the effect of the Babel-N template as a module
 directly, so userbox templates whose names don't start with "User" can be used
 in Babel-like tables (unlike with the Babel module), without sacrificing the
 nice formatting that the Babel template provides (which Babel-N fails in).
 The corresponding template is User:110521sgl/UserlessBabel.
 ]]--

 localp={}

 localgetArgs

 localfunctionshowBox(frame,v,nocat)
 localmaybeNocat=''
 ifnocatthen
 maybeNocat='|nocat=yes'
 end
 returnframe:preprocess('{{'..v..maybeNocat..'}}')
 end

 functionp.main(frame)
 ifnotgetArgsthen
 getArgs=require('Module:Arguments').getArgs
 end
 localargs=getArgs(frame,{wrappers='User:110521sgl/UserlessBabel'})

 localret=mw.html.create('table')
 :attr('role','presentation')
 :addClass('userboxes')
 :css({
 float=args.alignor'right',
 ['margin-left']=(args.leftor'1')..'em',
 ['margin-bottom']=(args.bottomor'0')..'em',
 width=(args.widthor'248')..'px',
 clear=args.alignor'right',
 color=args.textcoloror'#000000',
 border=(args.bordercoloror'#99B3FF')..' solid '..(args.solidor1)..'px'
 })

 localnocat=args.nocatandstring.lower(args.nocat)=='yes'

 ifargs.shadowandstring.lower(args.shadow)=='yes'then
 ret:css({['box-shadow']='0 2px 4px rgb(0,0,0,0.2)'})
 end

 ret:cssText(args['extra-css']or'')

 localcolor=args.coloror'inherit'
 localrow1=ret:tag('tr')
 localrow2=ret:tag('tr')
 localrow3=ret:tag('tr')

 localbody_cells=row2:tag('td')
 :css('vertical-align','middle !important')

 localuserboxes
 -- Special message for when first argument is blank; otherwise treat it as normal
 ifargs[1]andargs[1]:find('%S')then
 userboxes=showBox(frame,args[1],nocat)
 else
 userboxes=args.noboxestextor"''You haven't set up any languages. Please see [[Template:Babel/doc]] for help.''"
 end

 body_cells:wikitext(userboxes)

 -- "remove" args[1] so it isn't looked at in the loop
 -- table.remove(args,1) doesn't produce desired result
 args[1]=''

 -- Keep track of how many columns are in this table
 localcol_span=1
 for_,vinipairs(args)do
 -- ! indicates a new cell should be created
 ifv:find('%S')andv~='!'then
 body_cells:wikitext(showBox(frame,v,nocat))
 -- Recycling body_cells for <td>
 elseifvandv=='!'then
 col_span=col_span+1
 body_cells:done()
 body_cells=row2:tag('td')
 end
 end

 row1:tag('th')
 :css({['background-color']=color,
 ['text-align']='center'})
 :attr('colspan',col_span)
 :wikitext(args.headeror'[[Wikipedia:Babel]]')
 :done()

 row3:tag('td')
 :css({['background-color']=color,
 ['text-align']='center'})
 :attr('colspan',col_span)
 :wikitext(args.footeror'[[:Category:Wikipedians by language|Search user languages]]')
 :done()

 ifargs['special-boxes']then
 body_cells:wikitext(args['special-boxes'])
 end

 body_cells:done()

 returntostring(ret)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /