Skip to content

Commit

Permalink
Added visibility, model, xml code support! #41 #42
Browse files Browse the repository at this point in the history
  • Loading branch information
brentonhouse committed Aug 6, 2019
1 parent f5212d4 commit 3a90106
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Alloy/alloy.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function banner() {

if (!program.dump) {
console.log(logger.stripColors ? str : str.blue);
var m = 'Titanium Turbo ' + module.exports.version + ' by Axway. A mobile framework for Titanium.\n'.white;
var m = 'Titanium Turbo ' + module.exports.version + ' by Axway Developer Community. A mobile framework for Titanium.\n'.white;
console.log(logger.stripColors ? colors.stripColors(m) : m);
}
}
Expand Down
25 changes: 25 additions & 0 deletions Alloy/commands/compile/ast/string-statement-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Walk tree transformer changing "`......`" to `......` and "~......~" to ......
// This will allow you to use controller args in contained views/controllers
module.exports = function (_ref) {
var types = _ref.types;

return {
pre: function (state) {

},
visitor: {

Property: function (path, state) {
if (types.isStringLiteral(path.node.value)) {
const regex1 = /^`([^`]+)`$/;
const regex2 = /^~([^`]+)~$/;
if ( regex1.test(path.node.value.value) ) {
path.replaceWith(types.ObjectProperty(types.identifier(path.node.key.name), types.Identifier(path.node.value.value)));
} else if ( regex2.test(path.node.value.value) ) {
path.replaceWith(types.ObjectProperty(types.identifier(path.node.key.name), types.Identifier(path.node.value.value.replace(regex2, '$1'))));
}
}
},
}
};
};
3 changes: 3 additions & 0 deletions Alloy/commands/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ function optimizeCompiledCode(alloyConfig, paths) {
plugins: [
[require('./ast/builtins-plugin'), compileConfig],
[require('./ast/optimizer-plugin'), compileConfig.alloyConfig],
[require('./ast/string-statement-plugin'), compileConfig.alloyConfig],


]
}),
fullpath = path.join(compileConfig.dir.resources, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function parse(node, state, args) {
});

if (isCollectionBound) {
var localModel = CU.generateUniqueId();
var localModel = args.createArgs.model || CU.generateUniqueId();
var itemCode = '';
var itemsVar = CU.generateUniqueId();

Expand Down
29 changes: 29 additions & 0 deletions Alloy/commands/compile/parsers/Ti.UI.Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var CU = require('../compilerUtils');
var U = require('../../../utils');
var fs = require('fs-extra');
var path = require('path');

exports.parse = function(node, state) {
var args = CU.getParserArgs(node, state);
var compilerConfig = CU.getCompilerConfig();
var code = '';

function getSourceCode(src) {
if ( src) {
const sourcePath = path.join(compilerConfig.dir.resourcesPlatform, src);
if (fs.existsSync(sourcePath)) {
return fs.readFileSync(sourcePath, 'utf8');
}
}
}

// get code from any external source
code += getSourceCode(args.createArgs.src) || '';

// get code from text node
code += U.XML.getNodeText(node) || '';

return {
code: code.trim() + '\n\n',
};
};
2 changes: 1 addition & 1 deletion Alloy/commands/compile/parsers/Ti.UI.DashboardView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function parse(node, state, args) {
code += dashState.code;

if (isCollectionBound) {
var localModel = CU.generateUniqueId();
var localModel = args.createArgs.model || CU.generateUniqueId();
var itemCode = '';
var localArray = 'data';

Expand Down
2 changes: 1 addition & 1 deletion Alloy/commands/compile/parsers/Ti.UI.ScrollableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function parse(node, state, args) {
code += scrollState.code;

if (isCollectionBound) {
var localModel = CU.generateUniqueId();
var localModel = args.createArgs.model || CU.generateUniqueId();
var itemCode = '';

_.each(U.XML.getElementsFromNodes(node.childNodes), function(child) {
Expand Down
19 changes: 18 additions & 1 deletion Alloy/commands/compile/parsers/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ function parse(node, state, args) {
delete args.createArgs['textStyle'];
}

if ( args.visibility ) {
switch ( args.visibility ) {
case CONST.VISIBILITY_COLLAPSE:
args.origHeight = args.height;
args.origWidth = args.width;
args.height = 0;
args.width = 0;
break;
case CONST.VISIBILITY_HIDDEN:
args.visible = false;
break;
case CONST.VISIBILITY_VISIBLE:
args.visible = true;
break;
}
}

// Generate runtime code
if (state.isViewTemplate) {
var bindId = node.getAttribute('bindId');
Expand Down Expand Up @@ -164,7 +181,7 @@ function parse(node, state, args) {
}

if (isCollectionBound && CU.isNodeForCurrentPlatform(node)) {
var localModel = CU.generateUniqueId();
var localModel = args.createArgs.model || CU.generateUniqueId();
var itemCode = '';

_.each(U.XML.getElementsFromNodes(node.childNodes), function(child) {
Expand Down
3 changes: 2 additions & 1 deletion Alloy/commands/compile/sourceMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ exports.generateCodeAndSourceMap = function(generator, compileConfig) {
root: compileConfig.dir.resourcesPlatform,
plugins: [
[require('./ast/builtins-plugin'), compileConfig],
[require('./ast/optimizer-plugin'), compileConfig.alloyConfig]
[require('./ast/optimizer-plugin'), compileConfig.alloyConfig],
[require('./ast/string-statement-plugin'), compileConfig.alloyConfig],
]
});
if (compileConfig.sourcemap) {
Expand Down
3 changes: 0 additions & 3 deletions Alloy/commands/compile/styler.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,6 @@ exports.generateStyleParams = function(styles, classes, id, apiName, extraStyle,
}
});

// deep merge necessary to properly merge fonts
lastObj = deepExtend(true, lastObj, extraStyle || {});

// add in any final styles
// ALOY-1363: deep merge necessary to properly merge children
lastObj = deepExtend(true, lastObj, extraStyle || {});
Expand Down
5 changes: 5 additions & 0 deletions Alloy/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ exports.CONTROLLER_NODES = ['Alloy.Require', 'Alloy.Widget'];
exports.DEFAULT_BACKBONE_VERSION = '1.4.0';
exports.SUPPORTED_BACKBONE_VERSIONS = ['0.9.2', '1.1.2', '1.3.3', '1.4.0'];

// values for visibility property
exports.VISIBILITY_COLLAPSE = 'collapse';
exports.VISIBILITY_HIDDEN = 'hidden';
exports.VISIBILITY_VISIBLE = 'visible';

// property names
exports.CLASS_PROPERTY = 'classes';
exports.APINAME_PROPERTY = 'apiName';
Expand Down
4 changes: 4 additions & 0 deletions Alloy/template/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ var Alloy = require('/alloy'),
_ = Alloy._,
Backbone = Alloy.Backbone;

Ti.UI.VISIBILITY_COLLAPSE = 'collapse';
Ti.UI.VISIBILITY_HIDDEN = 'hidden';
Ti.UI.VISIBILITY_VISIBLE = 'visible';

__MAPMARKER_ALLOY_JS__
Alloy.createController('index');
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Titanium Turbo is a variation of Titanium Alloy that adds some enhancements and customizations for rapid development.

## [1.14.0-12] - 2019-08-06

### Added
- Added support for visibility property in XML Views with possible values of: `collapse`, `hidden`, and `visible`.
- Added constants: `Ti.UI.VISIBILITY_COLLAPSE`, `Ti.UI.VISIBILITY_HIDDEN`, and `Ti.UI.VISIBILITY_VISIBLE`
- Added support for `model` XML attribute to be used with with `dataCollection` to assign variable name to model
- Added support for adding code to XML View attributes when surrounded by '~'
- Added support for `Code` element in XML View. Add code by body or `src` attribute.

## [1.14.0-11] - 2019-08-02

### Updated
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"turbo",
"brentonhouse"
],
"version": "1.14.0-11",
"version": "1.14.0-12",
"author": "Appcelerator, Inc. <info@appcelerator.com>",
"maintainers": [
{
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ npm install --save-dev @titanium/plugin-turbo
* [x] Added support for xml attributes with dotted notation (e.g. `font.fontSize`) [[ALOY-1363]](https://jira.appcelerator.org/browse/ALOY-1363) ![Has been merged into Alloy](https://img.shields.io/badge/alloy-merged-blue.png)
* [x] Added support for using `$.args` in XML views. [[ALOY-1316]](https://jira.appcelerator.org/browse/ALOY-1316) ![Has been merged into Alloy](https://img.shields.io/badge/alloy-merged-blue.png)
* [x] Added support for using `$.*` in XML views. -- Anything that starts with "$." in an Alloy XML View will be used literally and not treated as a string.
* [x] Added support for using `turbo.*` in XML views. -- Anything that starts with "turbo." in an Alloy XML View will be used literally and not treated as a string. **[Necessary for `node_modules` support to LiveView]**
* [x] Added support for using `turbo.*` in XML views. -- Anything that starts with "turbo." in an Alloy XML View will be used literally and not treated as a string. **[Required workaround for `node_modules` support to LiveView]** [[TIMOB-27206]](https://jira.appcelerator.org/browse/TIMOB-27206)
* [x] Added support for `__init()` function in controller that will be called before view is built. -- Allows `$.*` variables to be created and used in XML views.
* [x] Added support for `visibility` property in XML Views with possible values of: `hidden`, `collapse`, and `visible` -- Allows collapsing of view in XML. [[TIMOB-27307]](https://jira.appcelerator.org/browse/TIMOB-27307)
* [x] Added constants: `Ti.UI.VISIBILITY_COLLAPSE`, `Ti.UI.VISIBILITY_HIDDEN`, and `Ti.UI.VISIBILITY_VISIBLE`
* [x] Added support for `model` XML attribute to be used with with `dataCollection` to assign variable name to model
* [x] Added support for adding code to XML View attributes when surrounded by '~' [[ALOY-1699]](https://jira.appcelerator.org/browse/ALOY-1699)
* [x] Added support for `Code` element in XML View. Add code by body or `src` attribute. [[ALOY-1700]](https://jira.appcelerator.org/browse/ALOY-1700)



Expand All @@ -83,6 +88,7 @@ npm install --save-dev @titanium/plugin-turbo

## 📚Learn More

* [Axway Developer Blog](https://devblog.axway.com)
* [Axway Developer Portal](https://developer.axway.com)

## 📣 Feedback
Expand Down

0 comments on commit 3a90106

Please sign in to comment.