Anonymous user
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
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
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,
table.insert(obj.templates, Template.new(invocationObj,
end
Line 500 ⟶ 514:
end
function NowikiInvocation:getInvocation(
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(
local invocation = self:getInvocation(
return mw.getCurrentFrame():preprocess(invocation)
end
Line 536 ⟶ 550:
end
function TableInvocation:getInvocation(
if self.code then
local nowikiObj = NowikiInvocation.new(self.code, self.cfg)
return nowikiObj:getInvocation(
else
return require('Module:Template invocation').invocation(
options.template,
self.invokeArgs
)
Line 548 ⟶ 562:
end
function TableInvocation:getOutput(
return mw.getCurrentFrame():expandTemplate{
title = options.template,
args = self.invokeArgs
}
|