@maccesar/titools 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/AGENTS-TEMPLATE.md +173 -0
  2. package/README.md +867 -0
  3. package/agents/ti-researcher.md +108 -0
  4. package/bin/titools.js +53 -0
  5. package/lib/commands/agents.js +126 -0
  6. package/lib/commands/install.js +188 -0
  7. package/lib/commands/uninstall.js +215 -0
  8. package/lib/commands/update.js +159 -0
  9. package/lib/config.js +119 -0
  10. package/lib/downloader.js +153 -0
  11. package/lib/installer.js +253 -0
  12. package/lib/platform.js +108 -0
  13. package/lib/symlink.js +142 -0
  14. package/lib/utils.js +270 -0
  15. package/package.json +67 -0
  16. package/skills/alloy-expert/SKILL.md +247 -0
  17. package/skills/alloy-expert/assets/ControllerAutoCleanup.js +182 -0
  18. package/skills/alloy-expert/references/alloy-structure.md +381 -0
  19. package/skills/alloy-expert/references/anti-patterns.md +133 -0
  20. package/skills/alloy-expert/references/code-conventions.md +469 -0
  21. package/skills/alloy-expert/references/contracts.md +280 -0
  22. package/skills/alloy-expert/references/controller-patterns.md +520 -0
  23. package/skills/alloy-expert/references/error-handling.md +484 -0
  24. package/skills/alloy-expert/references/examples.md +735 -0
  25. package/skills/alloy-expert/references/migration-patterns.md +298 -0
  26. package/skills/alloy-expert/references/patterns.md +448 -0
  27. package/skills/alloy-expert/references/performance-patterns.md +855 -0
  28. package/skills/alloy-expert/references/security-patterns.md +847 -0
  29. package/skills/alloy-expert/references/state-management.md +779 -0
  30. package/skills/alloy-expert/references/testing.md +872 -0
  31. package/skills/alloy-guides/SKILL.md +214 -0
  32. package/skills/alloy-guides/references/CLI_TASKS.md +243 -0
  33. package/skills/alloy-guides/references/CONCEPTS.md +191 -0
  34. package/skills/alloy-guides/references/CONTROLLERS.md +298 -0
  35. package/skills/alloy-guides/references/MODELS.md +1028 -0
  36. package/skills/alloy-guides/references/PURGETSS.md +56 -0
  37. package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +242 -0
  38. package/skills/alloy-guides/references/VIEWS_STYLES.md +388 -0
  39. package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +109 -0
  40. package/skills/alloy-guides/references/VIEWS_XML.md +558 -0
  41. package/skills/alloy-guides/references/WIDGETS.md +176 -0
  42. package/skills/alloy-howtos/SKILL.md +203 -0
  43. package/skills/alloy-howtos/references/best_practices.md +138 -0
  44. package/skills/alloy-howtos/references/cli_reference.md +253 -0
  45. package/skills/alloy-howtos/references/config_files.md +87 -0
  46. package/skills/alloy-howtos/references/custom_tags.md +147 -0
  47. package/skills/alloy-howtos/references/debugging_troubleshooting.md +101 -0
  48. package/skills/alloy-howtos/references/samples.md +167 -0
  49. package/skills/purgetss/SKILL.md +442 -0
  50. package/skills/purgetss/assets/purgetss.config.cjs +17 -0
  51. package/skills/purgetss/references/EXAMPLES.md +247 -0
  52. package/skills/purgetss/references/animation-system.md +1294 -0
  53. package/skills/purgetss/references/apply-directive.md +375 -0
  54. package/skills/purgetss/references/arbitrary-values.md +612 -0
  55. package/skills/purgetss/references/class-index.md +1350 -0
  56. package/skills/purgetss/references/cli-commands.md +948 -0
  57. package/skills/purgetss/references/configurable-properties.md +654 -0
  58. package/skills/purgetss/references/custom-rules.md +161 -0
  59. package/skills/purgetss/references/customization-deep-dive.md +722 -0
  60. package/skills/purgetss/references/dynamic-component-creation.md +489 -0
  61. package/skills/purgetss/references/grid-layout.md +455 -0
  62. package/skills/purgetss/references/icon-fonts.md +609 -0
  63. package/skills/purgetss/references/installation-setup.md +366 -0
  64. package/skills/purgetss/references/opacity-modifier.md +291 -0
  65. package/skills/purgetss/references/platform-modifiers.md +479 -0
  66. package/skills/purgetss/references/smart-mappings.md +42 -0
  67. package/skills/purgetss/references/titanium-resets.md +359 -0
  68. package/skills/purgetss/references/ui-ux-design.md +1526 -0
  69. package/skills/ti-guides/SKILL.md +94 -0
  70. package/skills/ti-guides/references/advanced-data-and-images.md +19 -0
  71. package/skills/ti-guides/references/alloy-cli-advanced.md +84 -0
  72. package/skills/ti-guides/references/alloy-data-mastery.md +29 -0
  73. package/skills/ti-guides/references/alloy-widgets-and-themes.md +19 -0
  74. package/skills/ti-guides/references/android-manifest.md +97 -0
  75. package/skills/ti-guides/references/app-distribution.md +258 -0
  76. package/skills/ti-guides/references/application-frameworks.md +377 -0
  77. package/skills/ti-guides/references/cli-reference.md +402 -0
  78. package/skills/ti-guides/references/coding-best-practices.md +102 -0
  79. package/skills/ti-guides/references/commonjs-advanced.md +134 -0
  80. package/skills/ti-guides/references/hello-world.md +100 -0
  81. package/skills/ti-guides/references/hyperloop-native-access.md +62 -0
  82. package/skills/ti-guides/references/javascript-primer.md +411 -0
  83. package/skills/ti-guides/references/reserved-words.md +36 -0
  84. package/skills/ti-guides/references/resources.md +183 -0
  85. package/skills/ti-guides/references/style-and-conventions.md +48 -0
  86. package/skills/ti-guides/references/tiapp-config.md +609 -0
  87. package/skills/ti-howtos/SKILL.md +174 -0
  88. package/skills/ti-howtos/references/android-platform-deep-dives.md +658 -0
  89. package/skills/ti-howtos/references/automation-fastlane-appium.md +95 -0
  90. package/skills/ti-howtos/references/buffer-codec-streams.md +140 -0
  91. package/skills/ti-howtos/references/cross-platform-development.md +348 -0
  92. package/skills/ti-howtos/references/debugging-profiling.md +543 -0
  93. package/skills/ti-howtos/references/extending-titanium.md +723 -0
  94. package/skills/ti-howtos/references/google-maps-v2.md +169 -0
  95. package/skills/ti-howtos/references/ios-map-kit.md +143 -0
  96. package/skills/ti-howtos/references/ios-platform-deep-dives.md +783 -0
  97. package/skills/ti-howtos/references/local-data-sources.md +301 -0
  98. package/skills/ti-howtos/references/location-and-maps.md +252 -0
  99. package/skills/ti-howtos/references/media-apis.md +210 -0
  100. package/skills/ti-howtos/references/notification-services.md +599 -0
  101. package/skills/ti-howtos/references/remote-data-sources.md +349 -0
  102. package/skills/ti-howtos/references/tutorials.md +502 -0
  103. package/skills/ti-howtos/references/using-modules.md +237 -0
  104. package/skills/ti-howtos/references/web-content-integration.md +307 -0
  105. package/skills/ti-howtos/references/webpack-build-pipeline.md +78 -0
  106. package/skills/ti-ui/SKILL.md +179 -0
  107. package/skills/ti-ui/references/accessibility-deep-dive.md +242 -0
  108. package/skills/ti-ui/references/animation-and-matrices.md +599 -0
  109. package/skills/ti-ui/references/application-structures.md +655 -0
  110. package/skills/ti-ui/references/custom-fonts-styling.md +579 -0
  111. package/skills/ti-ui/references/event-handling.md +393 -0
  112. package/skills/ti-ui/references/gestures.md +473 -0
  113. package/skills/ti-ui/references/icons-and-splash-screens.md +409 -0
  114. package/skills/ti-ui/references/layouts-and-positioning.md +462 -0
  115. package/skills/ti-ui/references/listviews-and-performance.md +619 -0
  116. package/skills/ti-ui/references/orientation.md +362 -0
  117. package/skills/ti-ui/references/platform-ui-android.md +635 -0
  118. package/skills/ti-ui/references/platform-ui-ios.md +469 -0
  119. package/skills/ti-ui/references/scrolling-views.md +252 -0
  120. package/skills/ti-ui/references/tableviews.md +568 -0
@@ -0,0 +1,298 @@
1
+ # Alloy Controllers
2
+
3
+ ## Table of Contents
4
+
5
+ - [Alloy Controllers](#alloy-controllers)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Overview](#overview)
8
+ - [Controllers](#controllers)
9
+ - [Events](#events)
10
+ - [Inheritance](#inheritance)
11
+ - [Conditional Code](#conditional-code)
12
+ - [Passing Arguments](#passing-arguments)
13
+ - [Global Namespace](#global-namespace)
14
+ - [Initializer File (alloy.js)](#initializer-file-alloyjs)
15
+ - [Library Code and CommonJS Modules](#library-code-and-commonjs-modules)
16
+ - [Specs Folder](#specs-folder)
17
+ - [Platform-Specific Library Folders](#platform-specific-library-folders)
18
+ - [Extending Alloy, Underscore.js and Backbone.js](#extending-alloy-underscorejs-and-backbonejs)
19
+
20
+ ## Overview
21
+
22
+ This topic covers how to write controller code as well as other JavaScript files excluding models. Some traditional Titanium development is required, since Alloy controllers make direct calls to the Titanium SDK API to manipulate UI objects and access non-UI APIs.
23
+
24
+ ## Controllers
25
+
26
+ In Alloy, controllers contain the application logic used to control the UI and communicate with the model. The following code contains the presentation logic (`index.js`) associated with the view (`index.xml`).
27
+
28
+ **app/controllers/index.js**
29
+
30
+ ```javascript
31
+ function doClick(e) {
32
+ alert($.label.text);
33
+ }
34
+
35
+ $.index.open();
36
+ ```
37
+
38
+ **app/views/index.xml**
39
+
40
+ ```xml
41
+ <Alloy>
42
+ <Window class="container">
43
+ <Label id="label" onClick="doClick">Hello, World</Label>
44
+ </Window>
45
+ </Alloy>
46
+ ```
47
+
48
+ All UI elements which have an `id` attribute in a view are automatically defined and available as a property prefixed by the special variable `$` in the controller. The `$` is a reference to the controller. For example, the `$.label` prefix in the controller is used to access the `Ti.UI.Label` object instance in the view. This reference is used to directly access properties or methods of this object. For example, calling `$.label.hide()` hides the label from the view or you can change the label text with `$.label.text`.
49
+
50
+ To access external controllers and views, use the `Alloy.createController` and `Controller.getView` methods, respectively.
51
+
52
+ If the top-level UI object does not have an ID defined, reference it using the name of the controller prefixed by the `$`. Since the Window object in the view does not contain an ID, the controller uses `$.index` to grab the top-level UI object from the view. However, if an `id` attribute was defined, for example, `<Window id='window'>`, the controller needs to use `$.window` to gain access to the Window object; `$.index` will be undefined and the application will throw an error when calling `$.index.open()`.
53
+
54
+ ### Events
55
+
56
+ Controllers extend `BackBone.Events` and as such can dispatch events.
57
+
58
+ For example, our index view could also require another controller to deliver the label and listen to an event:
59
+
60
+ **app/views/index.xml**
61
+
62
+ ```xml
63
+ <Alloy>
64
+ <Window class="container">
65
+ <Require id="label" src="label" onNotify="doSomething" />
66
+ </Window>
67
+ </Alloy>
68
+ ```
69
+
70
+ The view of the required label-controller would listen to the `click` event of the label itself:
71
+
72
+ **app/views/label.xml**
73
+
74
+ ```xml
75
+ <Alloy>
76
+ <Label id="label" onClick="passClick">Hello, World</Label>
77
+ </Alloy>
78
+ ```
79
+
80
+ And that label-controller would in turn fire the notify event on itself so the index controller will receive it:
81
+
82
+ **app/controllers/label.js**
83
+
84
+ ```javascript
85
+ function passClick(e) {
86
+ $.trigger('notify');
87
+ }
88
+ ```
89
+
90
+ ### Inheritance
91
+
92
+ Controllers can inherit from other controllers by assigning them as a base (parent) controller: `exports.baseController = 'baseControllerName'`. As in the CommonJS model, the controller inherits any exported functions from the base controller. These functions can also be overwritten.
93
+
94
+ For example, the animal view-controller defines a label object with a speak method:
95
+
96
+ **app/controllers/animal.js**
97
+
98
+ ```javascript
99
+ exports.speak = () => {
100
+ alert("Yelp!");
101
+ };
102
+ ```
103
+
104
+ **app/views/animal.xml**
105
+
106
+ ```xml
107
+ <Alloy>
108
+ <Label id="animalLabel">Animal</Label>
109
+ </Alloy>
110
+ ```
111
+
112
+ Then, the following code inherits from the animal view-controller and overrides the speak method and label text property to customize it for a dog controller.
113
+
114
+ **app/controllers/dog.js**
115
+
116
+ ```javascript
117
+ exports.baseController = "animal";
118
+ $.animalLabel.text = "Dog";
119
+ exports.speak = () => {
120
+ alert("Bark!");
121
+ };
122
+ ```
123
+
124
+ ### Conditional Code
125
+
126
+ Alloy introduces a set of special variables that act like compiler directives. Using these compiler constants optimizes the code at generation/compilation and any non-reachable code is removed.
127
+
128
+ The following are the constants defined by Alloy for use in the controller code:
129
+
130
+ * `OS_ANDROID` : true if the current compiler target is Android
131
+ * `OS_IOS` : true if the current compiler target is iOS
132
+ * `ENV_DEV` : true if the current compiler target is built for development (running in the simulator or emulator)
133
+ * `ENV_TEST` : true if the current compiler target is built for testing on a device
134
+ * `ENV_PRODUCTION` : true if the current compiler target is built for production (running after a packaged installation)
135
+ * `DIST_ADHOC` (since Alloy 1.4.0) : true if the current compiler target is built for iOS Ad Hoc distribution
136
+ * `DIST_STORE` (since Alloy 1.4.0) : true if the current compiler target is built for deployment to the Google Play Store or iTunes App Store
137
+
138
+ For example, since iOS devices do not include a back button, the application can conditionally add one to a window controller:
139
+
140
+ ```javascript
141
+ if (OS_IOS) {
142
+ const closeButton = Ti.UI.createButton({
143
+ title: 'Close',
144
+ style: Ti.UI.iPhone.SystemButtonStyle.PLAIN
145
+ });
146
+
147
+ closeButton.addEventListener('click', () => {
148
+ $.window.close();
149
+ });
150
+
151
+ $.window.leftNavButton = closeButton;
152
+ }
153
+ ```
154
+
155
+ ### Passing Arguments
156
+
157
+ When initializing an external controller, you can pass arguments to customize it, for instance, `const controller = Alloy.createController('controller', {args1: 'foo'})`. In the external controller, the special variable `$.args` is used to receive the arguments. Prior to Alloy 1.6, you needed to use `arguments[0]`. For example, suppose you want to add multiple TableViewRow objects to a TableView object.
158
+
159
+ For the TableViewRow object, called 'row', the view contains only the object, and the controller contains only a few lines of code to parse the arguments:
160
+
161
+ **app/views/row.xml**
162
+
163
+ ```xml
164
+ <Alloy>
165
+ <TableViewRow id="rowView"/>
166
+ </Alloy>
167
+ ```
168
+
169
+ **app/controllers/row.js (Alloy 1.6+)**
170
+
171
+ ```
172
+ $.rowView.title = $.args.title || '';
173
+ $.rowView.url = $.args.url || '';
174
+ ```
175
+
176
+ **app/controllers/row.js (Alloy <1.6)**
177
+
178
+ ```javascript
179
+ const args = arguments[0] || {};
180
+ ```
181
+
182
+ In a separate controller containing the TableView object, called 'tableView', the code is cycling through an array of data and creating new instances of 'row' to supply it to 'tableView.'
183
+
184
+ **app/controllers/index.js**
185
+
186
+ ```javascript
187
+ const data = [];
188
+ for (let i=0; i<source.length; i++) {
189
+ const arg = {
190
+ title: source[i].postTitle,
191
+ url: source[i].postLink
192
+ };
193
+ data.push(Alloy.createController('row', arg).getView());
194
+ }
195
+ $.tableView.setData(data);
196
+ ```
197
+
198
+ As seen in the example above, the controller is passing different arguments to the 'row' controller, creating unique instances of 'row'.
199
+
200
+ ### Global Namespace
201
+
202
+ Controllers can store and access global variables using the `Alloy.Globals` namespace. For example, you can store an instance of a parent window in Globals and access it in another window.
203
+
204
+ Store the parent window:
205
+
206
+ ```
207
+ $.index.open();
208
+ Alloy.Globals.parent = $.index;
209
+ ```
210
+
211
+ Access the parent window in another controller:
212
+
213
+ ```javascript
214
+ const parent = Alloy.Globals.parent;
215
+ parent.close();
216
+ ```
217
+
218
+ Other non-controller JavaScript code can access the Globals variable but need to require the Alloy module. See [Extending Alloy](#extending-alloy-underscorejs-and-backbonejs) below.
219
+
220
+ ## Initializer File (alloy.js)
221
+
222
+ The initializer file `app/alloy.js` can be used to execute some code near the beginning of the application's lifecycle. The contents of this file will be executed right before the initial `index.js` controller is loaded, allowing you to execute code before any UI components are loaded and to override built-in Alloy functions before they are executed. The code in this file also has access to the `Alloy` namespace.
223
+
224
+ For instance, the default `isTablet` method returns true if it is identified as an iPad, an Android device in the large or extra large group, or if either dimension exceeds 400 dp for Mobile Web application. To override that behavior, you can add the following code to `alloy.js`.
225
+
226
+ ```
227
+ Alloy.isTablet = () => {
228
+ return !(Math.min(Ti.Platform.displayCaps.platformHeight, Ti.Platform.displayCaps.platformWidth) < 600);
229
+ }
230
+ ```
231
+
232
+ ## Library Code and CommonJS Modules
233
+
234
+ Some JavaScript code might not be suitable as controller code, since it does not have an associated view, or you want to separate it from the MVC framework for easier reusability. Create a folder called `lib` in the `app` directory of your Alloy project. Add your CommonJS modules or JavaScript code using the CommonJS format into the `lib` folder. These files are copied to the `Resources` folder, when compiling your Alloy project.
235
+
236
+ To use the library or CommonJS module, require it with the library name or module name without the 'app/lib' path and '.js' extension:
237
+
238
+ ```javascript
239
+ const lib = require('library_name');
240
+ lib.foo();
241
+ ```
242
+
243
+ ::: warning ⚠️ Warning
244
+ Titanium and Alloy do not support the Node.js concept of "folders as modules". That is, requiring a folder name does not automatically load the `index.js` or `index.json` file inside the folder, or use the `package.json` file to locate the main entry point. You need to explicitly require the file that serves as the main entry point to the library.
245
+ :::
246
+
247
+ ### Specs Folder
248
+
249
+ Starting with Alloy 1.2.0, you can add the `specs` folder to your project. Like the `lib` folder, use the `specs` folder to add files to your project, except the files are only used when the deployment type is **not** production.
250
+
251
+ Create a folder called `specs` in the `app` directory of your Alloy project. Add your files to the specs folder. These files are copied to the `Resources` folder, when compiling your Alloy project if the deployment type is **not** production.
252
+
253
+ Use the `ENV_PROD` variable to check if the application is running as a production target or not, before using the files in the `specs` folder.
254
+
255
+ ```
256
+ if (!ENV_PROD) {
257
+ // Executes the fooFunction from the foo module
258
+ require('specs/foo').fooFuntion();
259
+ }
260
+ ```
261
+
262
+ ### Platform-Specific Library Folders
263
+
264
+ Starting with Alloy 1.5.0, you can also create platform-specific subfolders in the `lib` directory. Just add a folder named **android** or **ios** under the component folder and add your platform-specific files for Android or iOS into the folder, respectively. Do not include the platform-specific folder name when referencing the file.
265
+
266
+ ```
267
+ app/
268
+ ├──lib
269
+ │ ├──ios
270
+ │ │ └── library_name.js
271
+ │ └── library_name.js
272
+ ├──models
273
+ ├──styles
274
+ └──views
275
+ └── index.xml
276
+ ```
277
+
278
+ ### Extending Alloy, Underscore.js and Backbone.js
279
+
280
+ To access the Alloy API methods, such as `createController` and `createModel`, as well as Underscore.js and Backbone.js in CommonJS modules and JavaScript files in `app/lib`, you need to load those modules in to the library:
281
+
282
+ ```javascript
283
+ const Alloy = require('alloy'), _ = require("alloy/underscore")._, Backbone = require("alloy/backbone");
284
+
285
+ // Alloy extended
286
+ Alloy.createController('foo').getView().open();
287
+
288
+ // Underscore extended
289
+ const even = _.find([1, 2, 3, 4, 5, 6], num => num % 2 === 0);
290
+ Ti.API.info(even);
291
+
292
+ // Backbone extended
293
+ const Book = Backbone.Model.extend();
294
+ const book = new Book({title: 'Ulysses', author: 'James Joyce'});
295
+ Ti.API.info(JSON.stringify(book));
296
+ ```
297
+
298
+ Currently, these modules are automatically available in the global scope and these APIs can be used without loading the modules. Referencing these modules without loading them first with the `require` method is discouraged and this behavior may be deprecated in the future. To ensure compatibility with future releases, always use the `require` method to load and use these modules.