%{
--------------------------------------------------------------------------------
--
--  This file is part of the Doxyrest toolkit.
--
--  Doxyrest is distributed under the MIT license.
--  For details see accompanying license.txt file,
--  the public copy of which is also available at:
--  http://tibbo.com/downloads/archive/doxyrest/license.txt
--
--------------------------------------------------------------------------------

local argArray = table.pack(...)
local compound = argArray[1]

local variableSectionName
local functionSectionName
local isClass = compound.compoundKind == "class" or compound.compoundKind == "struct"

if isClass then
	variableSectionName = "Fields"
	functionSectionName = "Methods"
else
	variableSectionName = "Variables"
	functionSectionName = "Functions"
end

local compoundStats = prepareCompound(compound)
}

$(getCompoundTocTree(compound))

%{
local hasDetails =
	compoundStats.hasDocumentedItems or
	compoundStats.hasBriefDocumentation and compoundStats.hasDetailedDocumentation

if hasDetails then
}
Overview
~~~~~~~~

$(getItemBriefDocumentation(compound))

%{
else
}
$(getItemDetailedDocumentation(compound))

%{
end -- if

if #compound.groupArray > 0 or compound.hasGlobalNamespace then
	local groupTree = ""

	for i = 1, #compound.groupArray do
		local item = compound.groupArray[i]
		local targetFileName = getItemFileName(item)

		generateFile(targetFileName, "group.rst.in", item)
		groupTree = groupTree .. getGroupTree(item)
	end -- for

	if compound.hasGlobalNamespace then
		groupTree = groupTree .. getGroupTree(g_globalNamespace)
	end
}
$groupTree

%{
end -- if

if compoundStats.hasItems or isClass then
	includeFile("overview_compound.rst.in", compound, variableSectionName, functionSectionName)
end

if hasDetails then
}
.. _details-$(compound.id):

Detailed Documentation
~~~~~~~~~~~~~~~~~~~~~~

$(getItemDetailedDocumentation(compound))

%{
end -- if

if compoundStats.hasDocumentedVariables then
	includeFile("details_variables.rst.in", compound, variableSectionName)
end

if compoundStats.hasDocumentedFunctions then
	includeFile("details_functions.rst.in", compound, functionSectionName)
end

if #compound.footnoteArray > 0 then
	includeFile("footnotes.rst.in", compound)
end
}
