יחידה:פרמטרים
מראה
function foo(frame)
local ans = ""
local pframe = frame:getParent()
local template = pframe:getTitle()
local templatename = template
if (find1(templatename, "תבנית:") == 1) then
templatename = sub1(templatename, 7)
end
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local numbered = 0
local mustnum = data[1]
local parameters = data[2]
local suggestions = data[3]
for k, v in pairs( pframe.args ) do
if type( k ) == 'string' then
ans = checknamed(k, ans, parameters, suggestions[k])
else
if (mw.text.trim(v) ~= "") then
numbered = k
end
end
end
if (mustnum < numbered) then
ans = out (ans, "צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered)
end
if (ans == "") then
return ans
end
return "<div class=error> '''שגיאת פרמטרים ב[[" .. template .. "]]:<br/>"
.. ans .. "''' </div>[[קטגוריה:שגיאות פרמטריות]]"
end
function checknamed(k, ans, parameters, suggestion)
local i = 2
local answer
for p1, p in ipairs(parameters) do
if p == k then
return ans
end
end
answer = "פרמטר לא ידוע: ''" .. k .. "''"
if (suggestion ~= nil) then
answer = answer .. '<span style = "color:green">, מומלץ ' .. suggestion .. "</span>"
end
return out(ans, answer)
end
function out(ans, new)
return ans .. new .. "</br>"
end
function sub1(str, from, to)
return mw.ustring.sub(str, from, to)
end
function find1(str, what, ...)
local args = ...
local where = 1
if (args ~= nil) then
where = args
end
local ans = mw.ustring.find(str, what, where, true)
if (ans == nil) then
ans = 0
end
return ans
end
function len1(s)
if (s == nil) then
return 0
end
return mw.ustring.len(s)
end
return {
['main'] = foo
}