Jump to content

Module:LACMTA icon

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sameboat (talk | contribs) at 15:21, 1 March 2015 (Created page with 'local getArgs = require('Module:Arguments').getArgs local p = {} local function makeInvokeFunction(funcName) -- makes a function that can be returned from #...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

local function colorbox(color,text,link)
	return '[['..link..'|<span style="background-color:'..color..'" title="'..text..';border:1px solid darkgray;">&nbsp;&nbsp;</span>'
end

local t1 = {
	['Harbor Transitway'] = {'harbor transitway', 'harbor', color='#B8860B', icon='colorbox'},
	['El Monte Busway'] = {'el monte busway', 'el monte', color='#B8AD93', icon='colorbox'},
	['Regional Connector Transit Corridor'] = {'regional connector transit corridor', 'regional connector', 'regional', color='#604020', icon='colorbox'},
	['Orange Line'] = {'orange line', 'orange', icon='img_square', dab=true},
	['Red Line'] = {'red line', 'red', icon='img_circle', dab=true},
	['Purple Line'] = {'purple line', 'purple', icon='img_circle', dab=true},
	['Blue Line'] = {'blue line', 'blue', icon='img_circle', dab=true},
	['Expo Line'] = {'expo line', 'expo', icon='img_circle', dab=true},
	['Green Line'] = {'green line', 'green', icon='img_circle', dab=true},
	['Gold Line'] = {'gold line', 'gold', icon='img_circle', dab=true},
	['Crenshaw/LAX Line'] = {'crenshaw/lax line', 'crenshaw/lax', 'crenshaw line', 'crenshaw',  icon='img_circle'},
	['Silver Line'] = {'silver line', 'silver', icon='img_square', dab=true},
}

p.icon = makeInvokeFunction('_icon')
 
function p.icon(args)
	local result, link
	local code = args[1]
	local text = args[2] or ''
	if text then text = '&nbsp;('..text..')' end
	local showtext = args.showtext or ''
	for k, v in pairs(t1) do
		for _, name in ipairs(v) do
			if code == name then
				if showtext then
					if v.dab == true then
						link = k..' (Los Angeles Metro)'
						showtext = '&nbsp;[['..link..'|'..k..']]'
					else
						link = k
						showtext = '&nbsp;[['..k..']]'
					end
				end
				if v.icon == 'colorbox' then
					return colorbox(v.color,k,k)..showtext..text
				elseif v.icon == 'img_circle' then
					return '[[File:LACMTA Circle '..k..'.svg|17px|link='..link..'|alt='..link..'|'..link..']]'..showtext..text
				elseif v.icon == 'img_square' then
					return '[[File:LACMTA Square '..k..'.svg|17px|link='..link..'|alt='..link..'|'..link..']]'..showtext..text
				end
			else
				return colorbox('#fff',code,code..' (Los Angeles Metro)')..text
			end
		end
	end
end

return p