Module:Link: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
No edit summary
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
local str = {}
local str = {}


function str.producer( content )
function str.producer( frame )
-- if content == '' then
local new_args = str._getParameters( frame.args, { 'source' } )
-- return content
local content = new_args['source'] or ''
-- end
if content == '' then
return content
end


-- for _i, subject in ipairs({ 'Billy Corgan', 'Butch Vig' }) do
for _i, subject in ipairs({ 'Billy Corgan', 'Butch Vig' }) do
-- mw.ustring.gsub( content, subject, '[[:Category:Songs produced by ' .. subject .. '|' .. subject .. ']]' )
mw.ustring.gsub( content, subject, '[[:Category:Songs produced by ' .. subject .. '|' .. subject .. ']]' )
-- end
end


return content .. 'foo'
return content
end
 
--[[
Helper function that populates the argument list given that user may need to use a mix of
named and unnamed parameters. This is relevant because named parameters are not
identical to unnamed parameters due to string trimming, and when dealing with strings
we sometimes want to either preserve or remove that whitespace depending on the application.
]]
function str._getParameters( frame_args, arg_list )
local new_args = {}
local index = 1
local value
 
for _, arg in ipairs( arg_list ) do
value = frame_args[arg]
if value == nil then
value = frame_args[index]
index = index + 1
end
new_args[arg] = value
end
 
return new_args
end
end


return str
return str

Revision as of 21:28, 17 April 2020

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

local str = {}

function str.producer( frame )
	local new_args = str._getParameters( frame.args, { 'source' } )
	local content = new_args['source'] or ''
	if content == '' then
		return content
	end

	for _i, subject in ipairs({ 'Billy Corgan', 'Butch Vig' }) do
		mw.ustring.gsub( content, subject, '[[:Category:Songs produced by ' .. subject .. '|' .. subject .. ']]' )
	end

	return content
end

--[[
Helper function that populates the argument list given that user may need to use a mix of
named and unnamed parameters.  This is relevant because named parameters are not
identical to unnamed parameters due to string trimming, and when dealing with strings
we sometimes want to either preserve or remove that whitespace depending on the application.
]]
function str._getParameters( frame_args, arg_list )
	local new_args = {}
	local index = 1
	local value

	for _, arg in ipairs( arg_list ) do
		value = frame_args[arg]
		if value == nil then
			value = frame_args[index]
			index = index + 1
		end
		new_args[arg] = value
	end

	return new_args
end

return str