模組:NYCS SSI

被永久保护的模块
维基百科,自由的百科全书
文档图示 模块文档[创建]
local p = {}

local cfg = mw.loadData('Module:NYCS SSI/configuration')

-- trim whitespace
local function trim(s)
	return s:match('^%s*(.-)%s*$')
end

function p._main(args)
	local shorthand = args[1]
	if shorthand then shorthand = trim(shorthand) end 
	
	local return_table
	if cfg[shorthand] and type(cfg[shorthand]) == 'table' then
		return_table = cfg[shorthand]
	elseif cfg[shorthand] and type(cfg[shorthand]) == 'string' then
		return_table = cfg[cfg[shorthand]]
	else
		return_table = cfg.default
	end
	local noimage = args[2]
	if noimage and trim(noimage) ~= '' then return return_table.text end
	
	if not return_table.image then return return_table.image_substitute end

	local text = return_table.text
	local other_text = args['text']
	if other_text and trim(other_text) ~= '' then text = other_text end
	
	return '[[File:' .. return_table.image ..
		'.svg|10px|link=List of New York City Subway services#Time periods|' ..
		text .. ']]'
end

function p.main(frame)
	return p._main(frame:getParent().args)
end

return p