Module:Documentation: Difference between revisions
get rid of the env:grab function
m>Mr. Stradivarius (use the err function for all the errors) |
m>Mr. Stradivarius (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 = envFunc | local success, val = pcall(envFunc) | ||
env[key] = val | if success then | ||
env[key] = val -- Memoise the value. | |||
return val | |||
end | |||
end | end | ||
return nil | |||
end | end | ||
}) | }) | ||
Line 231: | Line 232: | ||
local title = env.title | local title = env.title | ||
local subpage = title.subpageText | local subpage = title.subpageText | ||
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 | ||
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')) | |||
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')) | |||
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')) | |||
end | end | ||
Line 381: | Line 357: | ||
local data = {} | local data = {} | ||
-- Get title objects. | -- Get title objects. | ||
local | local title = env.title | ||
local docTitle = env.docTitle | |||
if not title or not docTitle then | |||
return nil | |||
local | |||
if | |||
return | |||
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 | ||
if not subjectSpace then | |||
return nil | |||
end | |||
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 | return nil | ||
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 | return nil | ||
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 | ||
local sandboxTitle = env.sandboxTitle | |||
local testcasesTitle = env.testcasesTitle | |||
if not templateTitle or not sandboxTitle or not testcasesTitle then | |||
local | return nil | ||
local | |||
if not | |||
return | |||
end | end | ||
-- Make links. | -- Make links. |