Module:la-noun/table

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search
Text-x-generic with pencil.svg 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 function get_stylesheet()
	return mw.getCurrentFrame():extensionTag{
		name = "templatestyles", args = { src = "Template:la-decl-1st/style.css" }
	}
end

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

{| class="prettytable 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|}' .. data.footnote)
	
	return add_forms(output:concat(), data.forms)
end

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

{| class="prettytable 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|}' .. data.footnote)
	
	return add_forms(output:concat(), data.forms)
end

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

{| class="prettytable 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|}' .. data.footnote)
	
	return add_forms(output:concat(), data.forms)
end

return export