Content deleted Content added
update |
update |
||
Line 1:
--[=[ TemplatePar 2013-05-
Template parameter utility
* check
Line 26:
noErrorCat = "#invoke:TemplatePar * noError and missing category",
noname = "#invoke:TemplatePar * missing parameter name",
tooLong = "Error in template * parameter too long",
tooShort = "Error in template * parameter too short",
Line 41 ⟶ 40:
invalidPar = "#invoke:TemplatePar * Ungültiger Parameter",
minmax = "#invoke:TemplatePar * min > max",
multiSpell = "Fehler bei Vorlage *
noErrorCat = "#invoke:TemplatePar * noError und keine Kategorie",
noname = "#invoke:TemplatePar * Parametername nicht angegeben",
tooLong = "Fehler bei Vorlage * Parameter zu lang",
tooShort = "Fehler bei Vorlage * Parameter zu kurz",
Line 242 ⟶ 240:
g = g.args
end
for k, v in
if type( v ) == "string" then
if v:match( "^%s*$" ) then
v = false
end
else
v = false
end
if type( k ) == "number" then
end
end --
r
end
return r
end -- fetch()
Line 352 ⟶ 355:
local function
-- Perform parameter analysis
-- Precondition:
-- valid -- table; unique sequence of known parameters
-- duty -- table; sequence of mandatory parameters
-- got -- table; sequence of current parameters
-- options -- table or nil; optional details
-- Postcondition:
-- Return string as configured; empty if valid
-- Uses:
-- finder()
-- fault()
-- failure()
-- fed()
local k, v
local r = false
for k, v in pairs( got ) do
if not finder( valid, k ) then
r = fault( r, k )
end
end -- for k, v
if r then
r = failure( "unknown", r, options )
else -- all names valid
local i, s
for i = 1, #duty do
s = duty[ i ]
if not fed( got, s ) then
r = fault( r, s )
end
end -- for i
if r then
r = failure( "undefined", r, options )
else -- all mandatory present
for i = 1, #duty do
s = duty[ i ]
if not got[ s ] then
r = fault( r, s )
end
end -- for i
if r then
r = failure( "empty", r, options )
end
end
end
return r
end -- fix()
local function flat( collection, options )
-- Return all table elements with downcased string
-- Precondition:
-- collection -- table; k=v pairs
-- options -- table or nil; optional messaging details
-- Postcondition:
-- Return table, may be empty; or string with error message.
-- Uses:
-- mw.ustring.lower()
-- fault()
-- failure()
local k, v
local r = { }
local e = false
for k, v in pairs( collection ) do
if type ( k ) == "string" then
k = mw.ustring.lower( k )
if r[ k ] then
e = fault( e, k )
end
end
r[ k ] = v
end -- for k, v
if e then
r = failure( "multiSpell", e, options )
end
return r
end -- flat()
local function fold( options )
-- Merge two tables, create new sequence if both not empty
-- Precondition:
Line 365 ⟶ 449:
-- fault()
-- failure()
--
local i, e, r, s
local base = options.mandatory
Line 399 ⟶ 483:
end
end
if options.low and type( r ) == "table" then
end
return r
end --
local function
-- Run parameter analysis on current environment
-- Precondition:
Line 479 ⟶ 502:
-- false if valid
-- Uses:
--
-- failure()
-- fetch()
Line 493 ⟶ 516:
options.optional = { }
end
r =
else
options = { }
Line 508 ⟶ 531:
end
return finalize( r, options )
end --
Line 633 ⟶ 656:
-- false if valid
-- Uses:
--
return
end -- TemplatePar.check()
Line 670 ⟶ 693:
-- fault()
-- failure()
local t = mw.getCurrentFrame():getParent()
end -- TemplatePar.downcase()
Line 730 ⟶ 737:
-- false if valid
-- Uses:
--
return
end -- TemplatePar.verify()
Line 748 ⟶ 755:
-- Return string with error message or ""
-- Uses:
--
-- fill()
local options = { optional = { "1",
Line 758 ⟶ 765:
template = "#invoke:TemplatePar|check|"
}
local r =
if not r then
options = { mandatory = fill( frame.args[ 1 ] ),
Line 767 ⟶ 774:
template = frame.args.template
}
r =
end
return r or ""
Line 792 ⟶ 799:
-- Return string with error message or ""
-- Uses:
--
-- trim()
-- TemplatePar.valid()
Line 805 ⟶ 812:
template = "#invoke:TemplatePar|valid|"
}
local r =
if not r then
local s = trim( frame.args[ 2 ] )
|