Module:TemplateStarter: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 85: | Line 85: | ||
-- Main function to be called from wiki (for testing/preview) | -- Main function to be called from wiki (for testing/preview) | ||
function p.main(frame) | function p.main(frame) | ||
local | -- Simple validation without complex error handling for this function | ||
local args = frame.args | |||
local parent = frame:getParent() | |||
local pargs = parent and parent.args or {} | |||
-- Get parameters (check both direct and parent args) | |||
local articleName = args.articleName or pargs.articleName or args[1] or pargs[1] | |||
local templateType = args.templateType or pargs.templateType or args[2] or pargs[2] | |||
-- Validate inputs | |||
if not articleName or mw.text.trim(tostring(articleName)) == "" then | |||
return "Error: Article name is required" | |||
end | end | ||
if not templateType or mw.text.trim(tostring(templateType)) == "" then | |||
return "Error: Template type is required" | |||
return "Error: " | |||
end | end | ||
-- Generate the template content | -- Generate the template content | ||
local content = p.generateTemplate( | local content = p.generateTemplate(mw.text.trim(tostring(templateType))) | ||
-- For testing, return the generated content in a pre block | -- For testing, return the generated content in a pre block | ||
return string.format('<pre>Page: %s\n\n%s</pre>', | return string.format('<pre>Page: %s\n\n%s</pre>', | ||
mw.text.nowiki( | mw.text.nowiki(mw.text.trim(tostring(articleName))), | ||
mw.text.nowiki(content)) | mw.text.nowiki(content)) | ||
end | end | ||
| Line 150: | Line 133: | ||
end | end | ||
-- | -- Simple approach without complex error handling | ||
local | local templates = {} | ||
-- | -- Check if ConfigRepository.templates exists | ||
if ConfigRepository.templates then | |||
local index = 1 | local index = 1 | ||
for templateName, _ in pairs(ConfigRepository.templates) do | for templateName, _ in pairs(ConfigRepository.templates) do | ||
| Line 177: | Line 145: | ||
end | end | ||
end | end | ||
table.sort(templates) | table.sort(templates) | ||
end | end | ||
-- | -- Fallback to basic list if no templates found | ||
if #templates == 0 then | |||
templates = {"Person", "Organization", "Event", "TLD", "Process", "Norm", "LibraryInterview"} | templates = {"Person", "Organization", "Event", "TLD", "Process", "Norm", "LibraryInterview"} | ||
end | end | ||