Jump to content

Module:Danny B.

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Danny B./doc

-- Test module for [[User:Danny B.]]

local M = {}
------------------------------

function M.concatVals( frame )
    
    local output = ""
    local parentFrame = frame:getParent()
    local templateArgs = parentFrame.args
    local separator = parentFrame.args.separator or frame.args.separator or ', '
    local ampersand = parentFrame.args.ampersand or frame.args.ampersand or ' a '
    
    for key, value in pairs( templateArgs ) do
        output = output .. "[" .. key .. "]=\"" .. value .. "\""
    end

--    output = table.concat( templateArgs, separator )
    
    return output
    
end -- function concatVals


function M.paramTest( frame )
    
    local output
    local moduleArgs = frame.args
    local parentFrame = frame:getParent()
    local templateArgs = parentFrame.args
    
    output = "module args: "
    for key, value in pairs( moduleArgs ) do
        output = output .. "[" .. key .. "]=\"" .. value .. "\""
    end

    output = output .. "template args: "
    for key, value in pairs( templateArgs ) do
        output = output .. "[" .. key .. "]=\"<nowiki>" .. value .. "</nowiki>\""
    end

--[[
    if( templateArgs.named ) then
        output = "Named='" .. templateArgs.named .. "'"
    elseif ( templateArgs[1] ) then
        output = "Numbered='" .. templateArgs[1] .. "'"
    else
        output = "No param"
    end
--]]
    output = frame:preprocess( output )
    return output
    
end -- function M.paramTest


function M.testArg( frame )
    local parentFrame = frame:getParent()
    local output = parentFrame:getArgument( "1" )
    return output
end

function M.testArgs( frame )
    local parentFrame = frame:getParent()
    local output = ( parentFrame:getArgument( "1" ) or parentFrame:getArgument( "test" )):expand()
    return output
end

function split( str, separator )
    
	if not separator or separator == "" then
		return false
	end
	
    local position = 0
	local output = {}
	
	for sepBegin, sepEnd in function() return mw.ustring.find( str, separator, position, true ) end do
		table.insert( output, mw.ustring.sub( str, position, sepBegin-1 ) )
		position = sepEnd + 1
	end
	
	table.insert( output, mw.ustring.sub( str, position ) )
	
	return output
	
end -- function split

function numberedArgs( args )
	
	local output = {}
	local index = 1
	
	while args[index] ~= nil do
		
		local arg = args[index]
		
		output[index] = arg
		
		index = index + 1
		
	end
	
	return output
	
end


function M.pipeConcat( frame )
    
    local output
    local moduleArgs = frame.args
    local parentFrame = frame:getParent()
    local templateArgs = parentFrame.args
    local numberedArgs = numberedArgs( templateArgs )

    output = table.concat( numberedArgs, "<!-- sep -->" )
--    output = frame:preprocess( output )
    return output
    
end -- function M.pipeConcat

function M.testPipes( frame )
    
    local output
    local moduleArgs = frame.args
    local parentFrame = frame:getParent()
    local templateArgs = parentFrame.args
    
    output = table.concat( split( templateArgs["pipes"], "<!-- sep -->" ), "<br />\n" )
    
    output = frame:preprocess( output )
    return output
    
end -- function M.pipeConcat


function M.testSubst( frame )
    
    local moduleArgs = frame.args
    
    return ( moduleArgs["1"] == moduleArgs["2"] and "no" or "yes" ) .. "<pre>[" .. moduleArgs["1"] .."]\n[" .. moduleArgs["2"] .. "]\n[" .. ( moduleArgs["3"] or "-" ) .. "]</pre>"
    
end -- function M.testSubst


------------------------------
return M