Modul:TemplateData: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
2018-02-11
wp>PerfektesChaos (2018-02-10T1845) |
wp>PerfektesChaos (2018-02-11) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = "2018-02- | serial = "2018-02-11", | ||
item = 46997995 } | item = 46997995 } | ||
--[=[ | --[=[ | ||
Zeile 62: | Zeile 62: | ||
} | } | ||
local Permit = { | local Permit = { | ||
builder = { align = "block", | |||
block = "block", | |||
compressed = "block", | |||
dense = "block", | |||
grouped = "inline", | |||
half = "inline", | |||
indent = "block", | |||
inline = "inline", | |||
last = "block", | |||
lead = "block", | |||
newlines = "block", | |||
spaced = "inline" }, | |||
colors = { tableheadbg = "B3B7FF", | colors = { tableheadbg = "B3B7FF", | ||
required = "EAF3FF", | required = "EAF3FF", | ||
Zeile 1.060: | Zeile 1.072: | ||
local function format() | local function format() | ||
-- Build formatted element | |||
-- Returns <inline> | |||
local source = Data.tree.format:lower() | |||
local r, s | |||
if source == "inline" or source == "block" then | |||
r = mw.html.create( "i" ) | |||
:wikitext( source ) | |||
else | |||
local code | |||
if source:find( "|", 1, true ) then | |||
local scan = "^[\n ]*%{%{[\n _]*|[\n _]*=[\n _]*%}%}[\n ]*$" | |||
if source:match( scan, 1, true ) then | |||
code = source | |||
else | |||
source = mw.text.nowiki( source ):gsub( "\n", "\n" ) | |||
s = tostring( mw.html.create( "code" ) | |||
:wikitext( source ) ) | |||
Fault( "Invalid format " .. s ) | |||
source = false | |||
end | |||
else | |||
local words = mw.text.split( source, "%s+" ) | |||
local show, start, unknown | |||
for i = 1, #words do | |||
s = words[ i ] | |||
if i == 1 then | |||
start = s | |||
end | |||
if Permit.builder[ s ] == start then | |||
Permit.builder[ s ] = true | |||
else | |||
if unknown then | |||
unknown = string.format( "%s %s", unknown, s ) | |||
else | |||
unknown = s | |||
end | |||
end | |||
end -- i = 1, #words | |||
if unknown then | |||
s = tostring( mw.html.create( "code" ) | |||
:css( "white-space", "nowrap" ) | |||
:wikitext( s ) ) | |||
Fault( "Unknown/misplaced format keyword " .. s ) | |||
source = false | |||
start = false | |||
end | |||
if start == "inline" then | |||
if Permit.builder.half == true then | |||
show = "inline half" | |||
code = "{{_ |_=_}}" | |||
elseif Permit.builder.grouped == true then | |||
show = "inline grouped" | |||
code = "{{_ | _=_ }}" | |||
elseif Permit.builder.spaced == true then | |||
show = "inline spaced" | |||
code = "{{_ | _ = _ }}" | |||
end | |||
elseif start == "block" then | |||
local space = " " -- amid "|" and name | |||
local spaced = " " -- preceding "=" | |||
local spacer = " " -- following "=" | |||
local suffix = "N" -- closing "}}" on new line | |||
show = "block" | |||
if Permit.builder.indent == true then | |||
start = " " | |||
show = "block indent" | |||
else | |||
start = "" | |||
end | |||
if Permit.builder.compressed == true then | |||
space = "" | |||
spaced = "" | |||
spacer = "" | |||
show = show .. " compressed" | |||
if Permit.builder.last == true then | |||
show = show .. " last" | |||
else | |||
suffix = "" | |||
end | |||
else | |||
if Permit.builder.lead == true then | |||
show = show .. " lead" | |||
else | |||
space = "" | |||
end | |||
if Permit.builder.align == true then | |||
if type( Data.got ) == "table" and | |||
type( Data.got.params ) == "table" then | |||
local n = 0 | |||
for k, v in pairs( Data.got.params ) do | |||
if type( v ) == "table" and | |||
v.deprecated and | |||
type( k ) == "string" and | |||
#k > n then | |||
n = #k | |||
end | |||
end -- for k, v | |||
if n > 1 then | |||
spaced = string.rep( "_", n ) .. " " | |||
end | |||
end | |||
show = show .. " align" | |||
elseif Permit.builder.dense == true then | |||
spaced = "" | |||
spacer = "" | |||
show = show .. " dense" | |||
end | |||
end | |||
if Permit.builder.last == true then | |||
suffix = spacer | |||
show = show .. " last" | |||
end | |||
code = string.format( "N{{_N%s|%s_%s=%s_%s}}N", | |||
start, | |||
space, | |||
spaced, | |||
spacer, | |||
suffix ) | |||
end | |||
if show then | |||
r = mw.html.create( "span" ) | |||
:wikitext( show ) | |||
end | |||
end | |||
if code then | |||
source = code:gsub( "N", "\n" ) | |||
code = mw.text.nowiki( code ):gsub( "N", "\n" ) | |||
code = mw.html.create( "code" ) | |||
:wikitext( code ) | |||
if r then | |||
r = mw.html.create( "span" ) | |||
:node( r ) | |||
:node( code ) | |||
else | |||
r = code | |||
end | |||
end | |||
end | |||
Data.tree.format = source | |||
return r | |||
end -- format() | |||
local function formatter() | |||
-- Build presented documentation | -- Build presented documentation | ||
-- Returns <div> | -- Returns <div> | ||
Zeile 1.088: | Zeile 1.245: | ||
end | end | ||
if Data.tree and Data.tree.format then | if Data.tree and Data.tree.format then | ||
local e | local e = format() | ||
if e then | |||
if | local show = "Format" | ||
if Config.supportFormat then | |||
show = string.format( "[[%s|%s]]", | |||
Config.supportFormat, show ) | |||
end | |||
r:node( mw.html.create( "p" ) | |||
:wikitext( show .. ": " ) | |||
:node( e ) ) | |||
end | end | ||
end | end | ||
return r | return r | ||
end -- | end -- formatter() | ||
Zeile 1.136: | Zeile 1.285: | ||
end | end | ||
end | end | ||
Data.div:node( | Data.div:node( formatter() ) | ||
if not Data.lazy then | if not Data.lazy then | ||
Data.slim = flush() | Data.slim = flush() |