@@ -12,6 +12,7 @@ var model = {
1212 , yep : true
1313 , nope : false
1414 , nada : null
15+ , objectA : { 'A' : 'first' , 'B' : 'second' }
1516 , letters : [ 'A' , 'B' , 'C' ]
1617 , emptyList : [ ]
1718 , matrix : [ [ 0 , 1 ] , [ 1 , 0 ] ]
@@ -350,6 +351,27 @@ describe('View insertion', function() {
350351 expect ( view . get ( context ) ) . equal ( '<div><p><b>Hi</b></p></div>' ) ;
351352 } ) ;
352353
354+ it ( 'attributes can be used as object index if defined as alias' , function ( ) {
355+ var views = new templates . Views ( ) ;
356+ context . meta . views = views ;
357+ views . register ( 'body' , '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>' ) ;
358+ views . register ( 'section' , '<div><view is="paragraph" attr="{{@attr}}"></view></div>' ) ;
359+ views . register ( 'paragraph' , '<p>{{with @attr as #attr}}{{_page.objectA[#attr]}}{{/}}</p>' ) ;
360+ var view = views . find ( 'body' ) ;
361+ expect ( view . get ( context ) ) . equal ( '<div><p>first</p></div>' ) ;
362+ } ) ;
363+
364+ // This test fails
365+ it . skip ( 'attributes can be used as object index' , function ( ) {
366+ var views = new templates . Views ( ) ;
367+ context . meta . views = views ;
368+ views . register ( 'body' , '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>' ) ;
369+ views . register ( 'section' , '<div><view is="paragraph" attr="{{@attr}}"></view></div>' ) ;
370+ views . register ( 'paragraph' , '<p>{{_page.objectA[@attr]}}</p>' ) ;
371+ var view = views . find ( 'body' ) ;
372+ expect ( view . get ( context ) ) . equal ( '<div><p>first</p></div>' ) ;
373+ } ) ;
374+
353375 it ( 'views can define custom child attribute tags' , function ( ) {
354376 var views = new templates . Views ( ) ;
355377 context . meta . views = views ;
0 commit comments