Anonymous user
Module:Documentation: Difference between revisions
convert env table to use a metatable so we only process things when we need to; add a grab method and an err function for dealing with errors (main functions need to be converted to use these)
(finish converting existing values to use env table) |
(convert env table to use a metatable so we only process things when we need to; add a grab method and an err function for dealing with errors (main functions need to be converted to use these)) |
||
Line 73:
return '<small style="font-style: normal;">(' .. table.concat(ret, ' | ') .. ')</small>'
end
local function err(msg)
return string.format(
msg,
makeCategoryLink('Documentation template invocations with errors')
)
----------------------------------------------------------------------------
Line 106 ⟶ 114:
function p._main(args)
local env = p.getEnvironment(args)
local success, env = pcall(p.getEnv, args)▼
if not success then▼
▲ return string.format('<strong class="error">[[Module:Documentation]] error: %s</strong>', env) -- If there's an error, env is the error message.
▲ end
local root = htmlBuilder.create()
root
Line 139 ⟶ 142:
----------------------------------------------------------------------------
function p.
-- Returns a table with information about the environment, including the title to use, the subject namespace, etc.
-- This is called from p._main using pcall in case we get any errors from exceeding the expensive function count
Line 149 ⟶ 152:
-- env.docspace - the name of the namespace the title puts its documentation in.
-- env.templatePage - the name of the template page with no namespace or interwiki prefixes.
local env, envFuncs = {}, {}
-- Set up the metatable. If a nil value is called, we call that function in the envFuncs table and memoize it
-- in the env table so we don't have to call any of the functions more than once.
setmetatable(env, {
__index = function (t, key)
local envFunc = envFuncs[key]
local val = envFunc()
env[key] = val
return val
return nil
end
end
})
-- Get the title.
local title
▲ if titleArg then
error(message('titleArgError', 'string', {titleArg}))
end
title = mw.title.getCurrentTitle()▼
end
return title
▲ else
▲ title = mw.title.getCurrentTitle()
end
-- Get the subject namespace number.
function envFuncs.subjectSpace()
end
-- Get the name of the documentation namespace.
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
-- Pages in the Article, File, MediaWiki or Category namespaces must have their
-- /doc, /sandbox and /testcases pages in talk space.
▲ else
end
end
-- Get the template page with no namespace or interwiki prefixes.
local subpage = title.subpageText
▲ else
else
end
end
function env:grab(key)
return success, val
end
return env
|