Difference between revisions of "Module:Sandbox/Andy M. Wang"

From blackwiki
Jump to navigation Jump to search
blackwiki>Andy M. Wang
(%p was too generic)
blackwiki>Andy M. Wang
(fullstopendings specified. return to take a look)
Line 34: Line 34:
 
end
 
end
 
local text = 'For ' .. firstArg .. ', see ' .. links
 
local text = 'For ' .. firstArg .. ', see ' .. links
local i, j = string.find(text, "(%.|%?|%!)%]%]$")
+
 
return text .. ' -> ' .. tostring(i) .. ' ' .. tostring(j)
+
local nonFullStopEndings = { "%.%]%]$", "%?%]%]$", "%!%]%]$" }
 +
return nonFullStopEndings[1]
 +
 
 +
--local i, j = string.find(text, "(%.|%?|%!)%]%]$")
 +
 
 +
--return text .. ' -> ' .. tostring(i) .. ' ' .. tostring(j)
 
--return mHatnote._hatnote(text)
 
--return mHatnote._hatnote(text)
 
end
 
end
  
 
return p
 
return p

Revision as of 21:02, 2 May 2016

Template:NOINDEX

A longer-term module sandbox for testing.


local mHatnote = require('Module:Hatnote')
local mArguments -- lazily initialise

local p = {}

function p.forfun(frame)
	mArguments = require('Module:Arguments')
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local pages = {}
	local firstArg = (args[1] and args[1]) or 'other uses'
	for k, v in pairs(args) do
		if type(k) == 'number' then
			if k ~= 1 then
				pages[k - 1] = v
			end
		end
	end
	return p._for(mw.title.getCurrentTitle().text, firstArg, unpack(pages))
end

function p._for(titleText, firstArg, ...)
	local links = mHatnote.formatPages(...)
	--Module:See also behavior
	--links = mw.text.listToText(links)
	--Oxford comma
	if table.getn(links) <= 2 then
		links = mw.text.listToText(links, ' and ')
	else
		links = mw.text.listToText(links, ', ', ', and ')
	end
	if links == '' then
		links = mHatnote._formatLink(
			mw.title.getCurrentTitle().text .. ' (disambiguation)')
	end
	local text = 'For ' .. firstArg .. ', see ' .. links

	local nonFullStopEndings = { "%.%]%]$", "%?%]%]$", "%!%]%]$" }
	return nonFullStopEndings[1]

	--local i, j = string.find(text, "(%.|%?|%!)%]%]$")

	--return text .. ' -> ' .. tostring(i) .. ' ' .. tostring(j)
	--return mHatnote._hatnote(text)
end

return p