Module:la-noun/table

From Acadēmīa Latīnitātis

Documentation for this module may be created at Module:la-noun/table/doc

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
| class="form-cell" | {{{nom_sg}}}
|-
! class="case-header" | Genitive
| class="form-cell" | {{{gen_sg}}}
|-
! class="case-header" | Dative
| class="form-cell" | {{{dat_sg}}}
|-
! class="case-header" | Accusative
| class="form-cell" | {{{acc_sg}}}
|-
! class="case-header" | Ablative
| class="form-cell" | {{{abl_sg}}}
|-
! class="case-header" | Vocative
| class="form-cell" | {{{voc_sg}}}
|-]=]
	if data.forms.loc_sg then
		output:insert [=[

! class="case-header" |  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
| class="form-cell" | {{{nom_pl}}}
|-
! class="case-header" | Genitive
| class="form-cell" | {{{gen_pl}}}
|-
! class="case-header" | Dative
| class="form-cell" | {{{dat_pl}}}
|-
! class="case-header" | Accusative
| class="form-cell" | {{{acc_pl}}}
|-
! class="case-header" | Ablative
| class="form-cell" | {{{abl_pl}}}
|-
! class="case-header" | Vocative
| class="form-cell" | {{{voc_pl}}}
|-
]=]
	if data.forms.loc_pl then
		output:insert [=[

! class="case-header" |  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
| class="form-cell" | {{{nom_sg}}}
| class="form-cell" | {{{nom_pl}}}
|-
! class="case-header" | Genitive
| class="form-cell" | {{{gen_sg}}}
| class="form-cell" | {{{gen_pl}}}
|-
! class="case-header" | Dative
| class="form-cell" | {{{dat_sg}}}
| class="form-cell" | {{{dat_pl}}}
|-
! class="case-header" | Accusative
| class="form-cell" | {{{acc_sg}}}
| class="form-cell" | {{{acc_pl}}}
|-
! class="case-header" | Ablative
| class="form-cell" | {{{abl_sg}}}
| class="form-cell" | {{{abl_pl}}}
|-
! class="case-header" | 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
| 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