위키백과>밥풀떼기 m (밥풀떼기 사용자가 모듈:Parameter names example 문서를 넘겨주기를 만들지 않고 모듈:변수 이름 미리보기 문서로 옮겼습니다) |
m (판 8개를 가져왔습니다: 위키백과에서 가져옴) |
||
(사용자 2명의 중간 판 2개는 보이지 않습니다) | |||
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() | ||
64번째 줄: | 64번째 줄: | ||
end | end | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local args = require(' | local args = require('모듈:Arguments').getArgs(frame, { | ||
wrappers = ' | wrappers = '틀:변수 이름 미리보기' | ||
}) | }) | ||
return p._main(args, frame) | return p._main(args, frame) | ||
end | end | ||
return p | return p |
2020년 4월 12일 (일) 19:22 기준 최신판
이 모듈에 대한 설명문서는 모듈: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('모듈:Arguments').getArgs(frame, {
wrappers = '틀:변수 이름 미리보기'
})
return p._main(args, frame)
end
return p