Модуль:Example: различия между версиями
Перейти к навигации
Перейти к поиску
(для начала) |
(fix) |
||
Строка 9: | Строка 9: | ||
end | end | ||
− | function expand(frame, tname, | + | function expand(frame, tname, targs) |
local success, result = pcall( | local success, result = pcall( | ||
frame.expandTemplate, | frame.expandTemplate, | ||
frame, | frame, | ||
− | {title = | + | {title = tname, args = targs} |
) | ) | ||
if success then | if success then | ||
Строка 20: | Строка 20: | ||
return '' | return '' | ||
end | end | ||
+ | --return frame:expandTemplate({title = tname, args = args}) | ||
end | end | ||
Строка 28: | Строка 29: | ||
sep = args._sep or '→' | sep = args._sep or '→' | ||
nwt = mw.html.create(tag):tag(tag) | nwt = mw.html.create(tag):tag(tag) | ||
− | |||
content = '{{' | content = '{{' | ||
Строка 35: | Строка 35: | ||
else | else | ||
tname = args[1] | tname = args[1] | ||
− | 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 | ||
Строка 56: | Строка 53: | ||
nwt:wikitext(content):done() | nwt:wikitext(content):done() | ||
− | return tostring(nwt) .. sep .. tostring(expand(frame, tname, targs)) | + | return tostring(nwt) .. ' ' .. sep .. ' ' .. tostring(expand(frame, tname, targs)) |
end | end | ||
return p | return p |
Версия от 14:18, 16 января 2016
Для документации этого модуля может быть создана страница Модуль:Example/doc
local p = {}
local function copy(other)
local res = {}
for k,v in pairs(other) do
res[k] = v
end
return res
end
function expand(frame, tname, targs)
local success, result = pcall(
frame.expandTemplate,
frame,
{title = tname, args = targs}
)
if success then
return result
else
return ''
end
--return frame:expandTemplate({title = tname, args = args})
end
function p.main(frame)
local args = copy(frame.args)
tag = args._tag or 'code'
sep = args._sep or '→'
nwt = mw.html.create(tag):tag(tag)
content = '{{'
if args._template then
tname = args._template
else
tname = args[1]
table.remove(args,1)
end
content = content .. tname
local targs = {}
for k, v in pairs(args) do
if type(k) == 'number' then
targs[k] = v
content = content .. '|' .. v
elseif not k:find('^_') then
targs[k] = v
content = content .. '|' .. k .. '=' .. v
end
end
content = content .. '}}'
nwt:wikitext(content):done()
return tostring(nwt) .. ' ' .. sep .. ' ' .. tostring(expand(frame, tname, targs))
end
return p