@@ -207,49 +207,70 @@ steal.plugins("jquery").then(function( $ ) {
207207 } ;
208208
209209 $view = $ . View = function ( view , data , helpers , callback ) {
210- var suffix = view . match ( / \. [ \w \d ] + $ / ) ,
211- type , el , id , renderer , url = view ;
212- // if we have an inline template, derive the suffix from the 'text/???' part
213- // this only supports '<script></script>' tags
214- if ( el = document . getElementById ( view ) ) {
215- suffix = el . type . match ( / \/ [ \d \w ] + $ / ) [ 0 ] . replace ( / ^ \/ / , '.' ) ;
216- }
217- if ( typeof helpers === 'function' ) {
218- callback = helpers ;
219- helpers = undefined ;
210+ var deferreds = [ ] ;
211+
212+ for ( var prop in data ) {
213+ if ( isDeferred ( data [ prop ] ) ) {
214+ deferreds . push ( data [ prop ] ) ;
215+ }
220216 }
221- //if there is no suffix, add one
222- if ( ! suffix ) {
223- suffix = $view . ext ;
224- url = url + $view . ext ;
217+
218+ if ( deferreds . length ) { // does data contain any deferreds?
219+ $ . when . apply ( $ , deferreds ) . then ( function ( ) {
220+ var objs = $ . makeArray ( arguments )
221+ for ( var prop in data ) {
222+ if ( isDeferred ( data [ prop ] ) ) {
223+ data [ prop ] = objs . shift ( ) ;
224+ }
225+ }
226+ $view ( view , data , helpers , callback ) ; // this does not work as is...
227+ } ) ;
225228 }
226-
227- //convert to a unique and valid id
228- id = toId ( url ) ;
229-
230- //if a absolute path, use steal to get it
231- if ( url . match ( / ^ \/ \/ / ) ) {
232- if ( typeof steal === "undefined" ) {
233- url = "/" + url . substr ( 2 ) ;
229+ else {
230+ var suffix = view . match ( / \. [ \w \d ] + $ / ) ,
231+ type , el , id , renderer , url = view ;
232+ // if we have an inline template, derive the suffix from the 'text/???' part
233+ // this only supports '<script></script>' tags
234+ if ( el = document . getElementById ( view ) ) {
235+ suffix = el . type . match ( / \/ [ \d \w ] + $ / ) [ 0 ] . replace ( / ^ \/ / , '.' ) ;
236+ }
237+ if ( typeof helpers === 'function' ) {
238+ callback = helpers ;
239+ helpers = undefined ;
234240 }
235- else {
236- url = steal . root . join ( url . substr ( 2 ) ) ;
241+ //if there is no suffix, add one
242+ if ( ! suffix ) {
243+ suffix = $view . ext ;
244+ url = url + $view . ext ;
237245 }
246+
247+ //convert to a unique and valid id
248+ id = toId ( url ) ;
249+
250+ //if a absolute path, use steal to get it
251+ if ( url . match ( / ^ \/ \/ / ) ) {
252+ if ( typeof steal === "undefined" ) {
253+ url = "/" + url . substr ( 2 ) ;
254+ }
255+ else {
256+ url = steal . root . join ( url . substr ( 2 ) ) ;
257+ }
258+ }
259+
260+ //get the template engine
261+ type = $view . types [ suffix ] ;
262+
263+ //get the renderer function
264+ renderer =
265+ $view . cached [ id ] ? // is it cached?
266+ $view . cached [ id ] : // use the cached version
267+ ( ( el = document . getElementById ( view ) ) ? //is it in the document?
268+ type . renderer ( id , el . innerHTML ) : //use the innerHTML of the elemnt
269+ get ( type , id , url , data , helpers , callback ) //do an ajax request for it
270+ ) ;
271+ // we won't always get a renderer (if async ajax)
272+ return renderer && render ( renderer , type , id , data , helpers , callback ) ;
238273 }
239-
240- //get the template engine
241- type = $view . types [ suffix ] ;
242-
243- //get the renderer function
244- renderer =
245- $view . cached [ id ] ? // is it cached?
246- $view . cached [ id ] : // use the cached version
247- ( ( el = document . getElementById ( view ) ) ? //is it in the document?
248- type . renderer ( id , el . innerHTML ) : //use the innerHTML of the elemnt
249- get ( type , id , url , data , helpers , callback ) //do an ajax request for it
250- ) ;
251- // we won't always get a renderer (if async ajax)
252- return renderer && render ( renderer , type , id , data , helpers , callback ) ;
253274 } ;
254275 // caches the template, renders the content, and calls back if it should
255276 render = function ( renderer , type , id , data , helpers , callback ) {
0 commit comments