@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,214 @@
1
+ ---
2
+ name: alloy-guides
3
+ description: "Titanium Alloy MVC official framework reference. Use when working with, reviewing, analyzing, or examining Alloy models, views, controllers, Backbone.js data binding, TSS styling, widgets, Alloy CLI, sync adapters, migrations, or MVC compilation. Explains how Backbone.js models and collections work in Alloy."
4
+ argument-hint: "[concept]"
5
+ allowed-tools: Read, Grep, Glob, Edit, Write, Bash(node *)
6
+ ---
7
+
8
+ # Alloy MVC Framework Guide
9
+
10
+ Complete reference for building Titanium mobile applications with the Alloy MVC framework and Backbone.js.
11
+
12
+ ## Project Detection
13
+
14
+ :::info AUTO-DETECTS ALLOY PROJECTS
15
+ This skill automatically detects Alloy projects when invoked and provides framework-specific guidance.
16
+
17
+ **Detection occurs automatically** - no manual command needed.
18
+
19
+ **Alloy project indicators:**
20
+ - `app/` folder (MVC structure)
21
+ - `app/views/`, `app/controllers/` folders
22
+ - `app/models/` folder
23
+
24
+ **Behavior based on detection:**
25
+ - **Alloy detected** → Provides Alloy MVC documentation, Backbone.js patterns, TSS styling, widgets
26
+ - **Not detected** → Indicates this skill is for Alloy projects only, does not suggest Alloy-specific features
27
+ :::
28
+
29
+ ## Table of Contents
30
+
31
+ - [Alloy MVC Framework Guide](#alloy-mvc-framework-guide)
32
+ - [Project Detection](#project-detection)
33
+ - [Table of Contents](#table-of-contents)
34
+ - [Quick Reference](#quick-reference)
35
+ - [Project Structure](#project-structure)
36
+ - [MVC Quick Start](#mvc-quick-start)
37
+ - [Key Concepts](#key-concepts)
38
+ - [Critical Rules](#critical-rules)
39
+ - [Platform-Specific Properties in TSS](#platform-specific-properties-in-tss)
40
+ - [Common Patterns](#common-patterns)
41
+ - [Creating a Model](#creating-a-model)
42
+ - [Data Binding](#data-binding)
43
+ - [Platform-Specific Code](#platform-specific-code)
44
+ - [Widget Usage](#widget-usage)
45
+ - [Compilation Process](#compilation-process)
46
+ - [References](#references)
47
+ - [Related Skills](#related-skills)
48
+
49
+ ---
50
+
51
+ ## Quick Reference
52
+
53
+ | Topic | Reference File |
54
+ | ------------------------------------------------ | ----------------------------------------------------------------------- |
55
+ | Core concepts, MVC, Backbone.js, conventions | [CONCEPTS.md](references/CONCEPTS.md) |
56
+ | Controllers, events, conditional code, arguments | [CONTROLLERS.md](references/CONTROLLERS.md) |
57
+ | Models, collections, data binding, migrations | [MODELS.md](references/MODELS.md) |
58
+ | XML markup, elements, attributes, events | [VIEWS_XML.md](references/VIEWS_XML.md) |
59
+ | TSS styling, themes, platform-specific styles | [VIEWS_STYLES.md](references/VIEWS_STYLES.md) |
60
+ | Dynamic styles, autostyle, runtime styling | [VIEWS_DYNAMIC.md](references/VIEWS_DYNAMIC.md) |
61
+ | Controllers-less views, patterns | [VIEWS_WITHOUT_CONTROLLERS.md](references/VIEWS_WITHOUT_CONTROLLERS.md) |
62
+ | Creating and using widgets | [WIDGETS.md](references/WIDGETS.md) |
63
+ | CLI commands, code generation | [CLI_TASKS.md](references/CLI_TASKS.md) |
64
+ | PurgeTSS integration and features | [PURGETSS.md](references/PURGETSS.md) |
65
+
66
+ ## Project Structure
67
+
68
+ Standard Alloy project structure:
69
+
70
+ ```
71
+ app/
72
+ ├── alloy.js # Initializer file
73
+ ├── alloy.jmk # Build configuration
74
+ ├── config.json # Project configuration
75
+ ├── assets/ # Images, fonts, files (→ Resources/)
76
+ ├── controllers/ # Controller files (.js)
77
+ ├── i18n/ # Localization strings (→ i18n/)
78
+ ├── lib/ # CommonJS modules
79
+ ├── migrations/ # DB migrations (<DATETIME>_<name>.js)
80
+ ├── models/ # Model definitions (.js)
81
+ ├── platform/ # Platform-specific resources (→ platform/)
82
+ ├── specs/ # Test-only files (dev/test only)
83
+ ├── styles/ # TSS files (.tss)
84
+ ├── themes/ # Theme folders
85
+ ├── views/ # XML markup files (.xml)
86
+ └── widgets/ # Widget components
87
+ ```
88
+
89
+ ## MVC Quick Start
90
+
91
+ **Controller** (`app/controllers/index.js`):
92
+ ```javascript
93
+ function doClick(e) {
94
+ alert($.label.text);
95
+ }
96
+ $.index.open();
97
+ ```
98
+
99
+ **View** (`app/views/index.xml`):
100
+ ```xml
101
+ <Alloy>
102
+ <Window class="container">
103
+ <Label id="label" onClick="doClick">Hello, World</Label>
104
+ </Window>
105
+ </Alloy>
106
+ ```
107
+
108
+ **Style** (`app/styles/index.tss`):
109
+ ```javascript
110
+ ".container": { backgroundColor: "white" }
111
+ "Label": { color: "#000" }
112
+ ```
113
+
114
+ ## Key Concepts
115
+
116
+ - **Models/Collections**: Backbone.js objects with sync adapters (sql, properties)
117
+ - **Views**: XML markup with TSS styling
118
+ - **Controllers**: JavaScript logic with `$` reference to view components
119
+ - **Data Binding**: Bind collections to UI components automatically
120
+ - **Widgets**: Reusable components with MVC structure
121
+ - **Conventions**: File naming and placement drive code generation
122
+
123
+ ## Critical Rules
124
+
125
+ ### Platform-Specific Properties in TSS
126
+
127
+ :::danger CRITICAL: Platform-Specific Properties Require Modifiers
128
+ Using `Ti.UI.iOS.*` or `Ti.UI.Android.*` properties in TSS WITHOUT platform modifiers causes cross-platform compilation failures.
129
+
130
+ **Example of the damage:**
131
+ ```tss
132
+ // ❌ WRONG - Adds Ti.UI.iOS to Android project
133
+ "#mainWindow": {
134
+ statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT // FAILS on Android!
135
+ }
136
+ ```
137
+
138
+ **CORRECT approach - Use platform modifiers:**
139
+ ```tss
140
+ // ✅ CORRECT - Only adds to iOS
141
+ "#mainWindow[platform=ios]": {
142
+ statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
143
+ }
144
+
145
+ // ✅ CORRECT - Only adds to Android
146
+ "#mainWindow[platform=android]": {
147
+ actionBar: {
148
+ displayHomeAsUp: true
149
+ }
150
+ }
151
+ ```
152
+
153
+ **Properties that ALWAYS require platform modifiers:**
154
+ - iOS: `statusBarStyle`, `modalStyle`, `modalTransitionStyle`, any `Ti.UI.iOS.*`
155
+ - Android: `actionBar` config, any `Ti.UI.Android.*` constant
156
+
157
+ **Available modifiers:** `[platform=ios]`, `[platform=android]`, `[formFactor=handheld]`, `[formFactor=tablet]`, `[if=Alloy.Globals.customVar]`
158
+
159
+ **For more platform-specific patterns, see** [Platform Modifiers (purgetss)](skills/purgetss/references/platform-modifiers.md) or [Platform UI guides (ti-ui)](skills/ti-ui/references/platform-ui-ios.md).
160
+ :::
161
+
162
+ ## Common Patterns
163
+
164
+ ### Creating a Model
165
+ ```bash
166
+ alloy generate model book sql title:string author:string
167
+ ```
168
+
169
+ ### Data Binding
170
+ ```xml
171
+ <Collection src="book" />
172
+ <TableView dataCollection="book">
173
+ <TableViewRow title="{title}" />
174
+ </TableView>
175
+ ```
176
+
177
+ ### Platform-Specific Code
178
+ ```javascript
179
+ if (OS_IOS) {
180
+ // iOS-only code
181
+ }
182
+ if (OS_ANDROID) {
183
+ // Android-only code
184
+ }
185
+ ```
186
+
187
+ ### Widget Usage
188
+ ```xml
189
+ <Widget src="mywidget" id="foo" />
190
+ ```
191
+
192
+ ## Compilation Process
193
+
194
+ 1. **Cleanup**: Resources folder cleaned
195
+ 2. **Build Config**: alloy.jmk loaded (pre:load task)
196
+ 3. **Framework Files**: Backbone.js, Underscore.js, sync adapters copied
197
+ 4. **MVC Generation**: Models, widgets, views, controllers compiled to JS
198
+ 5. **Main App**: app.js generated from template
199
+ 6. **Optimization**: UglifyJS optimization, platform-specific code removal
200
+
201
+ ## References
202
+
203
+ Read detailed documentation from the reference files listed above based on your specific task.
204
+
205
+ ## Related Skills
206
+
207
+ For tasks beyond Alloy MVC basics, use these complementary skills:
208
+
209
+ | Task | Use This Skill |
210
+ | ----------------------------------------- | -------------- |
211
+ | Modern architecture, services, patterns | `alloy-expert` |
212
+ | Alloy CLI, config files, debugging errors | `alloy-howtos` |
213
+ | Utility-first styling with PurgeTSS | `purgetss` |
214
+ | Native features (location, push, media) | `ti-howtos` |
@@ -0,0 +1,243 @@
1
+ # Alloy Tasks with the CLI
2
+
3
+ ## Table of Contents
4
+
5
+ - [Alloy Tasks with the CLI](#alloy-tasks-with-the-cli)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Creating a New Application](#creating-a-new-application)
8
+ - [Creating a New Application Using a Test Application](#creating-a-new-application-using-a-test-application)
9
+ - [Generating Components](#generating-components)
10
+ - [Generating a Controller](#generating-a-controller)
11
+ - [Generating a View](#generating-a-view)
12
+ - [Generating a Style](#generating-a-style)
13
+ - [Generating a Model](#generating-a-model)
14
+ - [Generating a Migration](#generating-a-migration)
15
+ - [Generating a Widget](#generating-a-widget)
16
+ - [Generating alloy.jmk](#generating-alloyjmk)
17
+ - [Extracting Localization Strings](#extracting-localization-strings)
18
+ - [Compiling a Specific View-Controller](#compiling-a-specific-view-controller)
19
+ - [Building an Application](#building-an-application)
20
+ - [Installing Special Project Components](#installing-special-project-components)
21
+ - [Installing the Compiler Plugin](#installing-the-compiler-plugin)
22
+
23
+ ## Creating a New Application
24
+
25
+ > **Recommended:** Use `ti create --alloy` to create a new Alloy project in one step.
26
+
27
+ ```bash
28
+ ti create -t app --alloy --id com.example.myapp -n MyApp -p android,ios
29
+ ```
30
+
31
+ This creates a complete Alloy project structure with the `app` folder containing controllers, views, styles, models, and migrations.
32
+
33
+ **Alternative (interactive):**
34
+ ```bash
35
+ ti create
36
+ ```
37
+
38
+ You will be prompted to enter an application name and application ID. When prompted for project type, select **Alloy**.
39
+
40
+ **Legacy method (not recommended):**
41
+ ```bash
42
+ ti create
43
+ cd PROJECTDIRECTORY
44
+ alloy new
45
+ ```
46
+
47
+ This two-step approach is discouraged in favor of using `--alloy` directly.
48
+
49
+ ## Creating a New Application Using a Test Application
50
+
51
+ You can generate a new Alloy project using a test application from the Alloy Github repo.
52
+
53
+ ```bash
54
+ ti create -t app --classic -i com.appc.picker -n AlloyPicker
55
+ cd AlloyPicker
56
+ alloy new --testapp ui/picker
57
+ ```
58
+
59
+ ## Generating Components
60
+
61
+ The CLI can generate skeleton controllers (with views and styles), models, database migrations and widgets.
62
+
63
+ ### Generating a Controller
64
+
65
+ To generate a controller with a style and view:
66
+
67
+ ```bash
68
+ alloy generate controller <name> [--widgetname <widget_name>] [-o path_to_project/app] [--platform <platform>]
69
+ ```
70
+
71
+ This creates `app/controllers/<name>.js`, `app/styles/<name>.tss`, and `app/views/<name>.xml`.
72
+
73
+ ### Generating a View
74
+
75
+ To generate a view and style **without** a controller:
76
+
77
+ ```bash
78
+ alloy generate view <name> [--widgetname <widget_name>] [-o path_to_project/app] [--platform <platform>]
79
+ ```
80
+
81
+ This creates `app/styles/<name>.tss` and `app/views/<name>.xml`.
82
+
83
+ ### Generating a Style
84
+
85
+ To generate a style for a view-controller:
86
+
87
+ ```bash
88
+ alloy generate style <name> [--widgetname <widget_name>]
89
+ ```
90
+
91
+ Alloy uses the id and attribute names in the markup file to populate the skeleton style file. This creates `app/styles/<name>.tss`.
92
+
93
+ To generate style files for all view-controllers:
94
+
95
+ ```bash
96
+ alloy generate style --all
97
+ ```
98
+
99
+ ### Generating a Model
100
+
101
+ To generate a model:
102
+
103
+ ```bash
104
+ alloy generate model <name> <adapter> [<col_name_1>:<col_type_1> <col_name_2>:<col_type_2> ...] [-o path_to_project/app]
105
+ ```
106
+
107
+ The fourth parameter selects the adapter type: `sql` for SQLite or `properties` for local storage.
108
+
109
+ This creates `app/models/<name>.js`, and `app/migrations/DATETIME_<name>.js` if the adapter type is 'sql'.
110
+
111
+ ### Generating a Migration
112
+
113
+ To generate a standalone migration for a specific model:
114
+
115
+ ```bash
116
+ alloy generate migration <name> [-o path_to_project/app]
117
+ ```
118
+
119
+ This creates `app/migrations/DATETIME_<name>.js`.
120
+
121
+ ### Generating a Widget
122
+
123
+ To generate a basic widget:
124
+
125
+ ```bash
126
+ alloy generate widget <name> [-o path_to_project/app]
127
+ ```
128
+
129
+ This creates `app/widgets/<name>/widget.json`, `app/widgets/<name>/controllers/widget.js`, `app/widgets/<name>/styles/widget.tss`, and `app/widgets/<name>/views/widget.xml`. The widget is automatically added to `config.json`.
130
+
131
+ ### Generating alloy.jmk
132
+
133
+ To generate the build customization file:
134
+
135
+ ```bash
136
+ alloy generate jmk [-o path_to_project/app]
137
+ ```
138
+
139
+ This creates `app/alloy.jmk` with a few task hooks in place.
140
+
141
+ ## Extracting Localization Strings
142
+
143
+ The `alloy extract-i18n` command inspects your JS, TSS and XML files (since Alloy 1.6.0) for instances of Titanium's localization functions and adds those strings to an i18n strings.xml file.
144
+
145
+ ```bash
146
+ alloy extract-i18n [language] [--apply]
147
+ ```
148
+
149
+ **Parameters**:
150
+
151
+ * `language` – Optional. Two-letter language code (`en` or `es`). Default is `en`.
152
+ * `--apply` – Optional. Writes new entries to `strings.xml`. Without it, displays a preview.
153
+
154
+ Supported functions:
155
+
156
+ * `Titanium.Locale.getString()`
157
+ * `Ti.Locale.getString()`
158
+ * `L()`
159
+
160
+ **Example**:
161
+
162
+ ```javascript
163
+ // In JavaScript/TSS
164
+ const name = Ti.Locale.getString('name');
165
+ const color = Titanium.Locale.getString('color');
166
+ const currency = L('currency');
167
+ ```
168
+
169
+ ```xml
170
+ <!-- In XML (since Alloy 1.6.0) -->
171
+ <Label textid="greeting" />
172
+ <Button titleid="submit_button" />
173
+ ```
174
+
175
+ **Preview Output** (without --apply):
176
+
177
+ ```
178
+ [INFO] ######## BEFORE ########
179
+ [INFO] <?xml version="1.0" encoding="UTF-8"?>
180
+ [INFO] <resources>
181
+ [INFO] </resources>
182
+ [INFO]
183
+ [INFO] ######## AFTER ########
184
+ [INFO] <?xml version="1.0" encoding="UTF-8"?>
185
+ [INFO] <resources>
186
+ [INFO] <string name="name">name</string>
187
+ [INFO] <string name="color">color</string>
188
+ [INFO] <string name="currency">currency</string>
189
+ [INFO] <string name="greeting">greeting</string>
190
+ [INFO] <string name="submit_button">submit_button</string>
191
+ [INFO] </resources>
192
+ ```
193
+
194
+ Running with `--apply`:
195
+
196
+ ```bash
197
+ alloy extract-i18n --apply
198
+ ```
199
+
200
+ Generates `app/i18n/en/strings.xml`:
201
+
202
+ ```xml
203
+ <resources>
204
+ <string name="name">name</string>
205
+ <string name="color">color</string>
206
+ <string name="currency">currency</string>
207
+ <string name="greeting">greeting</string>
208
+ <string name="submit_button">submit_button</string>
209
+ </resources>
210
+ ```
211
+
212
+ ## Compiling a Specific View-Controller
213
+
214
+ To select which Alloy view-controller to compile to Titanium code:
215
+
216
+ ```bash
217
+ alloy compile --config platform=<platform>,file=<file>
218
+
219
+ ## Example
220
+ alloy compile --config platform=android,file=app/controller/index.js
221
+ ```
222
+
223
+ ## Building an Application
224
+
225
+ To build and run an application:
226
+
227
+ ```bash
228
+ ti build --platform <platform> [--project-dir <value>] [--sdk <value>] [<platform_build_options>]
229
+ ```
230
+
231
+ Running this from the root directory of the project compiles the files to the correct location automatically.
232
+
233
+ ## Installing Special Project Components
234
+
235
+ ### Installing the Compiler Plugin
236
+
237
+ To install the compiler plugin that hooks the Alloy project to Studio:
238
+
239
+ ```bash
240
+ alloy install plugin [path_to_project]
241
+ ```
242
+
243
+ Use this command to update the compiler plugin if your project was created using an older version of Alloy.
@@ -0,0 +1,191 @@
1
+ # Alloy Concepts
2
+
3
+ ## Table of Contents
4
+
5
+ - [Alloy Concepts](#alloy-concepts)
6
+ - [Table of Contents](#table-of-contents)
7
+ - [Overview](#overview)
8
+ - [Model-View-Controller](#model-view-controller)
9
+ - [Alloy: MVC with Backbone](#alloy-mvc-with-backbone)
10
+ - [Alloy and the Titanium SDK](#alloy-and-the-titanium-sdk)
11
+ - [Titanium SDK to Alloy Mapping](#titanium-sdk-to-alloy-mapping)
12
+ - [Convention over Configuration](#convention-over-configuration)
13
+ - [Platform-Specific Resources](#platform-specific-resources)
14
+ - [Widgets](#widgets)
15
+ - [Builtins](#builtins)
16
+ - [Compilation Process](#compilation-process)
17
+ - [Cleanup](#cleanup)
18
+ - [Build Configuration](#build-configuration)
19
+ - [Alloy Framework, Assets, and Lib](#alloy-framework-assets-and-lib)
20
+ - [Model-View-Controller and Widget Generation](#model-view-controller-and-widget-generation)
21
+ - [Main Application](#main-application)
22
+ - [Code Optimization](#code-optimization)
23
+
24
+ ## Overview
25
+
26
+ This guide covers the important concepts related to the Alloy framework, including the model-view-controller framework, convention-over-configuration design, widgets, and built-in support from Backbone.js and Underscore.js.
27
+
28
+ ## Model-View-Controller
29
+
30
+ Alloy utilizes the model-view-controller (MVC) pattern, which separates the application into three different components:
31
+
32
+ * **Models** provide the business logic, containing the rules, data and state of the application
33
+
34
+ * **Views** provide the GUI components to the user, either presenting data or allowing the user to interact with the model data
35
+
36
+ * **Controllers** provide the glue between the model and view components in the form of application logic
37
+
38
+ For example, in a calendar application, the models include events, reminders, invitations, and contacts. The views present the calendar data and reminders to the user or allow the user to add events. For reminders, the controller checks the model data and launches a 'reminder' view to the user. For adding events, the controller opens an 'add event' view, then adds the event into the model data once the user entered the data.
39
+
40
+ An advantage of MVC is the ability to reuse code by separating the functionality. For example, you can have specific views for different devices, while keeping the controller code relatively the same and the model data unchanged.
41
+
42
+ ### Alloy: MVC with Backbone
43
+
44
+ Backbone.js is a lightweight MVC framework, originally designed for web applications. Alloy models are built on top of Backbone.js, taking advantage of Backbone's rich Model and Collection APIs. You define models using a Javascript file that exports a special JSON object, which uses Backbone's extend functionality to customize models and collections.
45
+
46
+ Alloy views are built from Titanium UI components. You define views using XML markup and style them using Alloy _Titanium Style Sheets (.tss)_, which abstracts the creation of these components without using Titanium API calls. Alloy generates the code to create your views.
47
+
48
+ Alloy controllers generally have a one-to-one relationship with Alloy views. Controllers directly use the Titanium SDK API without an abstraction layer. The controller has access to all of the view components.
49
+
50
+ Additionally, Alloy provides built-in support for Underscore.js, which provides a set of utility functions, such as array and iterative helpers.
51
+
52
+ ## Alloy and the Titanium SDK
53
+
54
+ Alloy uses Titanium SDK to abstracts the creation of UI components through the use of XML markup and style sheets. If Alloy has not implemented a feature of the Titanium SDK or if the feature is not UI related, you can always use the Titanium SDK API in the Alloy controller code or create a CommonJS module to implement a feature. The table below lists what Alloy directly abstracts from the Titanium SDK.
55
+
56
+ For assets, such as images, any references to the `Resources` folder in the Titanium SDK documentation should be replaced with the `app/assets` folder to use it for Alloy. For example, the Icons and Splash Screens guide tells you to place files in either the `Resources/android` or `Resources/iphone` folder. For Alloy, the files should be placed in either the `app/assets/android` or `app/assets/iphone` folder.
57
+
58
+ ### Titanium SDK to Alloy Mapping
59
+
60
+ | Titanium SDK Component | Alloy Component |
61
+ | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | **Titanium.UI.* Objects** | **XML element**. Remove the namespace. For some elements, you may need to assign the `ns` attribute. |
63
+ | `Titanium.UI.createButton();` | `<Button />` creates a button |
64
+ | | **TSS element**. Remove the namespace. |
65
+ | | `"Button":{ /* Button attributes */ }` |
66
+ | **Titanium Object properties** | **XML attribute** if the property can be expressed as a string, number or Titanium SDK constant. |
67
+ | `Titanium.UI.createButton({text: "Foobar", top: 0, width: Ti.UI.SIZE});` | `<Button title="Foobar" top="0" width="Ti.UI.SIZE"/>` |
68
+ | | **TSS attribute** if the property can be directly expressed as a string, number, Titanium SDK constant, dictionary or array. |
69
+ | | `"Button":{ title: "Foobar", top: 0, width: Ti.UI.SIZE }` |
70
+ | **Titanium Object methods** | Use in the controller code. You need to define the `id` attribute of the object in the XML markup, so the object can be referenced in the controller. |
71
+ | `const button = Titanium.UI.createButton(); button.setTitle('Push Me!');` | `// Need to give the object an ID: <Button id="button" />` then `$.button.setTitle('Push Me!');` |
72
+ | **Titanium Object events** | XML attribute to bind a callback in the associated controller. Capitalize the first character of the event name and append 'on' to the beginning of the name. |
73
+ | `const button = Titanium.UI.createButton(); button.addEventListener('click', doClick);` | `<Button onClick="doClick"/>` (doClick needs to be declared in the associated controller) |
74
+
75
+ ## Convention over Configuration
76
+
77
+ To simplify development, Alloy uses a directory structure and naming conventions to organize the application rather than configuration files. Alloy expects to find files in specific locations. Any folder or file not adhering to the below naming conventions is ignored by Alloy. For example, at generation time, Alloy will look for the mandatory files `app/views/index.xml` and `app/controllers/index.js`, then the optional corresponding file `app/styles/index.tss`. Alloy requires these files to create the initial view-controller `Resources/<platform>/alloy/controllers/index.js`.
78
+
79
+ The following is a list of directories and files that can be found in an Alloy project:
80
+
81
+ | Directory/File | Description |
82
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
+ | `app` | Contains the models, views, controllers and assets of the application. All work should be done here. |
84
+ | `app/alloy.jmk` | Build configuration file. See Build Configuration File (alloy.jmk). |
85
+ | `app/alloy.js` | Initializer file used to preconfigure components or override Alloy methods before the main controller is executed. |
86
+ | `app/config.json` | Project configuration file. See Project Configuration File (config.json). |
87
+ | `app/assets` | Contains image assets and other files that need to be copied into the `Resources` directory. Reference these files in the code without the 'app/assets' path. |
88
+ | `app/controllers` | Contains controllers in the format `filename.js` to a corresponding view file `app/views/filename.xml`. |
89
+ | `app/i18n` | Since Alloy 1.8.0 and Titanium 5.2.0 Language Strings are sourced from `app/i18n` and Alloy will generate the `i18n` folder in the project root. |
90
+ | `app/lib` | Contains application-specific library code, typically in the CommonJS format. |
91
+ | `app/migrations` | Contains database migration files in the format `<DATETIME>_filename.js`. See Migrations for more information. |
92
+ | `app/models` | Contains model files in the format `filename.js`. |
93
+ | `app/platform` | Since Alloy 1.8.0 platform resources are sourced from `app/platform` and Alloy will generate the `platform` folder in the project root. |
94
+ | `app/specs` | Like the `app/lib` folder except it is only used if the deploy type is **not** production (since Alloy 1.2.0). |
95
+ | `app/styles` | Contains view styling in the format `filename.tss`, which is applied to a corresponding view file `app/views/filename.xml`. |
96
+ | `app/themes` | Contains themes to customize the assets and styles of the entire GUI. |
97
+ | `app/views` | Contains views in the format `filename.xml` with the optional corresponding files `app/controllers/filename.js` and `app/styles/filename.tss`. |
98
+ | `app/widgets` | Contains widget files. Each widget will have its own `app`-like directory structure. |
99
+ | `i18n` | Since Alloy 1.8.0 and Titanium 5.2.0 Language Strings are sourced from `app/i18n` and Alloy will generate the `i18n` folder in the project root. |
100
+ | `Resources` | Contains the Titanium files generated by the Alloy interface from the `app` directory. All files will be overwritten each time the application is built. Since Alloy 1.3.0, Alloy creates a separate Titanium project for each platform you build for in the `Resources/<platform>` folder. |
101
+
102
+ **Notes:** the `lib`, `migrations`, `themes` and `widgets` folders are not automatically generated when creating a new project. The `migrations` and `widgets` folder will be generated by the Alloy command-line interface if any of those components are generated. The `lib` and `themes` folders will need to be manually created.
103
+
104
+ The `alloy.jmk` file is not automatically generated when creating a new project. Use the command-line interface to generate this file.
105
+
106
+ ### Platform-Specific Resources
107
+
108
+ Controllers, views and styles can have platform-specific resources. 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.
109
+
110
+ For example, an iOS-specific view and an Android-specific controller would look like this:
111
+
112
+ ```
113
+ app/
114
+ ├── controllers/
115
+ │ ├── android/
116
+ │ │ └── index.js
117
+ │ └── index.js
118
+ └── views/
119
+ ├── ios/
120
+ │ └── index.xml
121
+ └── index.xml
122
+ ```
123
+
124
+ Alternatively, you can use special conditional code and attributes inside the controllers, views and styles to apply platform-specific code and components.
125
+
126
+ Additionally, the `assets` folder is laid out the same way as the `Resources` folder in a Titanium project for platform-specific files and density-specific images.
127
+
128
+ ## Widgets
129
+
130
+ Widgets are self-contained components that can be easily dropped into Alloy-powered Titanium projects. They were conceived as a way to reuse code in multiple applications or to be used multiple times in the same application. Widgets have their own models, views, controllers, styles and assets and are laid out the same as the `app` directory in the Alloy project.
131
+
132
+ * For information on using widgets in a project, see Importing Widgets.
133
+ * For information on creating widgets, see Creating Widgets.
134
+ * To search publicly available widgets, visit gitTio.
135
+
136
+ ## Builtins
137
+
138
+ Alloy comes with additional utilities used to simplify certain functions, such as animations, string manipulation, and display unit conversion. These utilities are referred to as 'builtins.' To use these utilities, the controller needs to call `require` with 'alloy' as the root directory. For example, to use an animation function to shake the current view by pressing the 'shake' button:
139
+
140
+ ```javascript
141
+ const animation = require('alloy/animation');
142
+ $.shake.addEventListener('click', e => {
143
+ animation.shake($.view);
144
+ });
145
+ ```
146
+
147
+ ## Compilation Process
148
+
149
+ This section provides a brief overview of how the Alloy command-line interface converts the files in the `app` folder to a Titanium project in the `Resources/<platform>` folder for each platform you build your project for. Before Alloy 1.3.0, Alloy creates only one Titanium project in the `Resources` folder.
150
+
151
+ ### Cleanup
152
+
153
+ The `Resources` folder is cleaned of any previous built files.
154
+
155
+ ### Build Configuration
156
+
157
+ If the build configuration file, `alloy.jmk`, exists, it is loaded. The 'pre:load' task executes at this point if it is defined.
158
+
159
+ ### Alloy Framework, Assets, and Lib
160
+
161
+ Alloy framework files, which include the Backbone.js and Underscore.js libraries, sync adapters and base controller class, are copied to the `Resources/<platform>/alloy` folder. The Alloy base library, `alloy.js`, is copied to the `Resources` folder. These files are necessary to run any Alloy project.
162
+
163
+ The project configuration file, `config.json`, is processed and copied to `Resources/<platform>/alloy/CFG.js`.
164
+
165
+ The files in the `assets` and `lib` folders, as well as the files in the theme's assets folder, are copied to the `Resources` folder.
166
+
167
+ The 'pre:compile' task executes at this point if it is defined.
168
+
169
+ ### Model-View-Controller and Widget Generation
170
+
171
+ The model files are processed. The compiler creates a JavaScript file per model and copies them to the `Resources/<platform>/alloy/models` folder.
172
+
173
+ The widget files are processed. The compiler creates a folder per widget that contains JavaScript files per view-controller and copies them to the `Resources/<platform>/alloy/widgets` folder.
174
+
175
+ The style, view, and controller files, as well as the files in the theme's style folder and the `app.tss` global style file, are processed. The compiler creates a JavaScript file per view-controller and copies them to the `Resources/<platform>/alloy/controllers` folder.
176
+
177
+ ### Main Application
178
+
179
+ Alloy creates a skeleton `app.js` file from a template. The contents of this file require some Alloy modules and calls the main view-controller `index.js`. If an initializer file, `alloy.js`, exists, the entire contents of the file are copied into the `app.js` file right before the call to initiate the main view-controller.
180
+
181
+ Before the file is written to the `Resources` directory, the 'compile:app.js' task executes if one is defined in the build configuration file.
182
+
183
+ ### Code Optimization
184
+
185
+ The generated code is processed through UglifyJS to optimize the code for speed and compactness. The code is optionally beautified.
186
+
187
+ If the code is compiled for a specific platform, all conditional code that should not be executed for that platform is removed. For example, if the application contains code sections specifically for iOS but the application is compiled for an Android platform, all of the iOS conditional code is removed.
188
+
189
+ Required Alloy builtin libraries are copied to the `Resources/<platform>/alloy` folder and optimized in the same process as described before.
190
+
191
+ Then, the 'post:compile' task executes if it is defined in the build configuration file.