Module:Template test case: Difference between revisions
(comment tweak and add a todo item) |
(if the first template is specified but the second is not, make the second the sandbox of the first rather than the sandbox of the base page; simplify the title-getting code in the process) |
||
Line 15: | Line 15: | ||
Template.__index = Template | Template.__index = Template | ||
function Template.new(invocationObj, options | function Template.new(invocationObj, options) | ||
local obj = setmetatable({}, Template) | local obj = setmetatable({}, Template) | ||
Line 24: | Line 24: | ||
obj.invocation = invocationObj | obj.invocation = invocationObj | ||
-- Validate | -- Validate input | ||
if not obj.template | if not obj.template and not obj.title then | ||
error('no template or title specified', 2) | |||
end | end | ||
Line 127: | Line 123: | ||
local templateOptions = mTableTools.numData(options, true) | local templateOptions = mTableTools.numData(options, true) | ||
obj.options = templateOptions.other or {} | obj.options = templateOptions.other or {} | ||
-- Add default template options | |||
templateOptions[1] = templateOptions[1] or {} | |||
templateOptions[2] = templateOptions[2] or {} | |||
if templateOptions[1].template and not templateOptions[2].template then | |||
templateOptions[2].template = templateOptions[1].template .. '/sandbox' | |||
end | |||
if not templateOptions[1].template then | |||
templateOptions[1].title = mw.title.getCurrentTitle().basePageTitle | |||
end | |||
if not templateOptions[2].template then | |||
templateOptions[2].title = templateOptions[1].title:subPageTitle('sandbox') | |||
end | |||
-- Make the template objects | -- Make the template objects | ||
obj.templates = {} | obj.templates = {} | ||
for i, t in ipairs(templateOptions) do | |||
table.insert(obj.templates, Template.new(invocationObj, t)) | |||
table.insert(obj.templates, Template.new( | |||
end | end | ||