GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing en.wikipedia.org — Module:ArgRest - Wikipedia
This is an auxiliary module intended to be invoked by templates; it permits templates to support an arbitrary set of parameters by repeating a block of wikitext multiple times. This module works with named as well as unnamed parameters, can handle multiple named parameters at the same time, and supports defaults, UsageIf you want to use this module in your template: take the block of wikitext that you want to be repeated for an arbitrary set of parameters, wrap it in
Afterwards, the module will "fill in" parameters with larger numbers than the ones originally given; i.e. in the above example, the module would allow the containing template to receive parameters
ExampleIf the (imaginary) template {{PlusMinusLoop}} has the following code: {{{plus1}}} - {{{minus1}}}{{#invoke:ArgRest|main|<nowiki> + {{{plus2}}} - {{{minus2|5}}}</nowiki>|plus2}} then {{PlusMinusLoop|plus1=0|minus1=1|plus2=1|minus2=2|plus3=3|plus5=21}} will yield Helpful templatesThere are a few templates that can used with this module to help it adapt to certain scenarios:
NoteBe wary when using ArgRest wrapped inside of an outer template; it hasn't quite been thoroughly tested in such scenarios, and should be watched carefully when it is used this way. LimitationsThis module currently suffers from a few limitations:
See alsoThe above documentation is transcluded from Module:ArgRest/doc. (edit | history) Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages. Subpages of this module.
local p = {} function p.main(frame) -- Undo sanitization: local code = frame.args[1] or '' if code:match'nowiki' then code = mw.text.unstripNoWiki(code) else error("<nowiki> missing from first parameter") end -- Angle brackets still remain santiized; unsanitize them local wikitext = code:gsub('<', '<'):gsub('>', '>') local secondParam = frame.args[2] local start = tonumber(secondParam:match('%d+')) -- Extract the first number from the second parameter local result = '' assert(secondParam, "second parameter missing") local function replaceTripleBraces(parameter, _, default, i) -- extract corresponding arguments from the parent function. the _ is necessary because the pipe still gets caught in the second capture group if _ == "" then default = nil end -- mildly ugly hack for checking for {{{parameter|}}} return frame:getParent().args[parameter:gsub("%d+", tostring(i))] or default or "{{{" .. parameter .. "}}}" end for i = start, math.huge do -- Check if the parameter is defined if not frame:getParent().args[secondParam:gsub('%d+', tostring(i))] then break end local processed = wikitext:gsub("{{{([^{}<>|]+)(|?)([^{}|]*)}}}", function(a, b, c) return replaceTripleBraces(a, b, c, i) end) -- Find stuff of the form {{{parameter}}} or {{{parameter|default}}} via pattern matching result = result .. processed end return frame:preprocess(result) end return p | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |