Jump to content

Module:United States legal citation templates

From Wikisource

local p = {} --p stands for package

function tableRow(data, paramMax)
	local templates = {}
	for k, t in pairs(data.templates) do
		table.insert(templates, "{{[[Template:" .. t .. "|" .. t .. "]]}}")
	end
	local templateCell = "<td>" .. table.concat(templates, ", ") .. "</td>"
	
	local parameters = {}
	for k = 1, #data.parameters, 1 do
		if k < #data.parameters then
			table.insert(parameters, "<td>" .. data.parameters[k] .. "</td>")
		else
			table.insert(parameters, "<td colspan='" .. paramMax - k + 1 .. "'>" .. data.parameters[k] .. "</td>")
		end
	end
	
	local description = "<td>" .. data.description .. "</td>"
	
	return "<tr>" .. templateCell .. table.concat(parameters) .. description .. "</tr>"
end

function p.templates_table()
	local rowData = {
		{templates = {"usc-sd"},
		parameters = {'title', '(section)', '(part)', '(chapter)', '(subtitle)', '(subchapter)', '(posttitle)', '(endtext)', '(plainlinks)', '(pipe)'},
		description = "'''[[United States Code]]''' via [[w:Cornell University|Cornell University]]'s [[w:Legal Information Institute|Legal Information Institute]]"},
		{templates = {"UnitedStatesCode", "USC", "usc"},
		parameters = {'title', 'section', '(end of section range)', '(pipe)'},
		description = "USC via Cornell"},
		{templates = {"UnitedStatesCode2", "USC2", "usc2"},
		parameters = {'title', 'section', 'description'},
		description = "USC via Cornell: description of the section"},
		{templates = {"UnitedStatesCodeSec", "USCSec"},
		parameters = {'title', 'section', '(pipe)'},
		description = "USC via Cornell: when citing one of a series of USC sections, where it would be redundant to display the full citation for each section, this template can be used to display only the section number."},
		{templates = {"UnitedStatesCodeSub", "USCSub"},
		parameters = {'title', 'section', '(levels of "sub")'},
		description = "Access to subsection/paragraph/subparagraph/clause/... to allow correct hyperlinking to the anchors embedded in the Cornell pages."},
		{templates = {"USCSub2", "uscsub2"},
		parameters = {'title', 'section', '(levels of "sub")'},
		description = "Combines 'USCSec' and 'USCSub', eliminating redundancy when citing subsections / subparagraphs / &c."},
		{templates = {"usc-clause"},
		parameters = {'title', 'section', 'clause'},
		description = "USC via Cornell: allows clauses"},
		{templates = {"usc-title-chap", "usctc"},
		parameters = {'title', 'chapter', '(subchapter)', '(pipe)'},
		description = "USC via Cornell: title/chapter links"},
		{templates = {"USStat", "usstat"},
		parameters = {'volume', 'page'},
		description = "'''[[United States Statutes at Large|Statutes at Large]]''' via the [[w:Library of Congress|Library of Congress]], the [[w:United States Government Printing Office|Government Printing Office]], or [[w:Google Books|Google Books]]"},
		{templates = {"USPL", "uspl"},
		parameters = {'congress', 'ordinal law'},
		description = "'''[[w:Act of Congress|Public Law]]''' via [[w:United States Government Printing Office|GPO Access]]"},
		{templates = {"USStatute"},
		parameters = {'congress', 'ordinal law', '(volume)', '(page)'},
		description = "Combines {{tl|USPL}} and {{tl|USStat}}, then add optional Year (<nowiki>{{{5}}}</nowiki>), Month (<nowiki>{{{6}}}</nowiki>), Day (<nowiki>{{{7}}}</nowiki>)"},
		{templates = {"USBill"},
		parameters = {'congress', 'bill type (S, SJ, HR, HJ)', 'bill number (1–?)', '(pipe)'},
		description = "'''[[w:United States Congress#Bills and resolutions|Congressional bills]]''' via [[w:THOMAS|THOMAS]]"},
		{templates = {"USHRollCall", "USHVote"},
		parameters = {'year', 'vote'},
		description = "House '''[[w:Roll call#House of Representatives|Roll call vote]]''' via Clerk.House.gov"},
		{templates = {"USSRollCall", "USSVote"},
		parameters = {'congress', 'session', 'vote'},
		description = "Senate '''[[w:Roll call#Senate|Roll call vote]]''' via Senate.gov"},
		{templates = {"USCongRec"},
		parameters = {'year', 'section', 'page', '(date)'},
		description = "'''[[Congressional Record]]''' via [[w:United States Government Printing Office|GPO Access]]"},
		{templates = {"Federal Register", "USFR", "USFedReg"},
		parameters = {'volume', 'page'},
		description = "'''[[Federal Register]]''' via [[w:United States Government Printing Office|GPO Access]]"},
		{templates = {"Federal reporter"},
		parameters = {'series', 'volume', 'case', '(+ optional parameters)'},
		description = "'''[[Federal Reporter]]''' via Wikisource or [http://openjurist.org OpenJurist]"},
		{templates = {"CodeFedReg", "USCFR"},
		parameters = {'volume', 'part', 'section', '(clause)'},
		description = "'''[[Code of Federal Regulations]]''' via [[w:United States Government Printing Office|GPO Access]]"},
		{templates = {"ExecutiveOrder"},
		parameters = {'number'},
		description = "'''[[w:Executive order (United States)|Executive Orders]]''' via [[Wikisource]]"},
		{templates = {"USSG"},
		parameters = {'chapter', 'section'},
		description = "'''[[w:United States Federal Sentencing Guidelines|U.S. Federal Sentencing Guidelines]]''' (2009) via the [[w:United States Sentencing Commission|U.S. Sentencing Commission]] website"},
		{templates = {"USSGSub"},
		parameters = {'chapter', 'section', '(up to 3 levels of "sub")'},
		description = "'''[[w:United States Federal Sentencing Guidelines|U.S. Federal Sentencing Guidelines]]''' (2009) via the [[w:United States Sentencing Commission|U.S. Sentencing Commission]] website"},
	}
	
	local paramMax = 0
	for k, data in pairs(rowData) do
		if #data.parameters > paramMax then
			paramMax = #data.parameters
		end
	end
	
	local tableRows = {}
	for k, data in pairs(rowData) do
		table.insert(tableRows, tableRow(data, paramMax))
	end
	
	local tableStart = "<table class='wikitable' style='margin-right:auto; margin-left:auto; width:100%;' cellpadding='2'>"
	
	local templateHeader = "<th rowspan='2'>Template(s)</th>"
	local descriptionHeader = "<th rowspan='2'>Description</th>"
	local parameterHeader = "<th colspan='" .. paramMax .. "'>Parameter(s)</th>"
	
	local numberedParamsList = {}
	for k = 1, paramMax, 1 do
		table.insert(numberedParamsList, "<th>" .. k .. "</th>")
	end
	local numberedParams = table.concat(numberedParamsList)
	
	local headerTop = "<tr>" .. templateHeader .. parameterHeader .. descriptionHeader .. "</tr>"
	local paramHeaderTop = "<tr>" .. numberedParams .. "</tr>"
	local paramHeaderBottom = "<tr>" .. templateHeader .. numberedParams .. descriptionHeader .. "</tr>"
	local headerBottom = "<tr>" .. parameterHeader .. "</tr>"
	
	return tableStart .. headerTop .. paramHeaderTop .. table.concat(tableRows) .. paramHeaderBottom .. headerBottom .. "</table>"
end

return p