Module:Link: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
No edit summary
Line 1: Line 1:
local str = {}
local p = {}


local function link( content, title, linkType, linkSubtype )
local function link( content, title, linkType, linkSubtype )
Line 10: Line 10:
end
end


-- local function linkAlbum( content, title, albumType )
function p._link(content, kind)
-- for _i, subject in ipairs({ 'Gish', 'Siamese Dream', 'Mellon Collie and the Infinite Sadness' }) do
local t = {}
-- local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|'
for s in string.gmatch(content, "([^,]+)") do
-- content = mw.ustring.gsub( content, subject, '[[:' .. cat_str .. subject .. ']][[' .. cat_str .. title .. ']]' )
s = mw.text.trim(s)
-- end
if kind == 'album' then
s = "''[[" .. s .. "]]''"
elseif kind == 'song' then
s = '"[[' .. s .. ']]"'
end
table.insert(t, s)
end
 
local ret = ''
for _i, s in pairs(t) do
ret = ret .. ', ' .. s
end
-- return content
return mw.text.trim(ret, ', ')
-- end
end


function str.album( frame )
function p.album( frame )
local content = frame.args[1]
local content = frame.args[1]
local title = frame.args[2]
local albumType = frame.args[3]
if content == '' then
if content == '' then
return content
return content
end
end
return p._album(content, album)
end
end


function str.producer( frame )
function p.producer( frame )
local content = frame.args[1]
local content = frame.args[1]
local title = frame.args[2]
local title = frame.args[2]
Line 39: Line 49:
end
end


function str.writer( frame )
function p.writer( frame )
local content = frame.args[1]
local content = frame.args[1]
local title = frame.args[2]
local title = frame.args[2]
Line 50: Line 60:
end
end


return str
return p

Revision as of 15:49, 17 June 2020

Documentation for this module may be created at Module:Link/doc

local p = {}

local function link( content, title, linkType, linkSubtype )
	for _i, subject in ipairs({ 'Billy Corgan', 'James Iha', "D'arcy Wretzky", 'Jimmy Chamberlin', 'Butch Vig', 'Flood', 'Alan Moulder', 'Kerry Brown', 'Bjorn Thorsrud', 'Nellee Hooper', 'Terry Date', 'Jeff Schroeder', 'Howard Willing', 'Rick Rubin', 'Roy Thomas Baker', 'Brad Wood', 'Dale Griffin', 'Ted de Bono' }) do
		local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|'
		content = mw.ustring.gsub( content, subject, '[[:' .. cat_str .. subject .. ']][[' .. cat_str .. title .. ']]' )
	end
	
	return content
end

function p._link(content, kind)
	local t = {}
	for s in string.gmatch(content, "([^,]+)") do
		s = mw.text.trim(s)
		if kind == 'album' then
			s = "''[[" .. s .. "]]''"
		elseif kind == 'song' then
			s = '"[[' .. s .. ']]"'
		end
		table.insert(t, s)
	end

	local ret = ''
	for _i, s in pairs(t) do
		ret = ret .. ', ' .. s
	end
	
	return mw.text.trim(ret, ', ')
end

function p.album( frame )
	local content = frame.args[1]
	if content == '' then
		return content
	end
	return p._album(content, album)
end

function p.producer( frame )
	local content = frame.args[1]
	local title = frame.args[2]
	local linkType = frame.args[3]
	if content == '' then
		return content
	end

	return link(content, title, linkType, 'produced')
end

function p.writer( frame )
	local content = frame.args[1]
	local title = frame.args[2]
	local linkType = frame.args[3]
	if content == '' then
		return content
	end

	return link(content, title, linkType, 'written')
end

return p