Difference between revisions of "Module:Other uses/sandbox"
Jump to navigation
Jump to search
blackwiki>Nihiltres m (Derped on function to use and doubling up the wrapping) |
m (7 revisions imported) |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 12: | Line 12: | ||
mTableTools = require('Module:TableTools') | mTableTools = require('Module:TableTools') | ||
local args = mTableTools.compressSparseArray(mArguments.getArgs(frame)) | local args = mTableTools.compressSparseArray(mArguments.getArgs(frame)) | ||
| − | local title = mw.title.getCurrentTitle(). | + | local title = mw.title.getCurrentTitle().prefixedText |
return p._otheruses(args, {title=title}) | return p._otheruses(args, {title=title}) | ||
| + | end | ||
| + | |||
| + | -- Produces standard {{other uses2}} implementation | ||
| + | function p.otheruses2(frame) | ||
| + | if (not frame:getParent().args[1]) then | ||
| + | return mHatnote.makeWikitextError( | ||
| + | "No target provided", | ||
| + | "Template:Other uses2#Error", | ||
| + | frame:getParent().args["category"] | ||
| + | ) | ||
| + | end | ||
| + | return p._otheruses({}, {title = frame:getParent().args[1]}) | ||
| + | end | ||
| + | |||
| + | --Implements "other [x]" templates with otherText supplied at invocation | ||
| + | function p.otherX(frame) | ||
| + | mArguments = require('Module:Arguments') | ||
| + | mTableTools = require('Module:TableTools') | ||
| + | local x = frame.args[1] | ||
| + | local args = mTableTools.compressSparseArray( | ||
| + | mArguments.getArgs(frame, {parentOnly = true}) | ||
| + | ) | ||
| + | local options = { | ||
| + | title = mw.title.getCurrentTitle().prefixedText, | ||
| + | otherText = x | ||
| + | } | ||
| + | return p._otheruses(args, options) | ||
end | end | ||
| Line 25: | Line 52: | ||
error('No default title data provided in "_otheruses" options table', 2) | error('No default title data provided in "_otheruses" options table', 2) | ||
end | end | ||
| − | if | + | local emptyArgs = true |
| + | for k, v in pairs(args) do | ||
| + | if type(k) == 'number' then emptyArgs = false break end | ||
| + | end | ||
| + | if emptyArgs then | ||
args = { | args = { | ||
options.defaultPage or | options.defaultPage or | ||
| Line 31: | Line 62: | ||
} | } | ||
end | end | ||
| + | --Generate and return hatnote | ||
local text = mHatlist.forSeeTableToString({{ | local text = mHatlist.forSeeTableToString({{ | ||
use = options.otherText and "other " .. options.otherText or nil, | use = options.otherText and "other " .. options.otherText or nil, | ||
Latest revision as of 08:12, 27 September 2020
Documentation for this module may be created at Module:Other uses/sandbox/doc
local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mTableTools --initialize lazily
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local p = {}
-- Produces standard {{other uses}} implementation
function p.otheruses(frame)
mArguments = require('Module:Arguments')
mTableTools = require('Module:TableTools')
local args = mTableTools.compressSparseArray(mArguments.getArgs(frame))
local title = mw.title.getCurrentTitle().prefixedText
return p._otheruses(args, {title=title})
end
-- Produces standard {{other uses2}} implementation
function p.otheruses2(frame)
if (not frame:getParent().args[1]) then
return mHatnote.makeWikitextError(
"No target provided",
"Template:Other uses2#Error",
frame:getParent().args["category"]
)
end
return p._otheruses({}, {title = frame:getParent().args[1]})
end
--Implements "other [x]" templates with otherText supplied at invocation
function p.otherX(frame)
mArguments = require('Module:Arguments')
mTableTools = require('Module:TableTools')
local x = frame.args[1]
local args = mTableTools.compressSparseArray(
mArguments.getArgs(frame, {parentOnly = true})
)
local options = {
title = mw.title.getCurrentTitle().prefixedText,
otherText = x
}
return p._otheruses(args, options)
end
-- Main generator
function p._otheruses(args, options)
--Type-checks and defaults
checkType('_otheruses', 1, args, 'table', true)
args = args or {}
checkType('_otheruses', 2, options, 'table')
if not (options.defaultPage or options.title) then
error('No default title data provided in "_otheruses" options table', 2)
end
local emptyArgs = true
for k, v in pairs(args) do
if type(k) == 'number' then emptyArgs = false break end
end
if emptyArgs then
args = {
options.defaultPage or
mHatnote.disambiguate(options.title, options.disambiguator)
}
end
--Generate and return hatnote
local text = mHatlist.forSeeTableToString({{
use = options.otherText and "other " .. options.otherText or nil,
pages = args
}})
return mHatnote._hatnote(text)
end
return p