Difference between revisions of "Module:Road data/browse"
Jump to navigation
Jump to search
blackwiki>Happy5214 (Splitting previous and next route cell functions) |
blackwiki>Happy5214 m (Use correct variables) |
||
| Line 79: | Line 79: | ||
dab = args.previous_dab} | dab = args.previous_dab} | ||
local nextData = {country = country, state = state, county = county, | local nextData = {country = country, state = state, county = county, | ||
| − | type = args.next_type, route = args.next_route, dab = args.next_dab} | + | type = args.next_type, route = args.next_route, |
| + | dab = args.next_dab} | ||
| − | local previousRoute = previousRoute( | + | local previousRoute = previousRoute(previousData) |
| − | local nextRoute = nextRoute( | + | local nextRoute = nextRoute(nextData) |
local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} ) | local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} ) | ||
Revision as of 14:40, 15 June 2014
This module is used by Template:Infobox road (via Module:Infobox road).
Tracking/maintenance category
local p = {}
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local parserModule = require "Module:Road data/parser"
local parser = parserModule.parser
local function size(args)
local country = args.country
local state = args.state or args.province
local type = args.type
if country == 'MEX' then
return "20x30"
elseif country == 'CAN' then
if state == 'AB' or state == 'QC' or state == 'SK' then
return "20x30"
elseif state == 'NS' then
if (type == 'NS' or type == 'Hwy') then
return "18"
else
return "x20"
end
elseif state == 'ON' then
if type == 'ON' or type == 'Hwy' or type == 'Fwy' then
return "20x30"
elseif type == 'CR' or type == 'RR' then
return "30x32"
end
end
return "25x20"
elseif country == 'USA' then
if state == 'NY' and (type == 'NY 1927' or type == 'NY 1948') then
return '20'
end
end
return 'x20'
end
local function shield(args)
local size = size(args)
local shield = parser(args, 'shield')
if not shield or shield == '' then return '' end
return string.format("[[File:%s|%spx|link=|alt=]]", shield, size)
end
local function link(args)
local abbr = parser(args, 'abbr')
local link = parser(args, 'link')
if not link or link == '' then
return mw.ustring.format("<span class=\"nowrap\">%s</span>", abbr)
else
return mw.ustring.format("<span class=\"nowrap\">[[%s|%s]]</span>", link, abbr)
end
end
local function previousRoute(args)
local shieldText = shield(args)
local linkText = link(args)
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "left"} )
cell:wikitext("← " .. shieldText .. ' ' .. linkText)
return cell
end
local function nextRoute(args)
local shieldText = shield(args)
local linkText = link(args)
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "right"} )
cell:wikitext(linkText .. ' ' .. shieldText .. " →")
return cell
end
function p._browse(args)
local browseRow = mw.html.create('tr')
local country = args.country
local state = args.state or args.province
local county = args.county
local previousData = {country = country, state = state, county = county,
type = args.previous_type, route = args.previous_route,
dab = args.previous_dab}
local nextData = {country = country, state = state, county = county,
type = args.next_type, route = args.next_route,
dab = args.next_dab}
local previousRoute = previousRoute(previousData)
local nextRoute = nextRoute(nextData)
local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} )
if args.browse_route then
centerRoute:wikitext("'''" .. args.browse_route .. "'''")
end
browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
return tostring(browseRow)
end
function p.browse(frame)
local args = getArgs(frame)
return p._browse(args)
end
return p