Function: render
This function initiates the rendering of the passed view. This is done by
loading the layout template into a cheerio DOM object.

Afterwards the presence of a main view object is checked. If available, that
main view gets rendered into the DOM. In any case, the passed view gets
rendered.

As a final step the presence of registered models in the application wide
<Barefoot.DataStore> is checked. If present, its content gets serialized into
a script DOM element so the client can properly deserialize its state
afterwards. See <Barefoot.Router.Client.start> for the deserialization code.

The resulting HTML code is then sent to the client by using the Express.JS
response object, buffered from the route callback in the <route> function.

Parameters:
(Barefoot.View) view - The view which should be rendered

See also:
* <route>
function render(view) {
	debug('render');

	var self = this
		, $;

	function initDOM() {
		debug('init DOM');

		$ = cheerio.load(self.layoutTemplate);
	}

	function renderMainView() {
		debug('render main view');

		var promise;

		if(!_.isUndefined(self.mainView)) {
			var clonedMainView = _.clone(self.mainView());
			clonedMainView.$ = $;
			clonedMainView.$el = clonedMainView.selectDOMElement($);
			promise = clonedMainView.render();
		}

		return promise;
	}

	function renderView() {
		debug('render view');

		view.$ = $;
		view.$el = view.selectDOMElement($);

		return view.render();
	}

	function serializeDataStore() {
		debug('serialize data store');

		if(!_.isUndefined(self.dataStore) &&
			_.keys(self.dataStore.registeredModelsAndCollections).length > 0) {
			var serializiedDataStore = JSON.stringify(self.dataStore.toJSON())
				, javaScriptElement =
					'<script>function deserializeDataStore(){' +
					'return ' + serializiedDataStore + ';}</script>';
			$('body').append(javaScriptElement);
		}
	}

	function writeHTTPResponse() {
		debug('write http response');

		self.res.send($.html());
	}

	function writeHTTPError(err) {
		winston.log('error', 'Uncatched HTTP Error', {
			source: toString()
			, err: err.toString() || err
			, stack: err.stack || undefined
		});
		debug('write http error');

		self.res.send(500);
	}

	Q.fcall(initDOM)
	.then(renderMainView)
	.then(renderView)
	.then(serializeDataStore)
	.done(writeHTTPResponse, writeHTTPError);
}