יחידה:ParamValidator: הבדלים בין גרסאות בדף

תוכן שנמחק תוכן שנוסף
כמקובל
ניסוי
שורה 180:
-- this is the function to be called by other modules. it expects the frame, and then an optional list of subpages, e.g. { "Documentation" }.
-- if second parameter is nil, only tempalte page will be searched for templatedata.
local function calculateViolations( frame, subpages )
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
local type_validators = {
['number'] = function( s ) return mw.language.getContentLanguage():parseFormattedNumber( s ) end
}
local function compatible( typ, val )
local func = type_validators[typ]
return type( func ) ~= 'function' or util.empty( val ) or func( val )
end
local function list_empty_or_contains(ar, searched)
if not ar or #ar == 0 then return true end
for _, val in ipairs(ar) do if val == searched then return true end end
return false
end
שורה 196 ⟵ 203:
local td_params = templatedata and templatedata.params
local all_aliases, all_series = {}, {}
if not td_params then return { ['no-templatedata'] = { [''] = '' } } end
שורה 236 ⟵ 244:
or not compatible( tp_param.type, value ) and 'incompatible'
or not series and already_seen[tp_param] and hasval and 'duplicate'
or hasval and not list_empty_or_contains(td_param.suggestedvalues , value) and 'unsuggested-value'
 
already_seen[tp_param] = hasval
שורה 245 ⟵ 255:
end
end
 
-- test for empty/missing paraeters declared "required"
for p_name, param in pairs( td_params ) do