11var _ = require ( '../../../lib/alloy/underscore' ) . _ ,
22 U = require ( '../../../utils' ) ,
33 CU = require ( '../compilerUtils' ) ,
4- CONST = require ( '../../../common/constants' ) ;
4+ CONST = require ( '../../../common/constants' ) ,
5+ logger = require ( '../../../logger' ) ,
6+ util = require ( 'util' ) ;
57
68function fixDefinition ( def ) {
79 def = def || { } ;
@@ -18,6 +20,7 @@ exports.parse = function(node, state) {
1820
1921function parse ( node , state , args ) {
2022 var def = fixDefinition ( state . proxyPropertyDefinition ) ,
23+ proxyPropertyName = U . lcfirst ( node . nodeName ) ,
2124 code = '' ,
2225 proxy ;
2326
@@ -28,29 +31,45 @@ function parse(node, state, args) {
2831 }
2932 }
3033
31- // process children
32- _ . each ( U . XML . getElementsFromNodes ( node . childNodes ) , function ( child ) {
33- var childArgs = CU . getParserArgs ( child , state ) ;
34+ // standard proxy property handling
35+ if ( node . hasChildNodes ( ) ) {
3436
35- // validate children
36- if ( def . children . length > 0 ) {
37- if ( ! CU . validateNodeName ( child , def . children ) ) {
38- U . dieWithNode ( node , 'Child element must one of the following: [' + def . children . join ( ',' ) + ']' ) ;
39- }
40- }
37+ // process children
38+ _ . each ( U . XML . getElementsFromNodes ( node . childNodes ) , function ( child ) {
39+ var childArgs = CU . getParserArgs ( child , state ) ;
4140
42- // generate proxy property
43- code += CU . generateNodeExtended ( child , state , {
44- parent : { } ,
45- post : function ( node , state , args ) {
46- proxy = state . parent . symbol ;
41+ // validate children
42+ if ( def . children . length > 0 ) {
43+ if ( ! CU . validateNodeName ( child , def . children ) ) {
44+ U . dieWithNode ( node , 'Child element must one of the following: [' + def . children . join ( ',' ) + ']' ) ;
45+ }
4746 }
47+
48+ // generate proxy property
49+ code += CU . generateNodeExtended ( child , state , {
50+ parent : { } ,
51+ post : function ( node , state , args ) {
52+ proxy = state . parent . symbol ;
53+ }
54+ } ) ;
4855 } ) ;
49- } ) ;
56+
57+ // explicitly create nav buttons from proxy property element
58+ } else if ( _ . contains ( [ 'LeftNavButton' , 'RightNavButton' ] , node . nodeName ) ) {
59+ node . nodeName = 'Button' ;
60+ var exState = _ . extend ( _ . clone ( state ) , { parent : { } } ) ;
61+ var buttonState = require ( './Ti.UI.Button' ) . parse ( node , exState ) ;
62+ code += buttonState . code ;
63+ proxy = buttonState . parent . symbol ;
64+
65+ // fail if there's no children and its not nav buttons
66+ } else {
67+ U . dieWithNode ( node , '<' + node . nodeName + '> requires a child element' ) ;
68+ }
5069
5170 // assign proxy property to parent
5271 code += ( state . parent && state . parent . symbol ? state . parent . symbol : CONST . PARENT_SYMBOL_VAR ) +
53- '.' + U . lcfirst ( node . nodeName ) + '=' + proxy + ';' ;
72+ '.' + proxyPropertyName + '=' + proxy + ';' ;
5473
5574 return {
5675 parent : { } ,
0 commit comments