Module:Parameter names example: Difference between revisions

m
(create a replacement for Template:Parameter names example)
 
m (11 revisions imported from templatewiki:Module:Parameter_names_example)
 
(10 intermediate revisions by 6 users not shown)
Line 11:
local function italicize(s)
return "''" .. s .. "''"
end
 
local function plain(s)
return s
end
 
Line 16 ⟶ 20:
-- Find how we want to format the arguments to the template.
local formatFunc
if args.display_display == 'italics' or args.display_display == 'italic' then
formatFunc = italicize
elseif args._display == 'plain' then
formatFunc = plain
else
formatFunc = makeParam
Line 24 ⟶ 30:
-- Build the table of template arguments.
local targs = {}
for _k, argNamev in ipairspairs(args) do
if type(k) == 'number' then
targs[argNamev] = formatFunc(argNamev)
elseif not k:find('^_') then
targs[k] = v
end
end
 
-- Find the template name and call it with the arguments.
local template
local template = args.template or mw.title.getCurrentTitle().basePageTitle.text
if args._template then
template = args._template
else
local templatecurrentTitle = args.template or mw.title.getCurrentTitle().basePageTitle.text
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(
return frame:expandTemplate{title = template, args = targs}
frame.expandTemplate,
frame,
return frame:expandTemplate {title = template, args = targs}
)
if success then
return result
else
return ''
end
end