위키백과>밥풀떼기 편집 요약 없음 |
위키백과>밥풀떼기 편집 요약 없음 |
||
2번째 줄: | 2번째 줄: | ||
local p = {} | local p = {} | ||
local function makeParam(s) | local function makeParam(s) | ||
local lb = '{' | local lb = '{' | ||
8번째 줄: | 8번째 줄: | ||
return lb:rep(3) .. s .. rb:rep(3) | return lb:rep(3) .. s .. rb:rep(3) | ||
end | end | ||
local function italicize(s) | local function italicize(s) | ||
return "''" .. s .. "''" | return "''" .. s .. "''" | ||
end | end | ||
local function plain(s) | local function plain(s) | ||
return s | return s | ||
end | end | ||
function p._main(args, frame) | function p._main(args, frame) | ||
-- Find how we want to format the arguments to the template. | -- Find how we want to format the arguments to the template. | ||
27번째 줄: | 27번째 줄: | ||
formatFunc = makeParam | formatFunc = makeParam | ||
end | end | ||
-- Build the table of template arguments. | -- Build the table of template arguments. | ||
local targs = {} | local targs = {} | ||
37번째 줄: | 37번째 줄: | ||
end | end | ||
end | end | ||
-- Find the template name. | -- Find the template name. | ||
local template | local template | ||
50번째 줄: | 50번째 줄: | ||
end | end | ||
end | end | ||
-- Call the template with the arguments. | -- Call the template with the arguments. | ||
frame = frame or mw.getCurrentFrame() | frame = frame or mw.getCurrentFrame() | ||
61번째 줄: | 61번째 줄: | ||
return result | return result | ||
else | else | ||
return ' | return '' | ||
end | end | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local args = require(' | local args = require('Module:Arguments').getArgs(frame, { | ||
wrappers = '' | wrappers = 'Template:Parameter names example' | ||
}) | }) | ||
return p._main(args, frame) | return p._main(args, frame) | ||
end | end | ||
return p | return p |
2014년 11월 26일 (수) 16:16 판
이 모듈에 대한 설명문서는 모듈:Parameter names example/설명문서에서 만들 수 있습니다
-- 이 모듈은 {{변수 이름 미리보기}}를 실행시킵니다.
local p = {}
local function makeParam(s)
local lb = '{'
local rb = '}'
return lb:rep(3) .. s .. rb:rep(3)
end
local function italicize(s)
return "''" .. s .. "''"
end
local function plain(s)
return s
end
function p._main(args, frame)
-- Find how we want to format the arguments to the template.
local formatFunc
if args._display == 'italics' or args._display == 'italic' then
formatFunc = italicize
elseif args._display == 'plain' then
formatFunc = plain
else
formatFunc = makeParam
end
-- Build the table of template arguments.
local targs = {}
for k, v in pairs(args) do
if type(k) == 'number' then
targs[v] = formatFunc(v)
elseif not k:find('^_') then
targs[k] = v
end
end
-- Find the template name.
local template
if args._template then
template = args._template
else
local currentTitle = mw.title.getCurrentTitle()
if currentTitle.prefixedText:find('/sandbox$') then
template = currentTitle.prefixedText
else
template = currentTitle.basePageTitle.prefixedText
end
end
-- Call the template with the arguments.
frame = frame or mw.getCurrentFrame()
local success, result = pcall(
frame.expandTemplate,
frame,
{title = template, args = targs}
)
if success then
return result
else
return ''
end
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Parameter names example'
})
return p._main(args, frame)
end
return p