მოდული:Transclude
მეჯინა
შეგიძლიათ შექმნათ დოკუმენტაცია ამ მოდულისათვის: მოდული:Transclude/ინფო
local p={}
-- გჷმიძახენს დინოხოლენ თანგის ომანგე თანგიშ არგუმენტეფიშამო
function p.call(frame)
local template = frame.args[1]
local args = frame:getParent().args
return frame:expandTemplate{ title=template, args=args }
end
-- ართამი რეალიზაცია forall დო call-შო
local function forallImpl(args, separator, conjunction, func)
-- კილაშ ნუმერაცია args -შე
local keys = {}
-- გიშაგორუა ნამდგარდია რანწკით, ნუმერაფილი კილეფიშამო
for key, value in pairs(args) do
if type(key) == 'number' and value and value ~= '' then
table.insert(keys, key)
end
end
table.sort(keys)
local results = {}
for _, key in ipairs(keys) do
local value = func(args[key])
table.insert(results, value)
end
return mw.text.listToText(results, separator, conjunction)
end
-- გჷმიძახენს დინოხოლენ თანგის, ნამუთ გჷნოჩანს თის ნუმერაცია მეჩამილ პარანეტრეფს ომანგე თანგის თითო-თითოთ
function p.forall(frame)
local template = frame.args[1]
local separator = frame.args.separator or ''
local conjunction = frame.args.conjunction or separator
local args = frame:getParent().args
local func = function(value)
return frame:expandTemplate{ title = template, args = {value} } -- ვარ-და შხვა frame?
end
return forallImpl(args, separator, conjunction, func)
end
-- ომანგე თანგშე ეთმეჭოფუნს ნუმერირაფილ თანგის დო აკმოკორობუნს თინეფს ართ ღოზის
function p.join(frame)
local separator = frame.args[1] or ''
local conjunction = frame.args[2] or separator
local args = frame:getParent().args
local func = function(value)
return value
end
return forallImpl(args, separator, conjunction, func)
end
-- ონინალე ფუნქცია: ლასუნს ნუმერირაფილ ინდექსეფშე გიშასხუნილ მისვიშ დუბლიკატეფს
local function deleteDuplicates(args)
local res = {}
for key, value in pairs(args) do
if args[key+1] ~= value then
table.insert(res, value)
end
end
return res
end
-- გჷმიძახენს დინოხოლენ თანგის მუსხირენშა, დო გჷნმოჩანს თის ოხვილურ თანგიშ არგუმენტეფიშ ბლოკეფს
function p.npc(frame)
local args = frame:getParent().args
local templateFrame = frame:getParent()
local template = frame.args[1]
-- გოთანჯუა, არგუმენტეფიშ ბლოკი ნამუ ნომერეფით რე ოხვილურინ;
-- დო ოხვილურ თანგის ქორე "პარამეტრი12" დო გიმოძახებულ მოდულს ქორე-და "პარამეტრი", გჷმიძახენს 12-ა ბლოკის
local nums = {}
for key, _ in pairs(args) do
local main, num = string.match(key, '^(.-)%s*(%d*)$')
num = tonumber(num)
-- "პარამეტრი12" გოთოლწონაფა, ხვალე მუჟანსჷთ გჷნოჩამილი რე "პარამეტრი"
if num and frame.args[main] then
table.insert(nums, num)
end
end
table.sort(nums)
nums = deleteDuplicates(nums)
-- გჷნმურს ბლოკეფიშ ოხვილურ ნომერეფს ძინაშ მეჯინათ დო ართშა
-- თანგიშა ინოხუნაფა:
-- 1. მოჩამილი მოდულიშ ართამი არგუმენტი
-- 2. მოჩამილი თანგიშ მოჩამილ სახეშ არგუმენტი "პარამეტრი12" მუჭოთ "პარამეტრი" 12-ა ბლოკის
local results = {}
for _, blockNum in ipairs(nums) do
-- მოდულიშ ართამი არგუმენტეფი, ნამუთ გჷნმაჩამუ ირ ბლოკის
local blockArgs = mw.clone(frame.args)
-- metatable ეშმაათანს expandTemplate
setmetatable(blockArgs, nil)
for key, value in pairs(args) do
local main, num = string.match(key, '^(.-)%s*(%d*)$')
num = tonumber(num)
-- არგუმენტიშ "პარამეტრი12" გინოჩამა მუჭოთ "პარამეტრი" 12-ა ბლოკის, ხვალე თინწკჷმა "პარამეტრი" ქორე-და მოდულიშ გჷმოძახებას
if blockNum == num and frame.args[main] then
blockArgs[main] = value
end
end
local blockText = templateFrame:expandTemplate{ title=template; args=blockArgs }
table.insert(results, blockText)
end
return table.concat(results)
end
-- ქიმინჯენს forall-შ ანალოგიურო რიცხობურ მათირეფონით, ნამუთ თირანს (სტანდარტულო, 1-შე) f.args[2]-შა.
function p.cycle(f)
local tf,ac,op=f:getParent(), {}, f.args.output or 'inline';
local sep='';
if op == 'newline' then
sep='\n';
end
for p,k in pairs(f.args) do
if type(p)=='number' then
if p>2 then ac[p-1]=k end
else ac[p]=k
end
end
local s,fh = f.args[2]:match('^%s*(%-?%d+)%s*%.%.') or 1,
f.args[2]:match('%.%.%s*(%S.*)%s*$') or f.args[2] or '';
fh=tonumber(fh) or fh:match('^%s*(.-)%s*$');
s=tonumber(s);
local acr={};
if not s then error('ციკლიშ დოჭყაფა „'..s..'“ — ვა რიცხუ') end
local function dc(order)
local r=tf:expandTemplate{ title=f.args[1]; args={s,unpack(ac)} }
if order == 'desc' then
s=s-1;
else
s=s+1;
end
if r~='' then table.insert(acr,r); return r end
end
if type(fh)=='number' then
if fh > s then
while s<=fh do dc('asc') end
else
while s>=fh do dc('desc') end
end
elseif fh~='' then
while tf:expandTemplate{ title=fh; args={s,unpack(ac)} } do dc('asc') end
else
while dc('asc') do end
end
return table.concat(acr, sep)
end
return p