Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
--generates auto short description for use in infobox settlement localp={} p.categories="" localplain=require('Module:Plain text')._main localgetArgs=require('Module:Arguments').getArgs localtableTools=require('Module:TableTools') functionp.reverseTable(init) init[1],init[3]=init[3],init[1] returninit end functionp.assign(args,argname,num) localval localvar={} fori=0,numdo --handle initial "subdivision_foo" without number ifi==0then val="" else val=tostring(i) end var[i+1]=p.validate(plain(args[argname..val])) end returnvar end --Display short description using {{short description}} functionp.shortdesc(text,frame) returnframe:expandTemplate{title='Short description',args={text,'noreplace'}} end functionp.category(cattype) localcategory=string.format('[[Category:Pages using infobox settlement with bad %s]]',cattype) ifcategorythenp.categories=p.categories..categoryend--categorize end --sanity and other checks functionp.validate(parameter,cat) ifnotparameterthenreturnnilend parameter=parameter:gsub('%b()','')--remove things in brackets as extraneous information :gsub('%s+',' ')--fix possible extra spaces from previous cleanup :gsub('^%s+','')--trim spaces from beginning :gsub('%s+$','')--trim spaces from end ifparameter:match("[,;]")ornotparameter:match("%a")then--must have some letters, ignore if multiple types/subdivisions ifcatthenp.category(cat)end returnnil end if(parameter=="")thenreturnnilend returnparameter end --removes redundancy like "England, United Kingdom" and fixes issues like "Foo in United States" (to "Foo in the United States") --also used in Module:Type in location functionp.cleanupLoc(location) iflocation==""thenreturnnilend localreplacements={ ["England, United Kingdom"]="England", ["Scotland, United Kingdom"]="Scotland", ["Wales, United Kingdom"]="Wales", ["New York City, New York, United States"]="New York City", ["^United States$"]="the United States", ["London, United Kingdom"]="London", ["London, England"]="London" } fori,vinpairs(replacements)do location=location:gsub(i,v)--series of replacements end returnlocation end functionp.main(frame) localcategories="" localsubdivision_types={} localsubdivision_names={} localargs=getArgs(frame,{parentOnly=true}) localsettlement_type=p.validate(plain(args.settlement_typeorargs.type),"settlement type")or"Place" localshort_description=plain(args.short_description) subdivision_types=p.assign(args,"subdivision_type",2) subdivision_names=p.assign(args,"subdivision_name",2) ifshort_descriptionthen if(short_description=='no')then return else returnp.shortdesc(short_description,frame) end end ifnot(subdivision_names[3]and (string.find(settlement_type,'[nN]eighbo[u]?rhood')orstring.find(settlement_type,'[sS]uburb')))then subdivision_names[3]=nil--display the third subdivision_type only if suburb or neighborhood end --if say "Voivodeship" is found within the subdivision_type, then specially handle --by adding Voivodeship to the end if not already present forx,yinipairs(subdivision_types)do localspecial_types={ "Voivodeship" } fori,jinipairs(special_types)do ifsubdivision_names[x]andstring.find(y,j,1,true) andnotstring.find(subdivision_names[x],j,1,true)then subdivision_names[x]=subdivision_names[x].." "..j end end end forx,yinipairs(subdivision_names)do ifythen ifstring.find(settlement_type,y,1,true)then--if the subdivision is found within the settlement type subdivision_names[x]=nil--don't display redundancy p.category("settlement type") end ify==mw.title.getCurrentTitle().textthen--if the title is the same as one of the subdivision_names subdivision_names[x]=nil--don't display redundancy end end end locallocation=table.concat(tableTools.compressSparseArray(p.reverseTable(subdivision_names)),', ') location=p.cleanupLoc(location) iflocationthenlocation=" in "..locationelselocation=""end returnp.shortdesc(settlement_type..location,frame)..p.categories end returnp