Module:Rail-interchange multi

This is an old revision of this page, as edited by Jc86035 (talk | contribs) at 09:28, 30 May 2015. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
 
local p = {}
 
local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Module:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return p[funcName](args)
	end
end

p.row = makeInvokeFunction('_row')
function p._row(args)
	local somelist = args[1] or frame.args[1]
	local result
	result = ''
	para1 = ''
	para2 = ''
	for k1, v1 in ipairs(mw.text.split(somelist, '\n')) do
		for k2, v2 in ipairs(mw.text.split(v1 .. '\\', '\\')) do
			if k2 > 2 then break
				elseif (k2 % 2 == 1) then
					if (k1 % 2 == 0) then
						para1 = v2
					else para1 = v2
					end
				elseif (k2 % 2 == 0) then para2 = v2
					result = result .. frame:expandTemplate{ title = 'Rail-interchange', args = { para1, para2 } }

			end
		end
	end
	result = '<div style="display: table-cell; vertical-align: middle; padding-left: 3px; white-space: nowrap;">' .. result .. '</div>'
	return result
end
 
return p