Документация
local p = {}
function p.tableRow(frame)
local is_template_exists = false
local BASEPAGE = mw.title.getCurrentTitle().baseText
local template_args, tlp_args, result = {}, {}, ""
for k, v in pairs(frame:getParent().args)
do
tlp_args[k] = v
if type(k) == "number" then k = k - 1 end
if k == 0 then -- первый параметр
result = v
tlp_args[1] = BASEPAGE
else
template_args[k] = v
end
end
local is_template_exists, resultTemplate = pcall(frame.expandTemplate, frame, {title=BASEPAGE, args=template_args})
local resultSandbox = frame:expandTemplate{title=BASEPAGE.."/песочница", args=template_args}
local is_equalTemplate = ""
if is_template_exists then
is_equalTemplate = is_equal(result, resultTemplate)
else
tlp_args[1] = tlp_args[1] .. "/песочница"
end
local tr = mw.html.create('tr')
tr:tag('td'):wikitext(frame:expandTemplate{title="tlp", args=tlp_args})
tr:tag('td'):wikitext(resultSandbox)
tr:tag('td'):wikitext(result)
tr:tag('td'):wikitext(is_equalTemplate)
tr:tag('td'):wikitext(is_equal(result, resultSandbox))
local html = tostring(tr)
html = html:gsub('</tr>', '') -- убираем закрывающий тег, чтобы можно было дополнять таблицу
return html
end
function is_equal(wait, result)
local title = "Не сделано"
if mw.title.equals(wait, result) then title = "Сделано" end
return mw.getCurrentFrame():expandTemplate{title=title, args={""}}
end
return p