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

אין תקציר עריכה
אין תקציר עריכה
שורה 5: שורה 5:
local template = pframe:getTitle()
local template = pframe:getTitle()
local templatename = template
local templatename = template
if find1(templatename, namespace) == 1 then templatename = mw.ustring.sub(templatename, len1(namespace) + 1) end
if find1(templatename, namespace) == 1
then templatename = mw.ustring.sub(templatename, len1(namespace) + 1) end
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local numbered = 0
local numbered = 0
local lastparam
local mustnum = data[1]
local mustnum = data[1]
parameters = data[2]
parameters = data[2]
שורה 13: שורה 15:
suggestions = data[4]
suggestions = data[4]
for tt, t in ipairs(must) do
for tt, t in ipairs(must) do
checkmust(t)
checkmust(t) end
end
for k, v in pairs(pframe.args) do
for k, v in pairs(pframe.args) do
if type(k) == "string" then checknamed(k) elseif not isempty(v) then numbered = k end
if type(k) == "string"
end
then checknamed(k)
if mustnum < numbered then out ("צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered) end
elseif not isempty(v)
if ans == "" then return ans end
then numbered = k lastparam = v end end
if mustnum < numbered
then out("צריך מקסימום " .. mustnum .. " פרמטרים ללא שם, ישנם " .. numbered .. ', כשהאחרון הוא: "' .. lastparam .. '"') end
if ans == ""
then return ans end
return '<div class=error><div class="parameters">' .. " '''שגיאת פרמטרים ב[[" .. template .. "]]:<br/>" .. ans ..  
return '<div class=error><div class="parameters">' .. " '''שגיאת פרמטרים ב[[" .. template .. "]]:<br/>" .. ans ..  
"''' </div></div>[[קטגוריה:שגיאות פרמטריות]]"  
"''' </div></div>[[קטגוריה:שגיאות פרמטריות]]"  
שורה 26: שורה 31:
function checkmust(must)
function checkmust(must)
for g, h in pairs(pframe.args) do
for g, h in pairs(pframe.args) do
if must == g .. "" then if isempty(h) then out("פרמטר חובה ריק: ''" .. g .. "''") end return end
if must == g .. ""
end
then if isempty(h)
then out("פרמטר חובה ריק: ''" .. g .. "''") end
return end end
out("פרמטר חובה חסר: ''" .. must .. "''")
out("פרמטר חובה חסר: ''" .. must .. "''")
end
end
שורה 34: שורה 41:
local answer = "פרמטר לא ידוע: ''" .. k .. "''"
local answer = "פרמטר לא ידוע: ''" .. k .. "''"
for p1, p in ipairs(parameters) do
for p1, p in ipairs(parameters) do
if p == k then return end
if p == k
end
then return end end
if suggestions[k] ~= nil then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end
if suggestions[k] ~= nil
then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end
out(answer)
out(answer)
end
end
שורה 42: שורה 50:
function isempty(v)
function isempty(v)
for i = 1, len1(v) do
for i = 1, len1(v) do
if mw.ustring.byte(v, i, i) > 32 then return false end
if mw.ustring.byte(v, i, i) > 32
end
then return false end end
return true
return true
end
end
שורה 53: שורה 61:
function find1(str, what, where)
function find1(str, what, where)
local ans = mw.ustring.find(str, what, where, true)
local ans = mw.ustring.find(str, what, where, true)
if ans == nil then ans = 0 end
if ans == nil
then ans = 0 end
return ans
return ans
end
end


function len1(s)
function len1(s)
if s == nil then return 0 end
if s == nil
then return 0 end
return mw.ustring.len(s)
return mw.ustring.len(s)
end
end


return {['main'] = foo}
return {['main'] = foo}