Изменения

Перейти к навигации Перейти к поиску
оформление
Строка 1: Строка 1:  
local p = {}
 
local p = {}
    +
-- используется для того, чтобы можно было удалять элементы из таблицы
 
local function copy(other)
 
local function copy(other)
 
local res = {}
 
local res = {}
Строка 9: Строка 10:  
end
 
end
   −
function expand(frame, tname, targs)
+
-- вызов шаблона, при ошибке возвращает пустую строку
 +
local function expand(frame, tname, targs)
 
local success, result = pcall(
 
local success, result = pcall(
 
frame.expandTemplate,
 
frame.expandTemplate,
Строка 30: Строка 32:  
local args = copy(getArgs(frame)) --copy(frame.args)
 
local args = copy(getArgs(frame)) --copy(frame.args)
 
local tag =  args._tag or 'code'
 
local tag =  args._tag or 'code'
local sep =  args._sep or '→'
+
local sep =  args._sep or '→' -- по умолчанию "→"
local nwt = mw.html.create(tag):tag(tag)
+
local nwt = mw.html.create(tag):tag(tag) --"no-wiki tag", внутри него шаблон не вызывается
local content = '{{'
+
local content = '{{' --для накопления содержимого тэга
local tname = args._template or args[1]
+
local tname = args._template or args[1]  
 
 
if args._template == nil then
+
if args._template == nil then --имя вызываемого шаблона в неименованном первом параметре, больше его обрабатывать не надо
 
table.remove(args,1)
 
table.remove(args,1)
 
end
 
end
   
content = content .. tname
 
content = content .. tname
 
local targs = {}
 
local targs = {}
 
for k, v in pairs(args) do
 
for k, v in pairs(args) do
if type(k) == 'number' then
+
if type(k) == 'number' then --неименованные параметры
 
targs[k] = v
 
targs[k] = v
 
content = content .. '|' .. v
 
content = content .. '|' .. v
elseif not k:find('^_') then
+
elseif not k:find('^_') then --именованные параметры, исключая модификаторы внешнего вида
 
targs[k] = v
 
targs[k] = v
 
content = content .. '|' .. k .. '=' .. v
 
content = content .. '|' .. k .. '=' .. v
 
end
 
end
 
end
 
end
   
content = content .. '}}'
 
content = content .. '}}'
 
nwt:wikitext(content):done()
 
nwt:wikitext(content):done()
Анонимный участник

Реклама:

Навигация