Module:Template test case: Difference between revisions

don't require __TEMPLATENAME__ magic word for nowiki invocations if there is only one template being displayed
(fix bad variable name)
(don't require __TEMPLATENAME__ magic word for nowiki invocations if there is only one template being displayed)
Line 138:
 
function Template:getInvocation(format)
local invocation = self._invocation:getInvocation(self:getName()){
template = self:getName(),
requireMagicWord = self.requireMagicWord,
}
if format == 'code' then
invocation = '<code>' .. mw.text.nowiki(invocation) .. '</code>'
Line 153 ⟶ 156:
 
function Template:getOutput()
return self._invocation:getOutput(self:getName()){
template = self:getName(),
requireMagicWord = self.requireMagicWord,
}
end
 
Line 264 ⟶ 270:
return ret
end)(templateOptions)
 
-- Don't require the __TEMPLATENAME__ magic word for nowiki invocations if
-- there is only one template being output.
if #templateOptions <= 1 then
templateOptions[1].requireMagicWord = false
end
 
mw.logObject(templateOptions)
 
-- Make the template objects
obj.templates = {}
for i, toptions in ipairs(templateOptions) do
table.insert(obj.templates, Template.new(invocationObj, toptions))
end
 
Line 500 ⟶ 514:
end
 
function NowikiInvocation:getInvocation(templateoptions)
local template = options.template:gsub('%%', '%%%%') -- Escape "%" with "%%"
local invocation, count = self.invocation:gsub(
self.cfg.templateNameMagicWordPattern,
template
)
if options.requireMagicWord ~= false and count < 1 then
error(self:message(
'nowiki-magic-word-error',
Line 515 ⟶ 529:
end
 
function NowikiInvocation:getOutput(templateoptions)
local invocation = self:getInvocation(templateoptions)
return mw.getCurrentFrame():preprocess(invocation)
end
Line 536 ⟶ 550:
end
 
function TableInvocation:getInvocation(templateoptions)
if self.code then
local nowikiObj = NowikiInvocation.new(self.code, self.cfg)
return nowikiObj:getInvocation(templateoptions)
else
return require('Module:Template invocation').invocation(
options.template,
self.invokeArgs
)
Line 548 ⟶ 562:
end
 
function TableInvocation:getOutput(templateoptions)
return mw.getCurrentFrame():expandTemplate{
title = options.template,
args = self.invokeArgs
}