Difference between revisions of "Module:Adjacent stations/Taiwan High Speed Rail"

From blackwiki
Jump to navigation Jump to search
blackwiki>Szqecs
blackwiki>Szqecs
Line 55: Line 55:
 
end
 
end
 
end
 
end
local b = { -- 'b' for 'border'
+
local s = { -- Styles index
['n'] = 'none; '
+
['w'] = 'style="width: 30%; '
 +
,['tac'] = 'style="text-align: center; '
 +
,['n'] = 'none; '
 
,['0'] = '0px none; '
 
,['0'] = '0px none; '
 
,['1'] = '1px solid #aaa; '
 
,['1'] = '1px solid #aaa; '
Line 65: Line 67:
 
,['r'] = 'border-right: '
 
,['r'] = 'border-right: '
 
}
 
}
local s = { -- 's' for 'style'
+
local style = {
['table'] = 'align="center" style="margin:0.5em auto; font-size:95% clear:both; ' .. b['t'] .. b['0'] .. 'border-collapse: separate;" cellspacing="0" cellpadding="-1"'
+
['table'] = 'align="center" style="margin:0.5em auto; font-size:95% clear:both; ' .. s['t'] .. s['0'] .. 'border-collapse: separate;" cellspacing="0" cellpadding="-1"'
,['header leftcell'] = 'style="width: 30%; ' .. b['br'] .. b['1'] .. b['l'] .. b['n'] .. b['bb'] .. b['n'] .. '"| '
+
,['header leftcell'] = s['w'] .. s['br'] .. s['1'] .. s['l'] .. s['n'] .. s['bb'] .. s['n'] .. '"| '
,['header midcell'] = 'colspan="3" style="' .. b['br'] .. b['n'] .. b['t'] .. b['1'] .. '"| '
+
,['header midcell'] = 'colspan="3" style="' .. s['br'] .. s['n'] .. s['t'] .. s['1'] .. '"| '
,['header rightcell'] = 'style="width: 30%; ' .. b['br'] .. b['1'] .. b['r'] .. b['n'] .. b['bb'] .. b['n'] .. '"| '
+
,['header rightcell'] = s['w'] .. s['br'] .. s['1'] .. s['r'] .. s['n'] .. s['bb'] .. s['n'] .. '"| '
,['body leftcell'] = 'style="text-align: center; ' .. b['l'] .. b['0'] .. b['bb'] .. b['0'] .. b['r'] .. b['1'] .. b['t'] .. b['1'] .. '"| '
+
,['body leftcell'] = s['tac'] .. s['l'] .. s['0'] .. s['bb'] .. s['0'] .. s['r'] .. s['1'] .. s['t'] .. s['1'] .. '"| '
,['body banner'] = 'style="text-align: center; ' .. b['l'] .. b['0'] .. b['bb'] .. b['0'] .. b['r'] .. b['0'] .. b['t'] .. b['1'] .. 'width: 8px; background-color: '
+
,['body banner'] = s['tac'] .. s['l'] .. s['0'] .. s['bb'] .. s['0'] .. s['r'] .. s['0'] .. s['t'] .. s['1'] .. 'width: 8px; background-color: '
,['body midcell'] = 'style="text-align: center; ' .. b['bb'] .. b['0'] .. '"| '
+
,['body midcell'] = s['tac'] .. s['bb'] .. s['0'] .. '"| '
,['body rightcell'] = 'style="text-align: center; ' .. b['l'] .. b['1'] .. b['bb'] .. b['0'] .. b['r'] .. b['0'] .. b['t'] .. b['1'] .. '"| '
+
,['body rightcell'] = s['tac'] .. s['l'] .. s['1'] .. s['bb'] .. s['0'] .. s['r'] .. s['0'] .. s['t'] .. s['1'] .. '"| '
 
}
 
}
 
local row = {
 
local row = {
['start'] = '{| class="wikitable" ' .. s['table']
+
['start'] = '{| class="wikitable" ' .. style['table']
 
,['header'] = '\n|-'
 
,['header'] = '\n|-'
.. '\n! ' .. s['header leftcell'] .. 'Preceding station'
+
.. '\n! ' .. style['header leftcell'] .. 'Preceding station'
.. '\n! ' .. s['header midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
+
.. '\n! ' .. style['header midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
.. '\n! ' .. s['header rightcell'] .. 'Following station'
+
.. '\n! ' .. style['header rightcell'] .. 'Following station'
 
,['body'] = '\n|-'
 
,['body'] = '\n|-'
.. '\n| ' .. s['body leftcell'] .. left .. left_toward
+
.. '\n| ' .. style['body leftcell'] .. left .. left_toward
.. '\n| ' .. s['body banner'] .. '#C35617"|'
+
.. '\n| ' .. style['body banner'] .. '#C35617"|'
.. '\n| ' .. s['body midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
+
.. '\n| ' .. style['body midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
.. '\n| ' .. s['body banner'] .. '#C35617"|'
+
.. '\n| ' .. style['body banner'] .. '#C35617"|'
.. '\n| ' .. s['body rightcell'] .. right .. right_toward
+
.. '\n| ' .. style['body rightcell'] .. right .. right_toward
 
,['end'] = '\n|}'
 
,['end'] = '\n|}'
 
}
 
}

Revision as of 16:20, 19 January 2018

Documentation for this module may be created at Module:Adjacent stations/Taiwan High Speed Rail/doc

local p = {}

function p.l(frame)
	local f = frame.args -- 'f' for 'frame'
	local THSR = {
		'Nangang',
		'Taipei',
		'Banqiao',
		'Taoyuan',
		'Hsinchu',
		'Miaoli',
		'Taichung',
		'Changhua',
		'Yunlin',
		'Chiayi',
		'Tainan',
		'Zuoying',
	}
	local function s_link(x) -- 's' for 'station'
		if x then
			if x == 'Nangang' or x == 'Taipei' or x == 'Banqiao' then
				return '\[\[' .. x .. ' station|' .. x .. '\]\]'
			else
				return '\[\[' .. x .. ' HSR station|' .. x .. '\]\]'
			end
		end
	end
	local index = tonumber(f[2])
	if index then
		if index > 2 and index < #THSR-1 then
			left = s_link(THSR[index-1])
			right = s_link(THSR[index+1])
			left_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[1]) .. '</div>'
			right_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[#THSR]) .. '</div>'
		elseif index == 1 then
			left = '<div style="font-style: italic">Terminus</div>'
			right = s_link(THSR[index+1])
			left_toward = ''
			right_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[#THSR]) .. '</div>'
		elseif index == 2 then
			left = s_link(THSR[index-1])
			right = s_link(THSR[index+1])
			left_toward = '<br><div style="font-size: smaller;font-style: italic">Terminus</div>'
			right_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[#THSR]) .. '</div>'
		elseif index == #THSR-1 then
			left = s_link(THSR[index-1])
			right = s_link(THSR[index+1])
			left_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[1]) .. '</div>'
			right_toward = '<br><div style="font-size: smaller;font-style: italic">Terminus</div>'
		elseif index == #THSR then
			left = s_link(THSR[index-1])
			right = '<div style="font-style: italic">Terminus</div>'
			left_toward = '<br><div style="font-size: smaller;font-style: italic">toward ' .. s_link(THSR[1]) .. '</div>'
			right_toward = ''
		end
	end
	local s = { -- Styles index
		['w'] = 'style="width: 30%; '
		,['tac'] = 'style="text-align: center; '
		,['n'] = 'none; '
		,['0'] = '0px none; '
		,['1'] = '1px solid #aaa; '
		,['br'] = 'border: '
		,['t'] = 'border-top: '
		,['bb'] = 'border-bottom: '
		,['l'] = 'border-left: '
		,['r'] = 'border-right: '
	}
	local style = {
		['table'] = 'align="center" style="margin:0.5em auto; font-size:95% clear:both; ' .. s['t'] .. s['0'] .. 'border-collapse: separate;" cellspacing="0" cellpadding="-1"'
		,['header leftcell'] = s['w'] .. s['br'] .. s['1'] .. s['l'] .. s['n'] .. s['bb'] .. s['n'] .. '"| '
		,['header midcell'] = 'colspan="3" style="' .. s['br'] .. s['n'] .. s['t'] .. s['1'] .. '"| '
		,['header rightcell'] = s['w'] .. s['br'] .. s['1'] .. s['r'] .. s['n'] .. s['bb'] .. s['n'] .. '"| '
		,['body leftcell'] = s['tac'] .. s['l'] .. s['0'] .. s['bb'] .. s['0'] .. s['r'] .. s['1'] .. s['t'] .. s['1'] .. '"| '
		,['body banner'] = s['tac'] .. s['l'] .. s['0'] .. s['bb'] .. s['0'] .. s['r'] .. s['0'] .. s['t'] .. s['1'] .. 'width: 8px; background-color: '
		,['body midcell'] = s['tac'] .. s['bb'] .. s['0'] .. '"| '
		,['body rightcell'] = s['tac'] .. s['l'] .. s['1'] .. s['bb'] .. s['0'] .. s['r'] .. s['0'] .. s['t'] .. s['1'] .. '"| '
	}
	local row = {
		['start'] = '{| class="wikitable" ' .. style['table']
		,['header'] = '\n|-'
			.. '\n! ' .. style['header leftcell'] .. 'Preceding station'
			.. '\n! ' .. style['header midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
			.. '\n! ' .. style['header rightcell'] .. 'Following station'
		,['body'] = '\n|-'
			.. '\n| ' .. style['body leftcell'] .. left .. left_toward
			.. '\n| ' .. style['body banner'] .. '#C35617"|'
			.. '\n| ' .. style['body midcell'] .. '\[\[Taiwan High Speed Rail\]\]'
			.. '\n| ' .. style['body banner'] .. '#C35617"|'
			.. '\n| ' .. style['body rightcell'] .. right .. right_toward
		,['end'] = '\n|}'
	}
	local position = {
		['all'] = row['start'] .. row['header'] .. row['body'] .. row['end']
		,['top'] = row['start'] .. row['header'] .. row['body']
		,['mid'] = row['body']
		,['bottom'] = row['body'] .. row['end']
		,['header mid'] = row['header'] .. row['body']
		,['header bottom'] =  row['header'] .. row['body'] .. row['end']
	}
	return position[f[1]]
end

return p