A general theory of secularization