יחידה:פרמטרים: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 3: | שורה 3: | ||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||
local template = pframe:getTitle() | local template = pframe:getTitle() | ||
local | local templatename = template | ||
local | if (find1(templatename, "תבנית:") == 1) then | ||
templatename = sub1(templatename, 7) | |||
end | |||
local data = mw.loadData('יחידה:פרמטרים/' .. templatename) | |||
local numbered = 0 | local numbered = 0 | ||
local mustnum = | local mustnum = data[1] | ||
local parameters = data[2] | |||
local suggestions = | local suggestions = data[3] | ||
for k, v in pairs( pframe.args ) do | for k, v in pairs( pframe.args ) do | ||
if type( k ) == 'string' then | if type( k ) == 'string' then | ||
ans = checknamed(k, ans, | ans = checknamed(k, ans, parameters, suggestions[k]) | ||
else | else | ||
if (mw.text.trim(v) ~= "") then | |||
if ( | numbered = k | ||
end | end | ||
end | end | ||
end | end | ||
if (mustnum < numbered | if (mustnum < numbered) then | ||
ans = out (ans, "צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered) | ans = out (ans, "צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered) | ||
end | end | ||
| שורה 33: | שורה 31: | ||
end | end | ||
function checknamed(k, ans, | function checknamed(k, ans, parameters, suggestion) | ||
local i = 2 | local i = 2 | ||
local answer | |||
if | for p1, p in ipairs(parameters) do | ||
if p == k then | |||
return ans | return ans | ||
end | end | ||
end | end | ||
answer = "פרמטר לא ידוע: ''" .. k .. "''" | |||
if (suggestion ~= nil) then | |||
answer = answer .. ", מומלץ " .. suggestion | |||
end | |||
return out(ans, answer) | |||
end | end | ||
function out(ans, new) | function out(ans, new) | ||
return ans .. new .. "</br>" | 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 | end | ||
גרסה מ־13:10, 8 במאי 2015
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 .. ", מומלץ " .. suggestion
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
}