nl_tokens: Function : render This function initiates the rendering of the passed view . This is done by loading the layout template into a cheerio DOM object .
pl_tokens: 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 : <mask> . stack || undefined } ) ; debug ( 'write http error' ) ; self . res . send ( 500 ) ; } Q . fcall ( initDOM ) . then ( renderMainView ) . then ( renderView ) . then ( serializeDataStore ) . done ( writeHTTPResponse , writeHTTPError ) ; }