לדלג לתוכן

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

מתוך צפונות ויקי
אין תקציר עריכה
אין תקציר עריכה
שורה 3: שורה 3:
local pframe = frame:getParent()
local pframe = frame:getParent()
local template = pframe:getTitle()
local template = pframe:getTitle()
local empty = false
local templatename = template
local start = true
if (find1(templatename, "תבנית:") == 1) then
templatename = sub1(templatename, 7)
end
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local numbered = 0
local numbered = 0
local mustnum = tonumber(frame.args[1])
local mustnum = data[1]
--local suggestions = mw.loadData(template .. "/ניהול_פרמטרים");
local parameters = data[2]
local suggestions = mw.loadData('יחידה:פרמטרים/סדרת טלוויזיה1');
local suggestions = data[3]
for k1, v1 in pairs( suggestions ) do
ans = out(ans, v1)
end
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, frame)
ans = checknamed(k, ans, parameters, suggestions[k])
else
else
numbered = k
if (mw.text.trim(v) ~= "") then
if (k == 1 and mw.text.trim(v) == "" and start) then
numbered = k
empty = true
end
end
end
end
start = false
end
end
if (mustnum < numbered and not (empty and mustnum == 0 and numbered == 1)) then
if (mustnum < numbered) then
ans = out (ans, "צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered)
ans = out (ans, "צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered)
end
end
שורה 33: שורה 31:
end
end


function checknamed(k, ans, frame)
function checknamed(k, ans, parameters, suggestion)
local i = 2
local i = 2
while (frame.args[i] ~= nil) do
local answer
if (frame.args[i] == k) then
for p1, p in ipairs(parameters) do
if p == k then
return ans
return ans
end
end
i = i + 1
end
end
return out(ans, "פרמטר לא ידוע: ''" .. k .. "''")
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
}