Module:Documentation: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(use the err function for all the errors) |
(get rid of the env:grab function) |
||
Line 175: | Line 175: | ||
local envFunc = envFuncs[key] |
local envFunc = envFuncs[key] |
||
if envFunc then |
if envFunc then |
||
local val = |
local success, val = pcall(envFunc) |
||
if success then |
|||
env[key] = val -- Memoise the value. |
|||
return val |
return val |
||
else |
|||
end |
|||
end |
end |
||
⚫ | |||
end |
end |
||
}) |
}) |
||
Line 231: | Line 232: | ||
local title = env.title |
local title = env.title |
||
local subpage = title.subpageText |
local subpage = title.subpageText |
||
local ret |
|||
if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then |
if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then |
||
return title.basePageTitle |
|||
else |
else |
||
return title |
|||
end |
end |
||
⚫ | |||
error(message('titleArgError', 'string', {titleArg})) |
|||
⚫ | |||
⚫ | |||
end |
end |
||
Line 265: | Line 261: | ||
function envFuncs.sandboxTitle() |
function envFuncs.sandboxTitle() |
||
-- Title object for the /sandbox subpage. |
-- Title object for the /sandbox subpage. |
||
return mw.title.new(env.docpageRoot .. '/' .. message('sandboxSubpage', 'string')) |
|||
local title = mw.title.new(titleArg) |
|||
⚫ | |||
error(message('titleArgError', 'string', {titleArg})) |
|||
end |
|||
⚫ | |||
end |
end |
||
function envFuncs.testcasesTitle() |
function envFuncs.testcasesTitle() |
||
-- Title object for the /testcases subpage. |
-- Title object for the /testcases subpage. |
||
return mw.title.new(env.docpageRoot .. '/' .. message('testcasesSubpage', 'string')) |
|||
local title = mw.title.new(titleArg) |
|||
if not title then |
|||
error(message('titleArgError', 'string', {titleArg})) |
|||
end |
|||
⚫ | |||
end |
end |
||
function envFuncs.printTitle() |
function envFuncs.printTitle() |
||
-- Title object for the /Print subpage. |
-- Title object for the /Print subpage. |
||
return mw.title.new(env.templatePage .. '/' .. message('printSubpage', 'string')) |
|||
local title = mw.title.new(titleArg) |
|||
if not title then |
|||
error(message('titleArgError', 'string', {titleArg})) |
|||
end |
|||
⚫ | |||
end |
|||
function env:grab(key) |
|||
local success, val = pcall(function() return self[key] end) |
|||
⚫ | |||
end |
end |
||
Line 381: | Line 357: | ||
local data = {} |
local data = {} |
||
-- Get title objects. |
-- Get title objects. |
||
local |
local title = env.title |
||
⚫ | |||
if titleSuccess then |
|||
⚫ | |||
data.title = title |
|||
⚫ | |||
else |
|||
⚫ | |||
end |
|||
local docTitleSuccess, docTitle = env:grab('docTitle') |
|||
if docTitleSuccess then |
|||
⚫ | |||
else |
|||
return err(docTitle) |
|||
end |
end |
||
-- View, display, edit, and purge links if /doc exists. |
-- View, display, edit, and purge links if /doc exists. |
||
Line 433: | Line 402: | ||
function p.makeStartBoxData(args, env, links) |
function p.makeStartBoxData(args, env, links) |
||
local subjectSpace = env.subjectSpace |
local subjectSpace = env.subjectSpace |
||
⚫ | |||
⚫ | |||
⚫ | |||
local data = {} |
local data = {} |
||
Line 506: | Line 478: | ||
function p._content(args, env) |
function p._content(args, env) |
||
-- Get the /doc title object |
-- Get the /doc title object |
||
local |
local docTitle = env.docTitle |
||
if not |
if not docTitle then |
||
⚫ | |||
return err(docTitle) -- docTitle is an error message |
|||
end |
end |
||
-- Get the documentation content. |
-- Get the documentation content. |
||
Line 532: | Line 504: | ||
-- Get environment data. |
-- Get environment data. |
||
local subjectSpace = env.subjectSpace |
local subjectSpace = env.subjectSpace |
||
local |
local docTitle = env.docTitle |
||
if not |
if not subjectSpace or not docTitle then |
||
return |
return nil |
||
end |
end |
||
Line 594: | Line 566: | ||
function p.makePrintBlurb(args, env) |
function p.makePrintBlurb(args, env) |
||
-- Get the /Print title object |
-- Get the /Print title object |
||
local |
local printTitle = env.printTitle |
||
if not |
if not printTitle then |
||
return |
return nil |
||
end |
end |
||
-- Make the print blurb. |
-- Make the print blurb. |
||
Line 613: | Line 585: | ||
function p.makeSubpagesBlurb(args, env) |
function p.makeSubpagesBlurb(args, env) |
||
-- Get the template title object |
-- Get the template title object |
||
local |
local templateTitle = env.templateTitle |
||
if not |
if not templateTitle then |
||
⚫ | |||
return err(templateTitle) -- Error message. |
|||
end |
end |
||
-- Make the subpages blurb. |
-- Make the subpages blurb. |
||
Line 634: | Line 606: | ||
function p.makeCategoriesBlurb(args, env) |
function p.makeCategoriesBlurb(args, env) |
||
-- Get the title object. |
-- Get the title object. |
||
local |
local docTitle = env.docTitle |
||
if not |
if not docTitle then |
||
return |
return nil |
||
end |
end |
||
-- Make the blurb. |
-- Make the blurb. |
||
Line 645: | Line 617: | ||
function p.makeDocPageBlurb(args, env) |
function p.makeDocPageBlurb(args, env) |
||
-- Get the title object. |
-- Get the title object. |
||
local |
local docTitle = env.docTitle |
||
if not |
if not docTitle then |
||
return |
return nil |
||
end |
end |
||
-- Make the blurb. |
-- Make the blurb. |
||
Line 680: | Line 652: | ||
local templatePage = env.templatePage |
local templatePage = env.templatePage |
||
-- Get title objects. |
-- Get title objects. |
||
local |
local templateTitle = env.templateTitle |
||
⚫ | |||
if not templateSuccess then |
|||
⚫ | |||
return err(templateTitle) |
|||
if not templateTitle or not sandboxTitle or not testcasesTitle then |
|||
end |
|||
⚫ | |||
⚫ | |||
if not sandboxSuccess then |
|||
return err(sandboxTitle) |
|||
end |
|||
⚫ | |||
if not testcasesSuccess then |
|||
return err(testcasesTitle) |
|||
end |
end |
||
-- Make links. |
-- Make links. |