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

function export.make_table_sg(data)
	local output = Array(data.title, mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = '-', palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! singular
|-
! [[nominative case|nominative]]
| {{{nom_sg}}}
|-
! [[genitive case|genitive]]
| {{{gen_sg}}}
|-
! [[dative case|dative]]
| {{{dat_sg}}}
|-
! [[accusative case|accusative]]
| {{{acc_sg}}}
|-
! [[ablative case|ablative]]
| {{{abl_sg}}}
|-
! [[vocative case|vocative]]
| {{{voc_sg}}}
|-]=]
	if data.forms.loc_sg then
		output:insert [=[

! [[locative case|locative]]
| {{{loc_sg}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom' })
	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, mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = '-', palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! plural
|-
! [[nominative case|nominative]]
| {{{nom_pl}}}
|-
! [[genitive case|genitive]]
| {{{gen_pl}}}
|-
! [[dative case|dative]]
| {{{dat_pl}}}
|-
! [[accusative case|accusative]]
| {{{acc_pl}}}
|-
! [[ablative case|ablative]]
| {{{abl_pl}}}
|-
! [[vocative case|vocative]]
| {{{voc_pl}}}
|-
]=]
	if data.forms.loc_pl then
		output:insert [=[

! [[locative case|locative]]
| {{{loc_pl}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom' })
	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, mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = '-', palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! singular
! plural
|-
! [[nominative case|nominative]]
| {{{nom_sg}}}
| {{{nom_pl}}}
|-
! [[genitive case|genitive]]
| {{{gen_sg}}}
| {{{gen_pl}}}
|-
! [[dative case|dative]]
| {{{dat_sg}}}
| {{{dat_pl}}}
|-
! [[accusative case|accusative]]
| {{{acc_sg}}}
| {{{acc_pl}}}
|-
! [[ablative case|ablative]]
| {{{abl_sg}}}
| {{{abl_pl}}}
|-
! [[vocative case|vocative]]
| {{{voc_sg}}}
| {{{voc_pl}}}
|-]=]
	if data.forms.loc_sg or data.forms.loc_pl then
		output:insert [=[

! [[locative case|locative]]
| {{{loc_sg}}}
| {{{loc_pl}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom' })
	if data.footnotes and data.footnotes ~= '' then
		output:insert('\n' .. data.footnotes)
	end
	
	return add_forms(output:concat(), data.forms)
end

return export