Skip to content

Commit 20bf42f

Browse files
Merge pull request tidev#341 from appcelerator/pr/336
Shorthand XML for nav buttons
2 parents 71e2049 + fe6ba6e commit 20bf42f

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

Alloy/commands/compile/parsers/Alloy.Abstract._ProxyProperty.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var _ = 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

68
function fixDefinition(def) {
79
def = def || {};
@@ -18,6 +20,7 @@ exports.parse = function(node, state) {
1820

1921
function 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: {},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function doLeftClick() {
2+
alert('Left button clicked');
3+
}
4+
function doRightClick() {
5+
alert('Right button clicked');
6+
}
7+
8+
$.index.open();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'#index': {
2+
backgroundColor: '#fff',
3+
fullscreen: false,
4+
exitOnClose: true
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Alloy>
2+
<NavigationWindow>
3+
<Window title="Proxy Shorthands">
4+
<LeftNavButton>
5+
<Button title="Left" onClick="doLeftClick"/>
6+
</LeftNavButton>
7+
<RightNavButton title="Right" onClick="doRightClick"/>
8+
</Window>
9+
</NavigationWindow>
10+
</Alloy>

0 commit comments

Comments
 (0)