Module:Jcon/documentation

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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.