Module:Template wrapper: Difference between revisions

Content deleted Content added
m 1 revision imported
m 1 revision imported
 
(3 intermediate revisions by 3 users not shown)
Line 1:
require('Module:No globalsstrict');
 
local error_msg = '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">&#124;_template=</code> missing or empty</span>';
Line 249:
]]
 
local function list (frame, do_link)
local args = {}; -- table of default and live parameters and their values to be passed to the listed template
local template = _main (frame, args, true); -- get default and live parameters and the name of the listed template
 
template = _main (frame, args, true); -- get default and live parameters and the name of the listed template
local function list (frame)
if not template then -- template name is required
local args = {}; -- table of default and live parameters and their values to be passed to the listed template
local return templateerror_msg; -- theemit nameerror ofmessage theand listedabandon if template name not present
 
template = _main (frame, args, true); -- get default and live parameters and the name of the listed template
if not template then -- template name is required
return error_msg; -- emit error message and abandon if template name not present
end
if do_link then
template = ('[[%s|%s]]'):format(frame:expandTemplate{ title='Transclude', args = {template} }, template)
end
table.sort(args)
for i = 1, #args do
local stripped = args[i]:match('^' .. i .. '=([^=]*)$')
if stripped then args[i] = stripped else break end
end
return frame:preprocess(table.concat({
'<code style="color:inherit; background:inherit; border:none;">&#123;&#123;',
template,
('<wbr><nowiki>|%s</nowiki>'):rep(#args):format(unpack(args)), '&#125;&#125;</code>'})); -- render the template
end
 
local function link (frame)
return frame:preprocess (table.concat ({'<code style="color:inherit; background:inherit; border:none;"><nowiki>{{', template, ' |', table.concat( args, ' |' ), '}}</nowiki></code>'})); -- render the template
return list(frame, true)
end
 
 
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
Line 267 ⟶ 279:
 
return {
link = link,
list = list,
wrap = wrap,