In typical LaTeX documents, the document content is typed inside the document environment, which is usually the last thing in the file:
\documentclass{article}
\begin{document}
Content goes here.
\end{document}
However, a custom class of mine takes care of everything:
\documentclass{mycustomclass}
% This macro is provided by the class. It does everything needed to output the document
% and is always the last macro to be carried out.
% It uses \begin{document}…\end{document} under the hood.
\outputdocument
Would it be possible to run that macro automatically at the end of the file that issued the \documentclass{myniceclass}, so that I didn't have to type it in all the documents that follow the class?
The general question is thus: How to run code automatically at the end of a specific file or at the end of input?
LuaTeX specific tricks (callbacks, maybe?) are allowed.

\input{mycustomdocument}rather than\documentclass{mycustomclass}. – Manuel Jan 20 '16 at 21:21\documentclass{mycustomclass}\input{fileofcontents}\outputdocument? – touhami Jan 20 '16 at 21:48