Module:la-noun/table

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local Array = require 'Module:array'

local function add_forms(wikitable, forms)
	if type(wikitable) ~= 'string' then
		error('Expected string, got ' .. type(wikitable))
	end
	
	wikitable = wikitable:gsub('{{{([^}]+)}}}', forms)
	return wikitable
end

local stylesheet = require("Module:TemplateStyles")("Template:la-decl-1st/style.css")

function export.make_table_sg(data)
	local output = Array(data.title, stylesheet)
	output:insert [=[

{| class="wikitable inflection-table inflection-table-la"
|-
! class="corner-header" | Case
! class="number-header" | Singular
|-
! class="case-header" | [[nominative case|Nominative]]
| class="form-cell" | {{{nom_sg}}}
|-
! class="case-header" | [[genitive case|Genitive]]
| class="form-cell" | {{{gen_sg}}}
|-
! class="case-header" | [[dative case|Dative]]
| class="form-cell" | {{{dat_sg}}}
|-
! class="case-header" | [[accusative case|Accusative]]
| class="form-cell" | {{{acc_sg}}}
|-
! class="case-header" | [[ablative case|Ablative]]
| class="form-cell" | {{{abl_sg}}}
|-
! class="case-header" | [[vocative case|Vocative]]
| class="form-cell" | {{{voc_sg}}}
|-]=]
	if data.forms.loc_sg then
		output:insert [=[

! class="case-header" |  [[locative case|Locative]]
| class="form-cell" | {{{loc_sg}}}]=]
	end
	output:insert('\n|}')
	if data.footnotes and data.footnotes ~= "" then
		output:insert('\n' .. data.footnotes)
	end

	return add_forms(output:concat(), data.forms)
end

function export.make_table_pl(data)
	local output = Array(data.title, stylesheet)
	output:insert [=[

{| class="wikitable inflection-table inflection-table-la"
|-
! class="corner-header" | Case
! class="number-header" | Plural
|-
! class="case-header" | [[nominative case|Nominative]]
| class="form-cell" | {{{nom_pl}}}
|-
! class="case-header" | [[genitive case|Genitive]]
| class="form-cell" | {{{gen_pl}}}
|-
! class="case-header" | [[dative case|Dative]]
| class="form-cell" | {{{dat_pl}}}
|-
! class="case-header" | [[accusative case|Accusative]]
| class="form-cell" | {{{acc_pl}}}
|-
! class="case-header" | [[ablative case|Ablative]]
| class="form-cell" | {{{abl_pl}}}
|-
! class="case-header" | [[vocative case|Vocative]]
| class="form-cell" | {{{voc_pl}}}
|-
]=]
	if data.forms.loc_pl then
		output:insert [=[

! class="case-header" |  [[locative case|Locative]]
| class="form-cell" | {{{loc_pl}}}]=]
	end
	output:insert('\n|}')
	if data.footnotes and data.footnotes ~= "" then
		output:insert('\n' .. data.footnotes)
	end
	
	return add_forms(output:concat(), data.forms)
end

function export.make_table(data)
	local output = Array(data.title, stylesheet)
	output:insert [=[

{| class="wikitable inflection-table inflection-table-la"
|-
! class="corner-header" | Case
! class="number-header" | Singular
! class="number-header" | Plural
|-
! class="case-header" | [[nominative case|Nominative]]
| class="form-cell" | {{{nom_sg}}}
| class="form-cell" | {{{nom_pl}}}
|-
! class="case-header" | [[genitive case|Genitive]]
| class="form-cell" | {{{gen_sg}}}
| class="form-cell" | {{{gen_pl}}}
|-
! class="case-header" | [[dative case|Dative]]
| class="form-cell" | {{{dat_sg}}}
| class="form-cell" | {{{dat_pl}}}
|-
! class="case-header" | [[accusative case|Accusative]]
| class="form-cell" | {{{acc_sg}}}
| class="form-cell" | {{{acc_pl}}}
|-
! class="case-header" | [[ablative case|Ablative]]
| class="form-cell" | {{{abl_sg}}}
| class="form-cell" | {{{abl_pl}}}
|-
! class="case-header" | [[vocative case|Vocative]]
| class="form-cell" | {{{voc_sg}}}
| class="form-cell" | {{{voc_pl}}}
|-]=]
	if data.forms.loc_sg or data.forms.loc_pl then
		output:insert [=[

! class="case-header" |  [[locative case|Locative]]
| class="form-cell" | {{{loc_sg}}}
| class="form-cell" | {{{loc_pl}}}]=]
	end
	output:insert('\n|}')
	if data.footnotes and data.footnotes ~= "" then
		output:insert('\n' .. data.footnotes)
	end
	
	return add_forms(output:concat(), data.forms)
end

return export