Modul:TemplateData: Unterschied zwischen den Versionen
2017-03-27
wp>PerfektesChaos (2017-01-01) |
wp>PerfektesChaos (2017-03-27) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { | local TemplateData = { serial = "2017-03-27", | ||
suite = "TemplateData" } | |||
--[=[ | --[=[ | ||
improve template:TemplateData | improve template:TemplateData | ||
Zeile 123: | Zeile 123: | ||
local function facility( about ) | local function facility( about, asked ) | ||
-- Create description head | -- Create description head | ||
-- Parameter: | -- Parameter: | ||
-- about -- table, supposed to contain description | -- about -- table, supposed to contain description | ||
-- asked -- true, if mandatory description | |||
-- Returns <block>, with head, or nil | -- Returns <block>, with head, or nil | ||
local para = mw.html.create( "p" ) | local para = mw.html.create( "p" ) | ||
Zeile 147: | Zeile 148: | ||
end -- for k, v | end -- for k, v | ||
end | end | ||
elseif Config.solo then | elseif Config.solo and asked then | ||
para:addClass( "error" ) | para:addClass( "error" ) | ||
:wikitext( Config.solo ) | :wikitext( Config.solo ) | ||
Zeile 425: | Zeile 426: | ||
local ranking = { "required", "suggested", "optional", "deprecated" } | local ranking = { "required", "suggested", "optional", "deprecated" } | ||
local r = mw.html.create( "tr" ) | local r = mw.html.create( "tr" ) | ||
local sort | local sort, typed | ||
for k, v in pairs( param ) do | |||
if v == "" then | |||
param[ k ] = false | |||
end | |||
end -- for k, v | |||
-- label | -- label | ||
sort = param.label or access | |||
if sort:match( "^%d+$" ) then | if sort:match( "^%d+$" ) then | ||
begin:attr( "data-sort-value", | begin:attr( "data-sort-value", | ||
Zeile 501: | Zeile 508: | ||
-- type | -- type | ||
if | if param.type then | ||
s = Permit.types[ | s = Permit.types[ param.type ] | ||
typed = mw.html.create( "td" ) | typed = mw.html.create( "td" ) | ||
if s then | if s then | ||
Zeile 707: | Zeile 714: | ||
local function flush() | local function flush() | ||
-- JSON encode narrowed input; obey unnamed (numerical) parameters | -- JSON encode narrowed input; obey unnamed (numerical) parameters | ||
-- Returns <templatedata> JSON string | |||
local r | local r | ||
if Data.tag then | if Data.tag then | ||
Zeile 774: | Zeile 782: | ||
if s == "string" then | if s == "string" then | ||
v = mw.text.trim( v ) | v = mw.text.trim( v ) | ||
end | end | ||
if scope:find( s, 1, true ) then | if scope:find( s, 1, true ) then | ||
Zeile 839: | Zeile 844: | ||
tag[ k ] = v | tag[ k ] = v | ||
end | end | ||
else | |||
s = string.format( "Type <code>%s</code> bad for %s", | s = string.format( "Type <code>%s</code> bad for %s", | ||
scope, f( k, slot ) ) | scope, f( k, slot ) ) | ||
Zeile 859: | Zeile 864: | ||
-- Returns <div> | -- Returns <div> | ||
local r = mw.html.create( "div" ) | local r = mw.html.create( "div" ) | ||
local s = facility( Data.tree ) | local s = facility( Data.tree, true ) | ||
if s then | if s then | ||
r:node( s ) | r:node( s ) |