Module:Unsubst: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
m
10 revisions imported
(add parameter list, aliases, flags; use Module:Template invocation)
m (10 revisions imported)
 
(3 intermediate revisions by 3 users not shown)
Line 9:
['$aliases'] = 'parameter aliases',
['$flags'] = 'flags',
['$B'] = 'template content',
['$template-name'] = 'template invocation name override',
}
 
Line 47 ⟶ 48:
-- Find the invocation name.
local mTemplateInvocation = require('Module:Template invocation')
local name
local name = mTemplateInvocation.name(frame:getParent():getTitle())
 
if frame.args['$template-name'] and '' ~= frame.args['$template-name'] then
name = frame.args['$template-name'] -- override whatever the template name is with this name
else
local name = mTemplateInvocation.name(frame:getParent():getTitle())
end
 
-- Combine passed args with passed defaults
Line 79 ⟶ 86:
-- Trim parameters, if not specified otherwise
if not string.find( ','..(frame.args['$flags'] or '')..',', ',%s*keep%-whitespace%s*,' ) then
for k, v in pairs( args ) do args[k] = mw.ustring.match(v, '^%s*(.*)%s*$') or '' end
end
-- Remove empty parameters, if specified
if string.find( ','..(frame.args['$flags'] or '')..',', ',%s*remove%-empty%s*,' ) then
for k, v in pairs( args ) do
if v == '' then args[k] = nil end
end
end
 
Line 103:
end
args[k] = nil
end
 
-- Remove empty parameters, if specified
if string.find( ','..(frame.args['$flags'] or '')..',', ',%s*remove%-empty%s*,' ) then
local tmp = 0
for k, v in ipairs( args ) do
if v ~= '' or ( args[k+1] and args[k+1] ~= '' ) or ( args[k+2] and args[k+2] ~= '' ) then
tmp = k
else
break
end
end
for k, v in pairs( args ) do
if v == '' then
if vnot (type(k) == 'number' and k < tmp) then args[k] = nil end
end
end
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu