Jump to content

Module:NYC bus link: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
preliminary prose change
m case insensitive city; error message for unrecognized city; fix prose;
Line 5: Line 5:
function p.getLink(frame)
function p.getLink(frame)
local args = getArgs(frame);
local args = getArgs(frame);
local result = {};
local city;
local city;
if 'NYC' == args.city then
args.city = args.city:lower();
if 'nyc' == args.city then
city = 'New York City bus';
city = 'New York City bus';
elseif 'LI' == args.city then
elseif 'li' == args.city then
city = 'Long Island bus';
city = 'Long Island bus';
elseif 'NJ' == args.city then
elseif 'nj' == args.city then
city = 'New Jersey bus';
city = 'New Jersey bus';
else
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">unexpected city: ', args.city, '</span>'})
end
end
local result = {};
for _, name in ipairs (args) do
for _, name in ipairs (args) do
table.insert (result, table.concat ({'[[', name, ' (', city, ')|', name, ']]'}))
table.insert (result, table.concat ({'[[', name, ' (', city, ')|', name, ']]'}))
end
end
if ('yes' == args.prose) or ('y' == args.prose) then
return mw.text.listToText (result);
local prose;
if 'yes' or 'y' == args.prose then
return mw.text.listToText (result, ', ', ' and ');
else
else
return table.concat (result, ', ');
return table.concat (result, ', ');

Revision as of 00:35, 9 July 2018

require('Module:No globals');
local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.getLink(frame)
	local args = getArgs(frame);
	local result = {};
	local city;
	
	args.city = args.city:lower();
	
	if 'nyc' == args.city then
		city = 'New York City bus';
	elseif 'li' == args.city then
		city = 'Long Island bus';
	elseif 'nj' == args.city then
		city = 'New Jersey bus';
	else
		return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">unexpected city: ', args.city, '</span>'})
	end
		
	for _, name in ipairs (args) do
		table.insert (result, table.concat ({'[[', name, ' (', city, ')|', name, ']]'}))
	end
	
	if ('yes' == args.prose) or ('y' == args.prose) then
		return mw.text.listToText (result);
	else
		return table.concat (result, ', ');
	end
end

return p;