Movatterモバイル変換


[0]ホーム

URL:


Jump to content
Wikimedia Meta-Wiki
Search

Module:Unsubst

Permanently protected module
From Meta, a Wikimedia project coordination wiki
Module documentation
You might want tocreate a documentation page for thisScribunto module.
Editors can experiment in this module’s sandbox(create |mirror) and testcases(create) pages.
Please add categories to the/doc subpage.Subpages of this module.
localcheckType=require('libraryUtil').checkTypelocalp={}localBODY_PARAM='$B'localspecialParams={['$params']='parameter list',['$aliases']='parameter aliases',['$flags']='flags',['$B']='template content'}functionp.main(frame,body)-- If we are substing, this function returns a template invocation, and if-- not, it returns the template body. The template body can be specified in-- the body parameter, or in the template parameter defined in the-- BODY_PARAM variable. This function can be called from Lua or from-- #invoke.-- Return the template body if we aren't substing.ifnotmw.isSubsting()thenifbody~=nilthenreturnbodyelseifframe.args[BODY_PARAM]~=nilthenreturnframe.args[BODY_PARAM]elseerror(string.format("no template content specified (use parameter '%s' from #invoke)",BODY_PARAM),2)endend-- Sanity check for the frame object.iftype(frame)~='table'ortype(frame.getParent)~='function'ornotframe:getParent()thenerror("argument #1 to 'main' must be a frame object with a parent ".."frame available",2)end-- Find the invocation name.localmTemplateInvocation=require('Module:Template invocation')localname=mTemplateInvocation.name(frame:getParent():getTitle())-- Combine passed args with passed defaultslocalargs={}ifstring.find(','..(frame.args['$flags']or'')..',',',%s*override%s*,')thenfork,vinpairs(frame:getParent().args)doargs[k]=vendfork,vinpairs(frame.args)doifnotspecialParams[k]thenifv=='__DATE__'thenv=mw.getContentLanguage():formatDate('F Y')endargs[k]=vendendelsefork,vinpairs(frame.args)doifnotspecialParams[k]thenifv=='__DATE__'thenv=mw.getContentLanguage():formatDate('F Y')endargs[k]=vendendfork,vinpairs(frame:getParent().args)doargs[k]=vendend-- Trim parameters, if not specified otherwiseifnotstring.find(','..(frame.args['$flags']or'')..',',',%s*keep%-whitespace%s*,')thenfork,vinpairs(args)doargs[k]=mw.ustring.match(v,'^%s*(.*)%s*$')or''endend-- Pull information from parameter aliaseslocalaliases={}ifframe.args['$aliases']thenlocallist=mw.text.split(frame.args['$aliases'],'%s*,%s*')fork,vinipairs(list)dolocaltmp=mw.text.split(v,'%s*>%s*')aliases[tonumber(mw.ustring.match(tmp[1],'^[1-9][0-9]*$'))ortmp[1]]=((tonumber(mw.ustring.match(tmp[2],'^[1-9][0-9]*$')))ortmp[2])endendfork,vinpairs(aliases)doifargs[k]and(notargs[v]orargs[v]=='')thenargs[v]=args[k]endargs[k]=nilend-- Remove empty parameters, if specifiedifstring.find(','..(frame.args['$flags']or'')..',',',%s*remove%-empty%s*,')thenlocaltmp=0fork,vinipairs(args)doifv~=''or(args[k+1]andargs[k+1]~='')or(args[k+2]andargs[k+2]~='')thentmp=kelsebreakendendfork,vinpairs(args)doifv==''thenifnot(type(k)=='number'andk<tmp)thenargs[k]=nilendendendend-- Order parametersifframe.args['$params']thenlocalparams,tmp=mw.text.split(frame.args['$params'],'%s*,%s*'),{}fork,vinipairs(params)dov=tonumber(mw.ustring.match(v,'^[1-9][0-9]*$'))orvifargs[v]thentmp[v],args[v]=args[v],nilendendfork,vinpairs(args)dotmp[k],args[k]=args[k],nilendargs=tmpendreturnmTemplateInvocation.invocation(name,args)endp['']=p.main-- For backwards compatibilityreturnp
Retrieved from "https://meta.wikimedia.org/w/index.php?title=Module:Unsubst&oldid=29398854"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp