Модуль:Example: различия между версиями
Перейти к навигации
Перейти к поиску
(например) |
(getArgs) |
||
Строка 25: | Строка 25: | ||
function p.main(frame) | function p.main(frame) | ||
− | local args = copy(frame.args) | + | if not getArgs then |
+ | getArgs = require('Module:Arguments').getArgs | ||
+ | end | ||
+ | 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) | ||
local content = '{{' | local content = '{{' | ||
− | local tname = | + | local tname = args._template or args[1] |
− | if args._template | + | if args._template == nil then |
− | |||
− | |||
− | |||
table.remove(args,1) | table.remove(args,1) | ||
end | end |
Версия от 15:04, 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)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = copy(getArgs(frame)) --copy(frame.args)
local tag = args._tag or 'code'
local sep = args._sep or '→'
local nwt = mw.html.create(tag):tag(tag)
local content = '{{'
local tname = args._template or args[1]
if args._template == nil then
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