Content deleted Content added
Migration zur Umparametrisierung abgeschlossen; keine Einbindungen mehr |
update |
||
Line 1:
--[=[ TemplatePar 2013-06-
Template parameter utility
* assert
* check
* count
Line 108 ⟶ 109:
end
return r
end --
Line 545 ⟶ 546:
local function format(
-- Check validity of
-- Precondition:
--
-- options -- table or nil; optional details
-- options.pattern
-- options.key
-- options.
-- options.min
-- options.max
Line 560 ⟶ 561:
-- Uses:
-- > Patterns
-- failure()
-- mw.text.trim()
-- failsafe()
-- containsCJK()
local r = false
local s = false
local
local
if type( options.pattern )
if options.key
r = failure( "dupRule", false, options )
scan = options.pattern
end
else
if type( options.key ) == "string" then
s = mw.text.trim( options.key )
else
end
scan = Patterns[ s
if type( scan
end
r = failure( "invalid", show, options )
end
end
else
r = failure( "unknownRule", s, options )
end
end
if scan then
local legal, got = pcall( failsafe,
if legal then
if not got then
if s == "aa" then
got = containsCJK(
end
if not got then
end
r = failure( "invalid", show, options )
end
end
Line 639 ⟶ 627:
end
end
if #
show = show .. " '" .. options.say ..
end
r = failure( "tooShort", show, options )
end
else
Line 650 ⟶ 640:
if options.max and not r then
if type( options.max ) == "number" then
if #
show = show .. " '" .. options.say ..
end
r = failure( "tooLong", show, options )
end
else
Line 661 ⟶ 653:
return r
end -- format()
local function formatted( assignment, access, options )
-- Check validity of one particular parameter in a collection
-- Precondition:
-- assignment -- collection
-- access -- id of parameter in collection
-- options -- table or nil; optional details
-- Postcondition:
-- Return string with error message as configured;
-- false if valid or no answer permitted
-- Uses:
-- > Patterns
-- failure()
-- mw.text.trim()
-- format()
-- failure()
local r = false
if type( assignment ) == "table" then
local story = assignment.args[ access ]
if type( story ) == "string" then
if type( options ) ~= "table" then
options = { }
end
options.say = access
r = format( story, options )
else
r = failure( "invalid", access, options )
end
end
return r
end -- formatted()
TemplatePar.assert = function ( analyze, append, options )
-- Perform parameter analysis on a single string
-- Precondition:
-- analyze -- string to be analyzed
-- append -- string: append error message, prepending <br />
-- false or nil: throw error with message
-- options -- table; optional details
-- Postcondition:
-- Return string with error message as configured;
-- false if valid
-- Uses:
-- format()
local r = format( analyze, options )
if ( r ) then
if ( type( append ) == "string" ) then
if ( append ~= "" ) then
r = append .. "<br />" .. r
end
else
error( r, 0 )
end
end
return r
end -- TemplatePar.assert()
Line 738 ⟶ 790:
TemplatePar.valid = function (
-- Check validity of one particular template parameter
-- Precondition:
--
-- options -- table or nil; optional details
-- Postcondition:
Line 748 ⟶ 800:
-- Uses:
-- mw.text.trim()
--
-- mw.getCurrentFrame()
-- frame:getParent()
-- formatted()
-- failure()
-- finalize()
local r
if type(
r = mw.text.trim(
if #r == 0 then
r = false
Line 759 ⟶ 814:
end
if r then
if type( options ) ~= "table" then
options = { }
end
if options.low then
params = TemplatePar.downcase( options )
else
params = mw.getCurrentFrame():getParent()
end
r = formatted( params, access, options )
else
r = failure( "noname", false, options )
Line 905 ⟶ 969:
else
s = frame.args[ 1 ] or ""
r = tonumber( s )
if ( r ) then
s = r
end
r = TemplatePar.valid( s, options )
end
|