https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ATemplateDataGenerator
Module:TemplateDataGenerator - Revision history
2025-05-26T01:48:03Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.2
https://en.wikipedia.org/w/index.php?title=Module:TemplateDataGenerator&diff=567535625&oldid=prev
Salix alba: don't really want to wrap the result in <pre>, better translation of parameters for getBlock
2013-08-07T13:06:24Z
<p>don't really want to wrap the result in <pre>, better translation of parameters for getBlock</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:06, 7 August 2013</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 134:</td>
<td colspan="2" class="diff-lineno">Line 134:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local p = {};</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local p = {};</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>function p.getBlock( <del style="font-weight: bold; text-decoration: none;">about</del>, <del style="font-weight: bold; text-decoration: none;">ahead</del>, alphabetical )</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>function p.getBlock( <ins style="font-weight: bold; text-decoration: none;">pagetitle</ins>, <ins style="font-weight: bold; text-decoration: none;">namespace</ins>, alphabetical )</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- Precondition:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- Precondition:</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> -- <del style="font-weight: bold; text-decoration: none;">about </del> -- string; page title related to template code</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> -- <ins style="font-weight: bold; text-decoration: none;">pagetitle</ins> -- string; page title related to template code</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> -- <del style="font-weight: bold; text-decoration: none;">ahead </del> -- string, number or nil; namespace (Template:)</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> -- <ins style="font-weight: bold; text-decoration: none;">namespace</ins> -- string, number or nil; namespace (Template:)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- alphabetical -- boolean or nil; sort parameter list</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- alphabetical -- boolean or nil; sort parameter list</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- Uses:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- Uses:</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- fun()</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- fun()</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> local title = mw.title.makeTitle( <del style="font-weight: bold; text-decoration: none;">ahead</del> or 10, <del style="font-weight: bold; text-decoration: none;">about</del> );</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local title = mw.title.makeTitle( <ins style="font-weight: bold; text-decoration: none;">namespace</ins> or 10, <ins style="font-weight: bold; text-decoration: none;">pagetitle</ins> );</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local lucky, r = pcall( fun, title, alphabetical );</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local lucky, r = pcall( fun, title, alphabetical );</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return r;</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return r;</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 161:</td>
<td colspan="2" class="diff-lineno">Line 161:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> return "<pre>" .. r .. "</pre>";</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;"> --</ins> return "<pre>" .. r .. "</pre>";</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> return r;</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end -- .f()</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>end -- .f()</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
</table>
Salix alba
https://en.wikipedia.org/w/index.php?title=Module:TemplateDataGenerator&diff=567291380&oldid=prev
PerfektesChaos: Created from w:de:Module:Vorlage:TemplateDataGenerator
2013-08-05T18:16:28Z
<p>Created from <a href="https://de.wikipedia.org/wiki/Module:Vorlage:TemplateDataGenerator" class="extiw" title="de:Module:Vorlage:TemplateDataGenerator">w:de:Module:Vorlage:TemplateDataGenerator</a></p>
<p><b>New page</b></p><div>--[=[ 2013-08-05<br />
{{TemplateDataGenerator}}<br />
Basic idea by [[w:en:User:Salix alba]]<br />
]=]<br />
<br />
<br />
<br />
local config = {<br />
luxury = false, -- default alphabetical order for parameter list<br />
start = false, -- preceeding lines<br />
shift = " ", -- (not used now) indentation, like " " or "\t"<br />
suffix = false, -- following lines<br />
scheme = [=["%s":<br />
{ "label": "%s",<br />
"description": "",<br />
"type": "string",<br />
"required": false<br />
}]=]<br />
-- config.scheme has placeholders %s<br />
-- for the parameter name and for "label".<br />
-- One of various indentation styles.<br />
-- Feel free to compose a different one, also using config.shift etc.<br />
};<br />
<br />
<br />
<br />
local function factory( analyze, alphabetical )<br />
-- Make parameter sequence from template source text<br />
-- analyze -- string; template source text<br />
-- alphabetical -- boolean or nil; sort parameter list<br />
-- Return:<br />
-- table (sequence) with parameter names<br />
local i, s;<br />
local r = { };<br />
for s in analyze:gmatch( "{{{([^|}\n]+)" ) do<br />
for i = 1, #r do<br />
if r[ i ] == s then<br />
s = false;<br />
break; -- for i<br />
end<br />
end -- for i<br />
if s then<br />
table.insert( r, s );<br />
end<br />
end -- for s in :gmatch()<br />
if alphabetical then<br />
table.sort( r, nil );<br />
end<br />
return r;<br />
end -- factory()<br />
<br />
<br />
<br />
local function format( analyze, alphabetical )<br />
-- Make JSON code from template source text<br />
-- analyze -- string; template source text<br />
-- alphabetical -- boolean or nil; sort parameter list<br />
-- Return:<br />
-- string with JSON code<br />
-- Uses:<br />
-- > config.shift<br />
-- > config.scheme<br />
-- factory()<br />
local i;<br />
local params = factory( analyze, alphabetical );<br />
local r = '{ "description": "",\n';<br />
-- local shift = config.shift or ""; -- currently unused<br />
local start = " ";<br />
local show, symbol;<br />
r = r .. ' "params": { ';<br />
for i = 1, #params do<br />
if i > 1 then<br />
r = string.format( "%s,\n%s ", r, start );<br />
end<br />
symbol = params[ i ];<br />
if mw.ustring.match( symbol, "^%u%u" ) then<br />
show = mw.ustring.sub( symbol, 1, 1 ) ..<br />
mw.ustring.lower( mw.ustring.sub( symbol, 2 ) );<br />
else<br />
show = "";<br />
end<br />
r = r .. string.format( config.scheme, symbol, show );<br />
-- common JSON pattern is ASCII; string.format() will do<br />
end -- for i<br />
r = string.format( "%s\n%s}\n}", r, start );<br />
return r;<br />
end -- format()<br />
<br />
<br />
<br />
local function fun( attempt, alphabetical )<br />
-- Retrieve used template params and build TemplateData skeleton<br />
-- Precondition:<br />
-- attempt -- mw.title object; related to template code<br />
-- alphabetical -- boolean or nil; sort parameter list<br />
-- Return:<br />
-- string to be applied<br />
-- Uses:<br />
-- > config.luxury<br />
-- > config.start<br />
-- > config.suffix<br />
-- format()<br />
local r;<br />
local source = string.match( attempt.baseText .. "/",<br />
"^([^/]+)/" );<br />
-- ensure top page in NS with no subpage property<br />
-- note that pattern is ASCII; string.match() will do<br />
local title = mw.title.makeTitle( attempt.namespace, source );<br />
if title.exists then<br />
local luxury = config.luxury;<br />
local spec = "%s<templatedata>\n%s\n</templatedata>\n%s";<br />
if type( alphabetical ) == "boolean" then<br />
luxury = alphabetical;<br />
end<br />
if config.start then<br />
r = config.start .. "\n";<br />
else<br />
r = "";<br />
end<br />
r = string.format( spec,<br />
r,<br />
format( title:getContent(), luxury ),<br />
config.suffix or "" );<br />
-- note that format spec is ASCII only; string.format() will do<br />
else -- test only<br />
r = "ERROR * no page " .. title.fullText;<br />
end<br />
return r;<br />
end -- fun()<br />
<br />
<br />
<br />
-- Export<br />
local p = {};<br />
<br />
function p.getBlock( about, ahead, alphabetical )<br />
-- Precondition:<br />
-- about -- string; page title related to template code<br />
-- ahead -- string, number or nil; namespace (Template:)<br />
-- alphabetical -- boolean or nil; sort parameter list<br />
-- Uses:<br />
-- fun()<br />
local title = mw.title.makeTitle( ahead or 10, about );<br />
local lucky, r = pcall( fun, title, alphabetical );<br />
return r;<br />
end -- .getBlock()<br />
<br />
<br />
<br />
function p.f( frame )<br />
-- Precondition:<br />
-- frame -- object<br />
-- Invoked on a template page or template subpage.<br />
-- Uses:<br />
-- fun()<br />
local luxury;<br />
local parental = frame:getParent().args;<br />
local sort = parental[ 1 ] or parental[ "1" ] or parental.sort;<br />
if sort then<br />
luxury = ( tonumber( sort) == 1 );<br />
end<br />
local lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );<br />
return "<pre>" .. r .. "</pre>";<br />
end -- .f()<br />
<br />
return p;</div>
PerfektesChaos