Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Jcon/documentation

From Wikipedia, the free encyclopedia

require('strict')

local p = {}

local data = mw.loadData('Module:Jcon/data')
local roadData = require('Module:Road data/strings/CAN/ON')
local parser = require('Module:Road data/parser').parser
local TableTools = require('Module:TableTools')

-- Generates a list of supported regions
function p.supported(frame)
	local reverseAliases = {}
	local entries = {}
	local pre = 'Note: All inputs are converted to lowercase by the template and "Region of", "County Road", etc. are striped from the input.'
	local post = 'Table produced by [[Module:Jcon/documentation]] with data from [[Module:Road data/strings/CAN/ON]] ('
		.. frame:expandTemplate{ title = 'edit', args = { 'Module:Road data/strings/CAN/ON' } } .. ').'
	local tableEl = mw.html.create('table'):addClass('wikitable') -- Create output table element
	
	local headerRow = tableEl:tag('tr')
	headerRow:tag('th'):wikitext('Type')
	headerRow:tag('th'):wikitext('Route name')
	
	for name, info in pairs(roadData) do
		if info.alias then
			roadData[name] = mw.loadData('Module:Road data/strings/' .. info.alias.module)[info.alias.type]
		end
	end
	
	local keys = TableTools.keysToList(roadData, function (a, b)
		return string.lower(a) < string.lower(b)
	end)
	
	local valueToGroup = {}
	local groups = {}

	for _, name in ipairs(keys) do
		if string.sub(name, 1, 1) ~= ' ' then
			local info = roadData[name]
			
			if valueToGroup[info] then
				table.insert(groups[valueToGroup[info]], name)
			else
				table.insert(groups, { name })
				valueToGroup[info] = #groups
			end
		end
	end
	
	for name, group in ipairs(groups) do
		local info = roadData[group[1]]
		local typeOut = ''
		
		for _, type in ipairs(group) do
			typeOut = typeOut .. '<code>' .. type .. '</code><br>'
		end
		
		local row = tableEl:tag('tr')
		row:tag('td'):wikitext(typeOut)
		row:tag('td'):wikitext(
			'<code>' .. (type(info.name) == 'table'
				and (info.name.default or info.name[0] or info.name.below or '??')
				or info.name) .. '</code>'
		)
	end
		
	for sign, fileName in pairs(data._signs) do
		local row = tableEl:tag('tr')
		row:tag('td'):wikitext(sign)
		row:tag('td'):wikitext('[[File:' .. fileName .. '|20px]]')
	end

	return pre .. tostring(tableEl) .. post
end

return p