Module:Template test case: Difference between revisions

add the option defaults before we compress the table to fix the case where the first numbered argument is higher than 2
(fix error message for missing template parameters and remove dependency on Module:TableTools)
(add the option defaults before we compress the table to fix the case where the first numbered argument is higher than 2)
Line 155:
obj.cfg = cfg
 
-- Separate numberedgeneral andoptions namedfrom template options. Template options are
-- numbered, whereas general options are not.
local generalOptions, templateOptions = {}, {}
do
-- Separate numbered and named options
local optionNum = {} -- a unique key for option numbers inside templateOptions
local rawTemplateOptions = {}
Line 175:
end
end
 
-- Add default template options
rawTemplateOptions[1] = rawTemplateOptions[1] or {}
rawTemplateOptions[2] = rawTemplateOptions[2] or {}
if templateOptionsrawTemplateOptions[1].template and not templateOptionsrawTemplateOptions[2].template then
templateOptions rawTemplateOptions[2].template = templateOptionsrawTemplateOptions[1].template ..
'/' .. obj.cfg.sandboxSubpage
end
if not templateOptionsrawTemplateOptions[1].template then
templateOptions rawTemplateOptions[1].title = mw.title.getCurrentTitle().basePageTitle
end
if not templateOptionsrawTemplateOptions[2].template then
templateOptions rawTemplateOptions[2].title = templateOptionsrawTemplateOptions[1].title:subPageTitle(
obj.cfg.sandboxSubpage
)
end
 
-- Remove gaps in the numbered options
local nums = {}
Line 184 ⟶ 201:
templateOptions[i] = rawTemplateOptions[num]
end
 
-- Check that there are no missing template options.
for i = 3, #templateOptions do -- Defaults arehave addedalready laterbeen added for 1 and 2.
local t = templateOptions[i]
if not t.template then
Line 201 ⟶ 219:
generalOptions.collapsible = yesno(generalOptions.collapsible)
obj.options = generalOptions
 
-- 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 ..
'/' .. obj.cfg.sandboxSubpage
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(
obj.cfg.sandboxSubpage
)
end
 
-- Make the template objects