mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-29 13:26:59 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62f0337198 | ||
|
|
eb89496733 | ||
|
|
5d6e070e01 | ||
|
|
ae31f9737f | ||
|
|
6e42537aa1 | ||
|
|
2b14076171 | ||
|
|
55ac8681af | ||
|
|
b5d2615307 | ||
|
|
6742ec84cf | ||
|
|
61d735662e | ||
|
|
050b89f82f | ||
|
|
1b179a603a | ||
|
|
4a6382aa7f | ||
|
|
f0c44c5719 | ||
|
|
2c2076bf69 | ||
|
|
5a67fec99e | ||
|
|
7cadd5fba4 | ||
|
|
6b59844084 | ||
|
|
b3963179d1 | ||
|
|
6a63c40e08 | ||
|
|
f91c525a30 | ||
|
|
19779a627f | ||
|
|
b19ad435df | ||
|
|
5627f789a3 | ||
|
|
1c9a812009 | ||
|
|
939398774d | ||
|
|
361dc99ea5 | ||
|
|
9f2a89a41e | ||
|
|
26df41b25e | ||
|
|
dd6fe54834 | ||
|
|
3cffa3a275 | ||
|
|
a0335be710 | ||
|
|
cabee3ae0b | ||
|
|
940c5e2451 | ||
|
|
870436ddd8 | ||
|
|
c3c8de77fc | ||
|
|
87807f180c | ||
|
|
9e344d527b | ||
|
|
2f9e36bdb2 | ||
|
|
5038e80bf2 | ||
|
|
7a2dbb276f | ||
|
|
3300e98ce2 | ||
|
|
693b795c2b | ||
|
|
ef8ab37eb4 | ||
|
|
118df1d952 | ||
|
|
8d4ff52b0f | ||
|
|
613c41fd6e | ||
|
|
ecac278f63 | ||
|
|
742890ee31 | ||
|
|
f08f11fb6f | ||
|
|
859e2f2767 | ||
|
|
19ad09eb66 | ||
|
|
39056a2868 | ||
|
|
8a2d560482 | ||
|
|
f62f960433 | ||
|
|
8fb67ce08d | ||
|
|
65b952d7f8 | ||
|
|
6c2a335b7c | ||
|
|
f717661eea | ||
|
|
35bdeb7519 | ||
|
|
93b927db63 | ||
|
|
9afdd2adb9 | ||
|
|
5fe87a04de | ||
|
|
7e2b75dd58 | ||
|
|
32e192e938 | ||
|
|
1af2b39db1 | ||
|
|
782eaf82f3 | ||
|
|
41d38e04a7 | ||
|
|
1611599a25 | ||
|
|
842cbc9e84 | ||
|
|
238d0e6a6c | ||
|
|
c5af3baaeb | ||
|
|
2030aa1af7 | ||
|
|
4445cb98cf | ||
|
|
12c420d861 | ||
|
|
dc33aa0b5d | ||
|
|
f200af909b | ||
|
|
6f3873ad6b | ||
|
|
70bb2e9d07 | ||
|
|
a9aaf0b940 | ||
|
|
80eb1506d8 | ||
|
|
68723d36f7 | ||
|
|
c937ee735e | ||
|
|
b553094742 | ||
|
|
f31ffed558 | ||
|
|
3f71f97b8b | ||
|
|
1a6308f621 |
@@ -1,4 +1,6 @@
|
||||
coverage/
|
||||
dist/
|
||||
tmp/
|
||||
build/
|
||||
src/scripts/vendor/
|
||||
src/js/index.js
|
||||
|
||||
+8
-23
@@ -1,31 +1,16 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
/coverage
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
/.lock-waf_darwin_build
|
||||
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
|
||||
tmp
|
||||
|
||||
dist
|
||||
/tmp/
|
||||
/src/js/index.js
|
||||
/dist.zip
|
||||
/build/
|
||||
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
# We ignore everying except for what is actually used by the pebble tool.
|
||||
/**/*
|
||||
!/dist.zip
|
||||
!/src/**/*
|
||||
!/index.js
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
# Contributing
|
||||
|
||||
Thanks for checking out Clay. We accept pull requests from anybody, however we ask
|
||||
that you follow some conventions when contributing to Clay.
|
||||
|
||||
We have set up a
|
||||
[piece-of-cake](https://github.com/pebble/clay/issues?q=is%3Aopen+is%3Aissue+label%3Apiece-of-cake)
|
||||
label in GitHub issues for bugs/features that are easy to implement. These issues are
|
||||
a great place to start for people that are new to the codebase.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Node](https://nodejs.org) (4.0 and later)
|
||||
- [Google Chrome](www.google.com/chrome) (To run tests)
|
||||
- [Pebble SDK](https://developer.pebble.com/sdk/) (optional)
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
### 1. Fork, then clone the repo:
|
||||
|
||||
`$ git clone git@github.com:your-username/clay.git`
|
||||
|
||||
### 2. Create a new branch with the following naming convention.
|
||||
|
||||
`#<issue-id>/description-of-change`
|
||||
|
||||
example:
|
||||
|
||||
`#90/support-message-keys`
|
||||
|
||||
If there is currently no GitHub issue open for your proposed contribution,
|
||||
then please make one. This allows us to assign milestones and triage priority.
|
||||
|
||||
### 3. Install the project dependencies.
|
||||
|
||||
`$ npm install`
|
||||
|
||||
### 4. Develop your feature
|
||||
|
||||
Commit as often as you like. Your branch will be squashed when the pull request is merged.
|
||||
|
||||
### 5. Run the tests
|
||||
|
||||
`$ npm run test`
|
||||
|
||||
### 6. Run linting
|
||||
|
||||
`$ npm run lint`
|
||||
|
||||
### 7. Submit your pull request
|
||||
|
||||
In the main comment of the pull request, you must state the GitHub issue that your PR
|
||||
resolves. You do this by using the syntax `Resolves #<issue-id>`. An example of this
|
||||
can be found [here](https://github.com/pebble/clay/pull/81)
|
||||
|
||||
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
|
||||
## Important Files
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
|
||||
### index.js
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`.
|
||||
It is responsible for serializing the provided config into a data URI that will be opened
|
||||
using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
|
||||
### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page,
|
||||
and is responsible for passing the injected config and other components to the
|
||||
`ClayConfig` class.
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
Use the following command to build Clay during development.
|
||||
|
||||
`$ npm run dev`
|
||||
|
||||
This command packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory
|
||||
so `dev/dev.html` can include them as script tags. This will also watch for changes
|
||||
in the project.
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to
|
||||
work with the files in the `dev/` directory than on a phone or emulator. Below is
|
||||
an explanation of the files and their purpose.
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependencies into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
|
||||
|
||||
## Testing your change inside of a test project.
|
||||
|
||||
Once your change is ready to be tested in the emulator or on the watch, follow these steps:
|
||||
|
||||
1. From your Clay fork run `$ npm run pebble-build`. This builds Clay to work with the Pebble SDK
|
||||
2. From your test Pebble project, run `$ pebble package install /path/to/your/clay/fork`.
|
||||
This will modify your `package.json` to point directly to your local copy of Clay.
|
||||
3. Run the usual`$ pebble build && pebble install --emulator basalt && pebble emu-app-config` to test your modifications
|
||||
4. If you make modifications to your fork of Clay, you must repeat the above steps.
|
||||
|
||||
|
||||
## Functionality
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js`
|
||||
initializes a new instance of `ClayConfig` and calls the injected custom function
|
||||
(`window.customFn`) with the `ClayConfig` as its context. This allows developers to
|
||||
add extra functionality to the config page, such as setting values of items dynamically
|
||||
or registering small custom components.
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over
|
||||
the config and injects each item into the page. Each item is an instance of `ClayItem`.
|
||||
It also indexes the items to later be retrieved with `.getAllItems()`,
|
||||
`.getItemByMessageKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
Clay enforces 100% test coverage. Chances are, that if you are submitting a pull request,
|
||||
there should be tests for the proposed code changes. Have a look at the other tests in
|
||||
the repository to see some examples of how you should be writing your tests.
|
||||
|
||||
There are two commands to use while writing your tests.
|
||||
|
||||
- `$ npm run test` - Runs all tests once.
|
||||
- `$ npm run test-debug` - Watches for file changes and re-runs all tests when it
|
||||
detects a change. This also leaves an in instance of Google Chrome running.
|
||||
If you click the "Debug" button in the top right of the page, a new tab will open.
|
||||
You can then use the Google Chrome developer tools to debug your tests as they run.
|
||||
Refreshing the page will re-run the tests.
|
||||
|
||||
## Style Guide
|
||||
|
||||
Our style guide is very similar to the
|
||||
[Airbnb style guide.](https://github.com/airbnb/javascript/tree/master/es5) with the
|
||||
following exceptions:
|
||||
|
||||
- When saving a reference to `this` use `self`.
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
var _this = this;
|
||||
return function() {
|
||||
console.log(_this);
|
||||
};
|
||||
}
|
||||
|
||||
// bad
|
||||
function() {
|
||||
var that = this;
|
||||
return function() {
|
||||
console.log(that);
|
||||
};
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
var self = this;
|
||||
return function() {
|
||||
console.log(self);
|
||||
};
|
||||
}
|
||||
```
|
||||
- Don't double name your functions. It makes refactoring more difficult.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var log = function log(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
// good
|
||||
var log = function(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
```
|
||||
|
||||
The style guide is enforced using ESLint. Run `$ npm run lint` to ensure you are
|
||||
adhering to the style guide.
|
||||
|
||||
## Getting Help
|
||||
|
||||
- Chat to us in the `#clay` channel on slack. http://slack.pbldev.io/
|
||||
- Visit the [Pebble Forums](https://forums.pebble.com/)
|
||||
- Tweet at [@pebbledev](https://twitter.com/pebbledev)
|
||||
- More options at https://developer.pebble.com/community/online/
|
||||
@@ -1,47 +1,46 @@
|
||||
# Clay
|
||||
Clay is a JavaScript library that makes it easy to add offline configuration pages to your Pebble apps. All you need to get started is a couple lines of JavaScript and a JSON file; no servers or HTML required.
|
||||
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `appKey` as defined in `appinfo.json` (or PebbleKit JS Message Keys on CloudPebble), and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `messageKey` as defined in `package.json` (or PebbleKit JS Message Keys on CloudPebble), and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
|
||||
**Clay is still in early development and may be missing some features. We would love your feedback! Pease submit any ideas or features via GitHub Issues.**
|
||||
Clay is distributed as a [Pebble package](https://developer.pebble.com/guides/pebble-packages/) so it is super easy to include in your project. If you are upgrading from v0.1.x of Clay you need to follow the [migration guide](#migrating-from-v01x-to-v1x) before you can get started.
|
||||
|
||||
# Getting Started (SDK)
|
||||
If you would like to contribute to Clay, check out the [contributing guide.](CONTRIBUTING.md)
|
||||
|
||||
Clay will eventually be built into the Pebble SDK. However, while it is still in beta you will need to follow the steps shown below:
|
||||
# Getting Started (SDK 3.13 or higher)
|
||||
|
||||
1. Download the **clay.js** distribution file from the [latest release](https://github.com/pebble/clay/releases/latest).
|
||||
2. Drop `clay.js` in your project's `src/js` directory.
|
||||
3. Create a JSON file called `config.json` and place it in your `src/js` directory.
|
||||
4. In order for JSON files to work you may need to change a line in your `wscript` from `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js'))` to `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']))`.
|
||||
5. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
1. Run `pebble package install pebble-clay` to install the package in your project
|
||||
2. Create a JSON file called `config.json` and place it in your `src/js` directory.
|
||||
3. In order for JSON files to work you may need to change a line in your `wscript` from `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js'))` to `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']))`.
|
||||
4. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
|
||||
```javascript
|
||||
var Clay = require('clay');
|
||||
var clayConfig = require('config.json');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
6. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
5. Ensure `pebble.enableMultiJS` is set to true in your `package.json`.
|
||||
6. Next is the fun part - creating your config page. Edit your `config.json` file to build a layout of elements as described in the sections below.
|
||||
7. Make sure you have defined all of your `messageKeys` in your `package.json`. More info on how that works [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
|
||||
# Getting Started (CloudPebble)
|
||||
|
||||
Clay will eventually be built into CloudPebble. However while it is still in beta, you will need to follow some steps.
|
||||
NOTE these are similar to using the SDK but instead of a data file called config.json, a javascript file config.js is required.
|
||||
|
||||
1. Create a new JavaScript file called `clay.js`.
|
||||
2. Copy the contents from the **clay.js** distribution file found in the [latest release](https://github.com/pebble/clay/releases/latest) into your newly created `clay.js` file.
|
||||
3. Create another JavaScript file called `config.js` with the following content. This will act as your config's root array element, from which the rest of the page is built up:
|
||||
1. Ensure `JS Handling` is set to `CommonJS-style` in your project settings.
|
||||
2. Under `Dependencies` in the project navigation, enter `pebble-clay` as the `Package Name` and `^1.0.0` for the `Version`. You may use any specific version you like, however using `^1.0.0` will ensure you receive all minor version updates.
|
||||
4. Create a JavaScript file called `config.js` with the following content. This will act as your config's root array element, from which the rest of the page is built up:
|
||||
|
||||
```javascript
|
||||
module.exports = [];
|
||||
```
|
||||
4. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
5. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
|
||||
```javascript
|
||||
var Clay = require('clay');
|
||||
var clayConfig = require('config');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
5. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
6. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
7. Make sure you have defined all of your message keys using `Automatic assignment` in your project settings. More info on how that works [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
|
||||
# Creating Your Config File
|
||||
|
||||
@@ -82,6 +81,7 @@ Sections help divide up the page into logical groups of items. It is recommended
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `section`. |
|
||||
| items | array | Array of items to include in this section. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this section to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -95,12 +95,12 @@ Sections help divide up the page into logical groups of items. It is recommended
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"messageKey": "email",
|
||||
"label": "Email Address"
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "enableAnimations",
|
||||
"messageKey": "enableAnimations",
|
||||
"label": "Enable Animations"
|
||||
}
|
||||
]
|
||||
@@ -121,9 +121,10 @@ Headings can be used in anywhere and can have their size adjusted to suit the co
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `heading`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The heading's text. |
|
||||
| size | int | Defaults to `4`. An integer from 1 to 6 where 1 is the largest size and 6 is the smallest. (represents HTML `<h1>`, `<h2>`, `<h3>`, etc). |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -151,8 +152,9 @@ Text is used to provide descriptions of sections or to explain complex parts of
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `text`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The content of the text element. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -178,11 +180,12 @@ Standard text input field.
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `input`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default value of the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attributes such as `required` or `type`. |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. Set `type` to values such as "email", "time", "date" etc to adjust the behavior of the component. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -190,13 +193,12 @@ Standard text input field.
|
||||
```javascript
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"messageKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Email Address",
|
||||
"attributes": {
|
||||
"placeholder": "eg: name@domain.com",
|
||||
"limit": 10,
|
||||
"required": "required",
|
||||
"type": "email"
|
||||
}
|
||||
}
|
||||
@@ -216,11 +218,11 @@ Switch for a single item.
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `toggle`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | int\|boolean | The default value of the toggle. Defaults to `false` if not specified. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -228,12 +230,9 @@ Switch for a single item.
|
||||
```javascript
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "invert",
|
||||
"messageKey": "invert",
|
||||
"label": "Invert Colors",
|
||||
"defaultValue": true,
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
"defaultValue": true
|
||||
}
|
||||
```
|
||||
|
||||
@@ -251,19 +250,19 @@ A dropdown menu containing multiple options.
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `select`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default value of the dropdown menu. Must match a value in the `options` array. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the dropdown menu. Each option is an object with a `label` and `value` property. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "select",
|
||||
"appKey": "flavor",
|
||||
"messageKey": "flavor",
|
||||
"defaultValue": "grape",
|
||||
"label": "Favorite Flavor",
|
||||
"options": [
|
||||
@@ -283,10 +282,58 @@ A dropdown menu containing multiple options.
|
||||
"label": "Banana",
|
||||
"value": "banana"
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
If you wish to use optgroups, then use the following format:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "select",
|
||||
"messageKey": "flavor",
|
||||
"defaultValue": "grape",
|
||||
"label": "Favorite Flavor",
|
||||
"options": [
|
||||
{
|
||||
"label": "",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"label": "Fruits",
|
||||
"value": [
|
||||
{
|
||||
"label": "Berry",
|
||||
"value": "berry"
|
||||
},
|
||||
{
|
||||
"label": "Grape",
|
||||
"value": "grape"
|
||||
},
|
||||
{
|
||||
"label": "Banana",
|
||||
"value": "banana"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Candy",
|
||||
"value": [
|
||||
{
|
||||
"label": "Chocolate",
|
||||
"value": "chocolate"
|
||||
},
|
||||
{
|
||||
"label": "Cream",
|
||||
"value": "cream"
|
||||
},
|
||||
{
|
||||
"label": "Lollipop",
|
||||
"value": "lollipop"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -309,20 +356,21 @@ The color picker will automatically show a different layout depending on the wat
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `color`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string OR int | The default color. One of the [64 colors](https://developer.pebble.com/guides/tools-and-resources/color-picker/) compatible with Pebble smartwatches. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| sunlight | boolean | Use the color-corrected sunlight color palette if `true`, else the uncorrected version. Defaults to `true` if not specified. |
|
||||
| layout | string OR array | Optional. Use a custom layout for the color picker. Defaults to automatically choosing the most appropriate layout for the connected watch. The layout is represented by a two dimensional array. Use `false` to insert blank spaces. You may also use one of the preset layouts by setting `layout` to: `"COLOR"`, `"GRAY"` or `"BLACK_WHITE"` |
|
||||
| allowGray | boolean | Optional. Set this to `true` to include gray (`#AAAAAA`) in the color picker for aplite running on firmware 3 and above. This is optional because only a subset of the drawing operations support gray on aplite. Defaults to `false` |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"messageKey": "background",
|
||||
"defaultValue": "ff0000",
|
||||
"label": "Background Color",
|
||||
"sunlight": true,
|
||||
@@ -339,7 +387,7 @@ The color picker will automatically show a different layout depending on the wat
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"messageKey": "background",
|
||||
"defaultValue": "ffffff",
|
||||
"label": "Background Color",
|
||||
"sunlight": false,
|
||||
@@ -352,7 +400,7 @@ The color picker will automatically show a different layout depending on the wat
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"messageKey": "background",
|
||||
"defaultValue": "aaaaaa",
|
||||
"label": "Background Color",
|
||||
"sunlight": false,
|
||||
@@ -374,19 +422,19 @@ A list of options allowing the user can only choose one option to submit.
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `radiogroup`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default selected item. Must match a value in the `options` array. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the radio group. Each option is an object with a `label` and `value` property. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "radiogroup",
|
||||
"appKey": "favorite_food",
|
||||
"messageKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"options": [
|
||||
{
|
||||
@@ -419,38 +467,27 @@ A list of options where a user may choose more than one option to submit.
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `checkboxgroup`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. **NOTE:** The checkboxgroup component will expect you to have defined a `messageKey` in your `package.json` using array syntax. In the example below, the matching entry in the `package.json` would be `favorite_food[3]`. In CloudPebble, you must use `Automatic assignment` for message keys and the `Key Array Length` must match the number of options in the checkboxgroup |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | array of strings | The default selected items. Each value must match one in the `options` array. |
|
||||
| defaultValue | array of booleans | The default selected items. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the checkbox group. Each option is an object with a `label` and `value` property. |
|
||||
| options | array of strings | The labels for each checkbox you want to appear in the checkbox group. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "checkboxgroup",
|
||||
"appKey": "favorite_food",
|
||||
"messageKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"defaultValue": ["sushi", "burgers"],
|
||||
"options": [
|
||||
{
|
||||
"label": "Sushi",
|
||||
"value": "sushi"
|
||||
},
|
||||
{
|
||||
"label": "Pizza",
|
||||
"value": "pizza"
|
||||
},
|
||||
{
|
||||
"label": "Burgers",
|
||||
"value": "burgers"
|
||||
}
|
||||
]
|
||||
"defaultValue": [true, false, true],
|
||||
"options": ["Sushi", "Pizza", "Burgers"]
|
||||
}
|
||||
```
|
||||
|
||||
In the above example, Sushi and Burgers will be selected by default.
|
||||
|
||||
---
|
||||
|
||||
### Generic Button
|
||||
@@ -464,8 +501,8 @@ A list of options where a user may choose more than one option to submit.
|
||||
| type | string | Set to `button`. |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| primary | boolean | If `true` the button will be orange, if `false`, the button will be gray (defaults to `false`)|
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -502,15 +539,15 @@ you must just remember to divide the received value on the watch accordingly.
|
||||
| min | number | The minimum allowed value of the slider. Defaults to `100` |
|
||||
| max | number | The maximum allowed value of the slider. Defaults to `0` |
|
||||
| step | number | The multiple of the values allowed to be set on the slider. The slider will snap to these values. This value also determines the precision used when the value is sent to the watch. Defaults to 1 |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "slider",
|
||||
"appKey": "slider",
|
||||
"messageKey": "slider",
|
||||
"defaultValue": 15,
|
||||
"label": "Slider",
|
||||
"description": "This is the description for the slider",
|
||||
@@ -534,7 +571,7 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `submit`. |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -547,13 +584,100 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
|
||||
---
|
||||
|
||||
### Coming Soon
|
||||
### Message keys and array syntax
|
||||
|
||||
- Tabs
|
||||
- Footer
|
||||
- Dynamic + draggable list
|
||||
Clay supports (and requires in some cases) the use of array syntax for message keys. Also known as `Automatic assignment` in CloudPebble. More info [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
|
||||
You can assign any component that does not return an array to a particular position in your message key. This is done by appending the position (zero indexed) wrapped in brackets to the end of the `messageKey` property. Do **NOT** include any spaces in your `messageKey`.
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "toggle",
|
||||
"messageKey": "light_switch[1]",
|
||||
"label": "Invert Colors",
|
||||
"defaultValue": true
|
||||
}
|
||||
```
|
||||
In the above example, the value of the item will be accessible with `MESSAGE_KEY_light_switch + 1` in your C code.
|
||||
|
||||
Components that return an array in their `.get()` method, such as the checkboxgroup will expect the corresponding message key to already be defined with the correct length. You **CAN NOT** use the array syntax in the `messageKey` property as this would be trying to create a 2 dimensional array.
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "checkboxgroup",
|
||||
"messageKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"defaultValue": [true, false, true],
|
||||
"options": ["Sushi", "Pizza", "Burgers"]
|
||||
}
|
||||
```
|
||||
In the above example, the value of the item will be accessible with `MESSAGE_KEY_favorite_food`, `MESSAGE_KEY_favorite_food + 1`, and `MESSAGE_KEY_favorite_food + 2` in your C code.
|
||||
|
||||
---
|
||||
### Showing items for specific platforms and features
|
||||
|
||||
If you want particular items or sections to only be present in the config based on the
|
||||
connected watch's capabilities, you can include the "capabilities" property in the item.
|
||||
The "capabilities" property is an array of features that the connected watch must have
|
||||
in order for the item or section to be included in the page. Note: all capabilities in
|
||||
the array must be present for item/section to be included.
|
||||
|
||||
You can also prefix the capability with `NOT_` to negate the capability. Eg: `NOT_HEALTH`
|
||||
will only be included in the page if the device does **NOT** support health.
|
||||
|
||||
**Warning:** Items that do not satisfy the capabilities will not be included in the page
|
||||
at all. You will not be able to use methods like `clayConfig.getItemByMessageKey()` to
|
||||
obtain a reference to them. However, this does mean that you will be able to have
|
||||
multiple items with the same `messageKey`as long as they do not both satisfy the
|
||||
same conditions.
|
||||
|
||||
##### Examples
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This item will only be visible for watches that are rectangular and have a microphone"
|
||||
"capabilities": ["MICROPHONE", "RECT"],
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "section",
|
||||
"capabilities": ["NOT_HEALTH"],
|
||||
"items": [
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "Only visible for watches that do not support health"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Below is the full list of capabilities
|
||||
|
||||
| Capability | Description |
|
||||
|------------|-------------|
|
||||
| PLATFORM_APLITE | Running on Pebble/Pebble Steel.|
|
||||
| PLATFORM_BASALT | Running on Pebble Time/Pebble Time Steel. |
|
||||
| PLATFORM_CHALK | Running on Pebble Time Round. |
|
||||
| PLATFORM_DIORITE | Running on Pebble 2 |
|
||||
| PLATFORM_EMERY | Running on Time 2. |
|
||||
| BW | Running on hardware that supports only black and white. |
|
||||
| COLOR | Running on hardware that supports 64 colors. |
|
||||
| MICROPHONE | Running on hardware that includes a microphone. |
|
||||
| SMARTSTRAP | Running on hardware that includes a smartstrap connector. |
|
||||
| SMARTSTRAP_POWER | Running on hardware that includes a powered smartstrap connector. |
|
||||
| HEALTH | Running on hardware that supports Pebble Health and the HealthService API. |
|
||||
| RECT | Running on hardware with a rectangular display. |
|
||||
| ROUND | Running on hardware with a round display. |
|
||||
| DISPLAY_144x168 | Running on hardware with a 144x168 pixels display. |
|
||||
| DISPLAY_180x180_ROUND | Running on hardware with a 180x180 pixels round display. |
|
||||
| DISPLAY_200x228 | Running on hardware with a 200x228 pixels display. |
|
||||
|
||||
## Manipulators
|
||||
|
||||
@@ -561,7 +685,7 @@ Each component has a **manipulator**. This is a set of methods used to talk to t
|
||||
At a minimum, manipulators must have a `.get()` and `.set(value)` method however there are also methods to assist in interactivity such as `.hide()` and `.disable()`.
|
||||
**NOTE:** There is currently no way to disable or hide an entire section. You must disable/hide each item in the section to achieve this effect.
|
||||
|
||||
When the config page is closed, the `.get()` method is run on all components registered with an `appKey` to construct the object sent to the C app.
|
||||
When the config page is closed, the `.get()` method is run on all components registered with an `messageKey` to construct the object sent to the C app.
|
||||
|
||||
Many of these methods fire an event when the method is called. You can listen for these events with `ClayItem.on()`.
|
||||
**NOTE** These events will only be fired if the state actually changes.
|
||||
@@ -636,7 +760,7 @@ Eg: If you run the `.show()` manipulator on an item that is already visible, the
|
||||
| Method | Returns | Event Fired | Description |
|
||||
|--------|---------|-------------| ------------|
|
||||
| `.set( [array] value)` | `ClayItem` | `change` | Checks the checkboxes that corresponds to the provided list of values. |
|
||||
| `.get()` | `Array.<string>` | | Gets an array of strings representing the list of the values of the checked items. **NOTE:** each item in the array will be separated by a zero when sent to the watch. See [`Clay.getSettings()`](#methods) |
|
||||
| `.get()` | `Array.<string>` | | Gets an array of booleans representing the list the checked items. **NOTE:** each item in the array will be converted to an `int` when sent to the watch. See [`Clay.getSettings()`](#methods) |
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. |
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. |
|
||||
| `.hide()` | `ClayItem` | `hide` | Hides the item |
|
||||
@@ -659,12 +783,12 @@ Clay is built to allow developers to add their own basic interactivity to the co
|
||||
|
||||
## Handling The 'showConfiguration' and 'webviewclosed' Events Manually
|
||||
|
||||
Clay will by default, automatically handle the 'showConfiguration' and 'webviewclosed' events. This allows the `appKey` of each config item to be automatically delivered to the `InboxReceivedHandler` on the watch side. If you wish to override this behavior and handle the events yourself, pass an object as the 3rd parameter of the Clay constructor with `autoHandleEvents` set to `false`.
|
||||
Clay will by default, automatically handle the 'showConfiguration' and 'webviewclosed' events. This allows the `messageKey` of each config item to be automatically delivered to the `InboxReceivedHandler` on the watch side. If you wish to override this behavior and handle the events yourself, pass an object as the 3rd parameter of the Clay constructor with `autoHandleEvents` set to `false`.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clayConfigAplite = require('./config-aplite');
|
||||
var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
||||
@@ -707,7 +831,7 @@ If you are using [Pebble.js](https://developer.pebble.com/docs/pebblejs/) and wo
|
||||
|
||||
```javascript
|
||||
var Settings = require('settings');
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig, null, {autoHandleEvents: false});
|
||||
|
||||
@@ -743,6 +867,8 @@ function cssColor(color) {
|
||||
cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
```
|
||||
|
||||
## Clay API (app.js)
|
||||
|
||||
### `Clay([Array] config, [function] customFn, [object] options)`
|
||||
|
||||
#### Constructor Parameters
|
||||
@@ -766,6 +892,7 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
|
||||
| `.meta.userData` | Any | A deep copy of the arbitrary data provided in the `options.userData`. Defaults to an empty object |
|
||||
| `.version` | String | The version of Clay currently being used. |
|
||||
|
||||
#### Methods
|
||||
|
||||
@@ -774,7 +901,39 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
| `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})` <br> `config` - an Array representing your config <br> `customFn` - function to be run in the context of the generated page <br> `options.autoHandleEvents` - set to `false` to prevent Clay from automatically handling the "showConfiguration" and "webviewclosed" events | `Clay` - a new instance of Clay. |
|
||||
| `.registerComponent( [ClayComponent] component )` <br> Registers a custom component. | `void`. |
|
||||
| `.generateUrl()` | `string` - The URL to open with `Pebble.openURL()` to use the Clay-generated config page. |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `appKey`, where the key is the `appKey` and the value is the chosen value of that item. This method will do some conversions depending on the type of the setting. Arrays containing strings will have zeros inserted before each item. eg `['one', 'two']` becomes `['one', 0, 'two', 0]`. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. Pass `false` as the second parameter to disable this behavior |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. <br><br>This method will do some conversions depending on the type of the setting. Arrays will use message key array syntax to make the values of each item in the array available as individual message keys. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. If the value is a number or an array of numbers and the optional property: "precision" is the power of precision (value * 10 ^ precision) and then floored. Eg: `1.4567` with a precision set to `3` will become `1456`. Pass `false` as the second parameter to disable this behavior. See the example below for how this all works |
|
||||
|
||||
#### `.getSettings()` Example
|
||||
|
||||
```javascript
|
||||
|
||||
// webviewclosed response
|
||||
{
|
||||
"favorite_food": {"value": [1, 0, 1]},
|
||||
"cool_things_enabled": {"value": true},
|
||||
"user_name": {"value": "Jane Doe"},
|
||||
"date_of_birth[0]": {"value": 1989},
|
||||
"date_of_birth[1]": {"value": 11},
|
||||
"date_of_birth[2]": {"value": 28},
|
||||
"rating": {"value": 3.5, "precision": 1},
|
||||
}
|
||||
|
||||
// resulting converted values
|
||||
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
messageKeys.favorite_food + 0 = 1;
|
||||
messageKeys.favorite_food + 1 = 0;
|
||||
messageKeys.favorite_food + 2 = 1;
|
||||
messageKeys.cool_things_enabled = 1;
|
||||
messageKeys.user_name = 'Jane Doe';
|
||||
messageKeys.date_of_birth + 0 = 1989;
|
||||
messageKeys.date_of_birth + 1 = 11;
|
||||
messageKeys.date_of_birth + 2 = 28;
|
||||
messageKeys.rating = 35;
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -794,7 +953,7 @@ Make sure to always wait for the config page to be built before manipulating ite
|
||||
##### app.js
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var customClay = require('./custom-clay');
|
||||
var userData = {token: 'abc123'}
|
||||
@@ -812,20 +971,20 @@ module.exports = function(minified) {
|
||||
|
||||
function toggleBackground() {
|
||||
if (this.get()) {
|
||||
clayConfig.getItemByAppKey('background').enable();
|
||||
clayConfig.getItemByMessageKey('background').enable();
|
||||
} else {
|
||||
clayConfig.getItemByAppKey('background').disable();
|
||||
clayConfig.getItemByMessageKey('background').disable();
|
||||
}
|
||||
}
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = clayConfig.getItemByAppKey('cool_stuff');
|
||||
var coolStuffToggle = clayConfig.getItemByMessageKey('cool_stuff');
|
||||
toggleBackground.call(coolStuffToggle);
|
||||
coolStuffToggle.on('change', toggleBackground);
|
||||
|
||||
// Hide the color picker for aplite
|
||||
if (!clayConfig.meta.activeWatchInfo || clayConfig.meta.activeWatchInfo.platform === 'aplite') {
|
||||
clayConfig.getItemByAppKey('background').hide();
|
||||
clayConfig.getItemByMessageKey('background').hide();
|
||||
}
|
||||
|
||||
// Set the value of an item based on the userData
|
||||
@@ -841,7 +1000,7 @@ module.exports = function(minified) {
|
||||
};
|
||||
```
|
||||
|
||||
## Clay API
|
||||
## Clay API (Custom Function)
|
||||
|
||||
### `ClayConfig([Object] settings, [Array] config, [$Minified] $rootContainer)`
|
||||
|
||||
@@ -853,6 +1012,8 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
|----------|------|-------------|
|
||||
| `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page. |
|
||||
| `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page. |
|
||||
| `.EVENTS.BEFORE_DESTROY` | String | Dispatched prior to destroying the page. |
|
||||
| `.EVENTS.AFTER_DESTROY` | String | Dispatched after destroying the page. |
|
||||
| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. |
|
||||
| `.meta` | Object | Contains information about the current user and watch |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
@@ -866,11 +1027,12 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
| Method | Returns |
|
||||
|--------|---------|
|
||||
| `.getAllItems()` | `Array.<ConfigItem>` - an array of all config items. |
|
||||
| `.getItemByAppKey( [string] appKey )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `appKey`, otherwise `undefined`. |
|
||||
| `.getItemByMessageKey( [string] messageKey )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `messageKey`, otherwise `undefined`. |
|
||||
| `.getItemById( [string] id )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `id`, otherwise `undefined`. |
|
||||
| `.getItemsByType( [string] type )` | `Array.<ConfigItem>` - an array of config items that match the provided `type`. |
|
||||
| `.serialize()` | `Object` - an object representing all items with an `appKey` where the key is the `appKey` and the value is an object with the `value` property set to the result of running `.get()` on the Clay item. If the Clay item has a `precision` property set, it is included in the object |
|
||||
| `.build()` <br> Builds the config page. Will dispatch the `BEFORE_BUILD` event prior to building the page, then the `AFTER_BUILD` event once it is complete. | `ClayConfig` |
|
||||
| `.serialize()` | `Object` - an object representing all items with an `messageKey` where the key is the `messageKey` and the value is an object with the `value` property set to the result of running `.get()` on the Clay item. If the Clay item has a `precision` property set, it is included in the object |
|
||||
| `.build()` <br> Builds the config page. Will dispatch the `BEFORE_BUILD` event prior to building the page, then the `AFTER_BUILD` event once it is complete. If the config page has already been built, then the `ClayConfig.destroy()` method will be executed prior to building the page again. | `ClayConfig` |
|
||||
| `.destroy()` <br> Destroys the config page. Will dispatch the `BEFORE_DESTROY` event prior to destroying the page, then the `AFTER_DESTROY` event once it is complete. This method wipes the config page completely, including all existing items. You will need to make sure that you re-attach your event handlers for any items that are replaced | `ClayConfig` |
|
||||
| `.on( [string] events, [function] handler )` <br> Register an event to the provided handler. The handler will be called with this instance of `ClayConfig` as the context. If you wish to register multiple events to the same handler, then separate the events with a space | `ClayConfig` |
|
||||
| `.off( [function] handler )` <br> Remove the given event handler. **NOTE:** This will remove the handler from all registered events. | `ClayConfig` |
|
||||
| `.trigger( [string] name, [object] eventObj={} )` <br> Trigger the provided event and optionally pass extra data to the handler. | `ClayConfig` |
|
||||
@@ -885,7 +1047,7 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `.id` | String | The ID of the item if provided in the config. |
|
||||
| `.appKey` | String | The ID of the item if provided in the config. |
|
||||
| `.messageKey` | String | The ID of the item if provided in the config. |
|
||||
| `.config` | Object | Reference to the config passed to the constructer. |
|
||||
| `$element` | $Minified | A Minified list representing the root HTML element of the config item. |
|
||||
| `$manipulatorTarget` | $Minified | A Minified list representing the HTML element with **data-manipulator-target** set. This is generally pointing to the main `<input>` element and will be used for binding events. |
|
||||
@@ -921,15 +1083,15 @@ Components are simple objects with the following properties.
|
||||
| `style` | string | no | Any extra CSS styles you want to inject into the page. Make sure to namespace your CSS with a class that is unique to your component in order to avoid conflicts with other components. |
|
||||
| `manipulator` | string / manipulator | yes | Provide a string here to use one of the built-in manipulators, such as `val`. If an object is provided, it must have both a `.set(value)` and `.get()` method. |
|
||||
| `defaults` | object | Only if your template requires it. | An object of all the defaults your template requires. |
|
||||
| `initialize` | function | no | Method which will be called after the item has been added to the page. It will be called with the `ClayItem` as the context (`this`) and with [`minified`](#minified) as the first parameter and [`clayConfig`](#clayconfigobject-settings-array-config-minified-rootcontainer) as the second paramater |
|
||||
| `initialize` | function | no | Method which will be called after the item has been added to the page. It will be called with the `ClayItem` as the context (`this`) and with [`minified`](#minified) as the first parameter and [`clayConfig`](#clayconfigobject-settings-array-config-minified-rootcontainer) as the second parameter |
|
||||
|
||||
### Registering a custom component.
|
||||
|
||||
Components must be registered before the config page is built. The easiest way to do this is in your `app.js` after you have initialized Clay:
|
||||
|
||||
```javascript
|
||||
var Clay = require('clay');
|
||||
var clayConfig = require('config.json');
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
|
||||
clay.registerComponent(require('./my-custom-component'));
|
||||
@@ -965,52 +1127,164 @@ clay.registerComponent(require('./my-custom-component'));
|
||||
- `_.template()`
|
||||
- `_.isObject()`
|
||||
|
||||
# Project Structure and Development
|
||||
# Migrating from v0.1.x to v1.x
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
There were some changes in the 3.13 SDK that required Clay to undergo some major changes. For the majority of developers a simple find and replace over your config will do the trick.
|
||||
|
||||
#### index.js
|
||||
### appKey is now messageKey.
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`. It is responsible for serializing the provided config into a data URI that will be opened using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
You will need to update your config files and change any items that use `appKey` to `messageKey`
|
||||
|
||||
#### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page, and is responsibe for passing the injected config and other components to the `ClayConfig` class.
|
||||
|
||||
|
||||
### Building
|
||||
|
||||
There are two ways to build Clay, production mode and development mode.
|
||||
|
||||
#### Production Mode
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "invert",
|
||||
"label": "Invert Colors",
|
||||
"defaultValue": true
|
||||
}
|
||||
```
|
||||
$ npm run build
|
||||
becomes:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "toggle",
|
||||
"messageKey": "invert",
|
||||
"label": "Invert Colors",
|
||||
"defaultValue": true
|
||||
}
|
||||
```
|
||||
|
||||
Packages up the entire Clay project into `dist/clay.js` to be required in the developer's `app.js`.
|
||||
### clayConfig.getItemByAppKey is now clayConfig.getItemByMessageKey.
|
||||
|
||||
#### Development Mode
|
||||
If you have a [custom function](#custom-function) and are using the `clayConfig.getItemByAppKey()` method you will need to change this to `clayConfig.getItemByMessageKey()`
|
||||
|
||||
```
|
||||
$ npm run dev
|
||||
### clay.getSettings() will now by default, return an object where the keys are numbers.
|
||||
|
||||
In the past, `clay.getSettings()` would return something that looked like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
BACKGROUND_COLOR: 0,
|
||||
NAME: 'Jane Doe',
|
||||
ENABLE_TOOLS: 1
|
||||
}
|
||||
```
|
||||
|
||||
Packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory so `dev/dev.html` can include them as script tags. This will also watch for changes in the project.
|
||||
It now uses the values provided in the `message_keys` module to construct this object.
|
||||
The new format looks something like:
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to work with the files in the `dev/` directory than on a phone or emulator. Below is an explanation of the files and their purpose.
|
||||
```javascript
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
```
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependancies things into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
If you wish to find out what keys are associated with what values, you must use the `message_keys` module.
|
||||
|
||||
## Functionality
|
||||
```javascript
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js` initializes a new instance of `ClayConfig` and calls the injected custom function (`window.customFn`) with the `ClayConfig` as its context. This allows developers to add extra functionality to the config page, such as setting values of items dynamically or registering small custom components.
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
// Get the keys and values from each config item
|
||||
var claySettings = clay.getSettings(e.response);
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over the config and injects each item into the page. Each item is an instance of `ClayItem`. It also indexes the items to later be retrieved with `.getAllItems()`, `.getItemByAppKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
// In this example messageKeys.NAME is equal to 10001
|
||||
console.log('Name is ' + claySettings[messageKeys.NAME]); // Logs: "Name is Jane Doe"
|
||||
});
|
||||
```
|
||||
|
||||
**NOTE:** The above only applies to the default behavior of the method. If you pass
|
||||
`false` to the second argument, a standard object will be returned with the `messageKey`
|
||||
as the key.
|
||||
|
||||
```javascript
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
clay.getSettings(e.response);
|
||||
/* returns:
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
*/
|
||||
|
||||
clay.getSettings(e.response, false);
|
||||
/* returns:
|
||||
{
|
||||
BACKGROUND_COLOR: {value: 0},
|
||||
NAME: {value: 'Jane Doe'},
|
||||
ENABLE_TOOLS: {value: true}
|
||||
}
|
||||
|
||||
Notice that the value for ENABLE_TOOLS was not converted to a number from a boolean
|
||||
*/
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Checkbox groups now use arrays.
|
||||
|
||||
In the previous version of Clay, checkbox groups would split the values of the items with zeros. This made for clumsy usage on the C side. Checkbox groups are now much simpler to use thanks to message keys. You will however need to update you config to the new format.
|
||||
|
||||
#### Changes:
|
||||
- `defaultValue` and the value that is returned by the `.get()` method is now an array of booleans.
|
||||
- `options` are now an array of labels and do not have their own value
|
||||
- Instead of splitting the result on the C side you now use the message key syntax. In the example below `MESSAGE_KEY_favorite_food + 2` would have a value of `1`
|
||||
|
||||
#### Old Format
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "checkboxgroup",
|
||||
"appKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"defaultValue": ["sushi", "burgers"],
|
||||
"options": [
|
||||
{
|
||||
"label": "Sushi",
|
||||
"value": "sushi"
|
||||
},
|
||||
{
|
||||
"label": "Pizza",
|
||||
"value": "pizza"
|
||||
},
|
||||
{
|
||||
"label": "Burgers",
|
||||
"value": "burgers"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### New Format
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "checkboxgroup",
|
||||
"messageKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"defaultValue": [true, false, true],
|
||||
"options": ["Sushi", "Pizza", "Burgers"]
|
||||
}
|
||||
```
|
||||
|
||||
### Clay is now a pebble package
|
||||
|
||||
You no longer need to download a file into your project. Clay is now a Pebble package so you can go ahead and delete your `clay.js` and follow the getting started guide above to install clay in your project.
|
||||
|
||||
Prior to SDK 3.13, `require` paths were handled in a non-standard way. When requiring modules, the name of the module was sufficient (ie. `require('config.json')`). However, with the release of SDK 3.13, the require paths changed so that you now have to require the module by using its path relative to the file it's being required in. This means requiring the config module now is done in app.js by using `require('./clay-config.json')`. An incorrect path would result in an error similar to this:
|
||||
```
|
||||
[14:16:03] javascript> JavaScript Error:
|
||||
Error: Cannot find module 'clay-config.json'
|
||||
at Object.loader.require (loader.js:66:11)
|
||||
at _require.require (loader.js:54:48)
|
||||
at Object.loader (src/js/app.js:1:1)
|
||||
at _require (loader.js:57:10)
|
||||
at Object.loader.require (loader.js:69:10)
|
||||
```
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
/* eslint-disable quotes */
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
"type": "heading",
|
||||
"id": "main-heading",
|
||||
"defaultValue": "Clay Test Page",
|
||||
"size": 1
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This is config 2"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
{
|
||||
"type": "heading",
|
||||
"defaultValue": "This is a section"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"messageKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Input Field",
|
||||
"description": "This is a new field",
|
||||
"attributes": {
|
||||
"placeholder": "Placeholder set with attributes"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "submit",
|
||||
"defaultValue": "Save"
|
||||
}
|
||||
];
|
||||
+60
-15
@@ -13,6 +13,17 @@ module.exports = [
|
||||
"defaultValue": "Some arbitrary text explaining how this all works. " +
|
||||
"It's cool if this wraps across multiple lines"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"capabilities": ["RECT", "MICROPHONE"],
|
||||
"items": [
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This section is only visible for rectangular devices that" +
|
||||
" have a microphone"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
@@ -20,9 +31,14 @@ module.exports = [
|
||||
"type": "heading",
|
||||
"defaultValue": "This is a section"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This is only visible for aplite",
|
||||
"capabilities": ["APLITE"]
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"messageKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Input Field",
|
||||
"description": "This is a description for the input component. " +
|
||||
@@ -31,9 +47,23 @@ module.exports = [
|
||||
"placeholder": "Placeholder set with attributes"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"label": "Time Field",
|
||||
"attributes": {
|
||||
"type": "time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"label": "Date Field",
|
||||
"attributes": {
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "slider",
|
||||
"appKey": "slider",
|
||||
"messageKey": "slider",
|
||||
"defaultValue": 15,
|
||||
"label": "Slider",
|
||||
"description": "This is the description for the slider",
|
||||
@@ -43,20 +73,32 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "cool_stuff",
|
||||
"messageKey": "cool_stuff",
|
||||
"label": "This is a Toggle",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"messageKey": "arrayToggle[0]",
|
||||
"label": "This is a Toggle",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"messageKey": "arrayToggle[1]",
|
||||
"label": "This is a Toggle",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "colorTest",
|
||||
"messageKey": "colorTest",
|
||||
"defaultValue": "FF0000",
|
||||
"label": "Standard Color Picker",
|
||||
"sunlight": false
|
||||
},
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "sunnyColorTest",
|
||||
"messageKey": "sunnyColorTest",
|
||||
"defaultValue": "00FF00",
|
||||
"label": "Sunny Color Picker",
|
||||
"sunlight": true
|
||||
@@ -80,7 +122,7 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
"type": "radiogroup",
|
||||
"appKey": "radiogroup-test",
|
||||
"messageKey": "radiogroup-test",
|
||||
"label": "Radio Group",
|
||||
"options": [
|
||||
{ "label": "Test thing", "value": "one" },
|
||||
@@ -90,25 +132,28 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
"type": "checkboxgroup",
|
||||
"appKey": "checkboxgroup-test",
|
||||
"defaultValue": ["quote' \"test", "two"],
|
||||
"messageKey": "checkboxgroup-test",
|
||||
"defaultValue": [0, 1, 0],
|
||||
"label": "Checkbox Group",
|
||||
"options": [
|
||||
{ "label": "First thing", "value": "three" },
|
||||
{ "label": "Another thing", "value": "two" },
|
||||
{ "label": "Final thing", "value": "three" }
|
||||
]
|
||||
"options": [ "First thing", "Another thing", "Final thing" ]
|
||||
},
|
||||
{
|
||||
"type": "select",
|
||||
"appKey": "flavor",
|
||||
"messageKey": "flavor",
|
||||
"defaultValue": "grape",
|
||||
"label": "Select Menu",
|
||||
"options": [
|
||||
{ "label": "", "value": "" },
|
||||
{ "label": "Berry", "value": "berry" },
|
||||
{ "label": "This Option is Selected", "value": "grape" },
|
||||
{ "label": "Banana", "value": "banana" }
|
||||
{ "label": "Banana", "value": "banana" },
|
||||
{
|
||||
"label": "This is an optgroup",
|
||||
"value": [
|
||||
{ "label": "Peach", "value": "peach" },
|
||||
{ "label": "Mango", "value": "mango" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
|
||||
+13
-3
@@ -10,16 +10,26 @@ module.exports = function() {
|
||||
*/
|
||||
function toggleBackground() {
|
||||
if (this.get()) {
|
||||
Clay.getItemByAppKey('colorTest').enable();
|
||||
Clay.getItemByMessageKey('colorTest').enable();
|
||||
} else {
|
||||
Clay.getItemByAppKey('colorTest').disable();
|
||||
Clay.getItemByMessageKey('colorTest').disable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
function handleButtonClick() {
|
||||
Clay.config = Clay.meta.userData.config2;
|
||||
Clay.build();
|
||||
}
|
||||
|
||||
Clay.on(Clay.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = Clay.getItemByAppKey('cool_stuff');
|
||||
var coolStuffToggle = Clay.getItemByMessageKey('cool_stuff');
|
||||
toggleBackground.call(coolStuffToggle);
|
||||
coolStuffToggle.on('change', toggleBackground);
|
||||
|
||||
Clay.getItemById('testButton').on('click', handleButtonClick);
|
||||
});
|
||||
|
||||
console.log('userData: ', Clay.meta.userData);
|
||||
|
||||
+15
-1
@@ -6,7 +6,21 @@ window.claySettings = {};
|
||||
window.customFn = require('./custom-fn.js');
|
||||
window.clayComponents = require('../src/scripts/components');
|
||||
window.clayMeta = require('../test/fixture').meta({
|
||||
userData: {foo: 'bar'}
|
||||
activeWatchInfo: {
|
||||
platform: 'basalt',
|
||||
model: 'qemu_platform_basalt',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 2,
|
||||
suffix: ''
|
||||
}
|
||||
},
|
||||
userData: {
|
||||
foo: 'bar',
|
||||
config2: require('./config-2')
|
||||
}
|
||||
});
|
||||
|
||||
var platform = window.navigator.userAgent.match(/Android/) ? 'android' : 'ios';
|
||||
|
||||
+8
-5
@@ -15,6 +15,7 @@ var uglify = require('gulp-uglify');
|
||||
var sassify = require('sassify');
|
||||
var autoprefixify = require('./src/scripts/vendor/autoprefixify');
|
||||
var insert = require('gulp-insert');
|
||||
var clayPackage = require('./package.json');
|
||||
|
||||
var sassIncludePaths = [].concat(
|
||||
require('bourbon').includePaths,
|
||||
@@ -37,7 +38,7 @@ var autoprefixerOptions = {
|
||||
|
||||
var stringifyOptions = ['.html', '.tpl'];
|
||||
var versionMessage = '/* Clay - https://github.com/pebble/clay - Version: ' +
|
||||
require('./package.json').version +
|
||||
clayPackage.version +
|
||||
' - Build Date: ' + new Date().toISOString() + ' */\n';
|
||||
|
||||
gulp.task('clean-js', function() {
|
||||
@@ -84,21 +85,22 @@ gulp.task('inlineHtml', ['js', 'sass'], function() {
|
||||
gulp.task('clay', ['inlineHtml'], function() {
|
||||
return browserify('index.js', {
|
||||
debug: false,
|
||||
standalone: 'clay'
|
||||
standalone: clayPackage.name
|
||||
})
|
||||
.transform('deamdify')
|
||||
.transform(stringify(stringifyOptions))
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
.require(require.resolve('./index'), {expose: 'pebble-clay'})
|
||||
.require(require.resolve('./index'), {expose: clayPackage.name})
|
||||
.exclude('message_keys')
|
||||
.bundle()
|
||||
.pipe(source('clay.js'))
|
||||
.pipe(source('index.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify({
|
||||
preserveComments: 'license'
|
||||
}))
|
||||
.pipe(insert.prepend(versionMessage))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
.pipe(gulp.dest('./src/js'));
|
||||
});
|
||||
|
||||
gulp.task('dev-js', ['js', 'sass'], function() {
|
||||
@@ -107,6 +109,7 @@ gulp.task('dev-js', ['js', 'sass'], function() {
|
||||
.transform('deamdify')
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
.ignore('message_keys')
|
||||
.bundle()
|
||||
.pipe(source('dev.js'))
|
||||
.pipe(gulp.dest('./tmp/'));
|
||||
|
||||
@@ -4,6 +4,8 @@ var configPageHtml = require('./tmp/config-page.html');
|
||||
var toSource = require('tosource');
|
||||
var standardComponents = require('./src/scripts/components');
|
||||
var deepcopy = require('deepcopy/build/deepcopy.min');
|
||||
var version = require('./package.json').version;
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
/**
|
||||
* @param {Array} config - the Clay config
|
||||
@@ -38,6 +40,7 @@ function Clay(config, customFn, options) {
|
||||
watchToken: '',
|
||||
userData: {}
|
||||
};
|
||||
self.version = version;
|
||||
|
||||
/**
|
||||
* Populate the meta with data from the Pebble object. Make sure to run this inside
|
||||
@@ -80,23 +83,50 @@ function Clay(config, customFn, options) {
|
||||
}
|
||||
|
||||
/**
|
||||
* If this function returns true then the callback will be executed
|
||||
* @callback _scanConfig_testFn
|
||||
* @param {Clay~ConfigItem} item
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback _scanConfig_callback
|
||||
* @param {Clay~ConfigItem} item
|
||||
*/
|
||||
|
||||
/**
|
||||
* Scan over the config and run the callback if the testFn resolves to true
|
||||
* @private
|
||||
* @param {Clay~ConfigItem|Array} item
|
||||
* @param {_scanConfig_testFn} testFn
|
||||
* @param {_scanConfig_callback} callback
|
||||
* @return {void}
|
||||
*/
|
||||
function _registerStandardComponents(item) {
|
||||
function _scanConfig(item, testFn, callback) {
|
||||
if (Array.isArray(item)) {
|
||||
item.forEach(function(item) {
|
||||
_registerStandardComponents(item);
|
||||
_scanConfig(item, testFn, callback);
|
||||
});
|
||||
} else if (item.type === 'section') {
|
||||
_registerStandardComponents(item.items);
|
||||
} else if (standardComponents[item.type]) {
|
||||
self.registerComponent(standardComponents[item.type]);
|
||||
_scanConfig(item.items, testFn, callback);
|
||||
} else if (testFn(item)) {
|
||||
callback(item);
|
||||
}
|
||||
}
|
||||
|
||||
_registerStandardComponents(self.config);
|
||||
// register standard components
|
||||
_scanConfig(self.config, function(item) {
|
||||
return standardComponents[item.type];
|
||||
}, function(item) {
|
||||
self.registerComponent(standardComponents[item.type]);
|
||||
});
|
||||
|
||||
// validate config against teh use of appKeys
|
||||
_scanConfig(self.config, function(item) {
|
||||
return item.appKey;
|
||||
}, function() {
|
||||
throw new Error('appKeys are no longer supported. ' +
|
||||
'Please follow the migration guide to upgrade your project');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,9 +190,10 @@ Clay.prototype.generateUrl = function() {
|
||||
Clay.prototype.getSettings = function(response, convert) {
|
||||
// Decode and parse config data as JSON
|
||||
var settings = {};
|
||||
response = response.match(/^\{/) ? response : decodeURIComponent(response);
|
||||
|
||||
try {
|
||||
settings = JSON.parse(decodeURIComponent(response));
|
||||
settings = JSON.parse(response);
|
||||
} catch (e) {
|
||||
throw new Error('The provided response was not valid JSON');
|
||||
}
|
||||
@@ -197,8 +228,8 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Strings will be returned without modification
|
||||
* - Numbers will be returned without modification
|
||||
* - Booleans will be converted to a 0 or 1
|
||||
* - Arrays that contain strings will be split with a zero.
|
||||
* eg: ['one', 'two'] becomes ['one', 0, 'two', 0]
|
||||
* - Arrays that contain strings will be returned without modification
|
||||
* eg: ['one', 'two'] becomes ['one', 'two']
|
||||
* - Arrays that contain numbers will be returned without modification
|
||||
* eg: [1, 2] becomes [1, 2]
|
||||
* - Arrays that contain booleans will be converted to a 0 or 1
|
||||
@@ -206,12 +237,12 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Arrays must be single dimensional
|
||||
* - Objects that have a "value" property will apply the above rules to the type of
|
||||
* value. If the value is a number or an array of numbers and the optional
|
||||
* property: "precision" is provided, then the number will be multipled by 10 to
|
||||
* property: "precision" is provided, then the number will be multiplied by 10 to
|
||||
* the power of precision (value * 10 ^ precision) and then floored.
|
||||
* Eg: 1.4567 with a precision set to 3 will become 1456
|
||||
* @param {number|string|boolean|Array|Object} val
|
||||
* @param {number|string|boolean|Array} val.value
|
||||
* @param {number} [val.precision=0]
|
||||
* @param {number|undefined} [val.precision=0]
|
||||
* @returns {number|string|Array}
|
||||
*/
|
||||
Clay.prepareForAppMessage = function(val) {
|
||||
@@ -232,12 +263,8 @@ Clay.prepareForAppMessage = function(val) {
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
result = [];
|
||||
val.forEach(function(item) {
|
||||
var itemConverted = Clay.prepareForAppMessage(item);
|
||||
result.push(itemConverted);
|
||||
if (typeof itemConverted === 'string') {
|
||||
result.push(0);
|
||||
}
|
||||
val.forEach(function(item, index) {
|
||||
result[index] = Clay.prepareForAppMessage(item);
|
||||
});
|
||||
} else if (typeof val === 'object' && val) {
|
||||
if (typeof val.value === 'number') {
|
||||
@@ -263,16 +290,56 @@ Clay.prepareForAppMessage = function(val) {
|
||||
|
||||
/**
|
||||
* Converts a Clay settings dict into one that is compatible with
|
||||
* Pebble.sendAppMessage();
|
||||
* Pebble.sendAppMessage(); It also uses the provided messageKeys to correctly
|
||||
* assign arrays into individual keys
|
||||
* @see {prepareForAppMessage}
|
||||
* @param {Object} settings
|
||||
* @returns {{}}
|
||||
*/
|
||||
Clay.prepareSettingsForAppMessage = function(settings) {
|
||||
var result = {};
|
||||
|
||||
// flatten settings
|
||||
var flatSettings = {};
|
||||
Object.keys(settings).forEach(function(key) {
|
||||
result[key] = Clay.prepareForAppMessage(settings[key]);
|
||||
var val = settings[key];
|
||||
var matches = key.match(/(.+?)(?:\[(\d*)\])?$/);
|
||||
|
||||
if (!matches[2]) {
|
||||
flatSettings[key] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
var position = parseInt(matches[2], 10);
|
||||
key = matches[1];
|
||||
|
||||
if (typeof flatSettings[key] === 'undefined') {
|
||||
flatSettings[key] = [];
|
||||
}
|
||||
|
||||
flatSettings[key][position] = val;
|
||||
});
|
||||
|
||||
var result = {};
|
||||
Object.keys(flatSettings).forEach(function(key) {
|
||||
var messageKey = messageKeys[key];
|
||||
var settingArr = Clay.prepareForAppMessage(flatSettings[key]);
|
||||
settingArr = Array.isArray(settingArr) ? settingArr : [settingArr];
|
||||
|
||||
settingArr.forEach(function(setting, index) {
|
||||
result[messageKey + index] = setting;
|
||||
});
|
||||
});
|
||||
|
||||
// validate the settings
|
||||
Object.keys(result).forEach(function(key) {
|
||||
if (Array.isArray(result[key])) {
|
||||
throw new Error('Clay does not support 2 dimensional arrays for item ' +
|
||||
'values. Make sure you are not attempting to use array ' +
|
||||
'syntax (eg: "myMessageKey[2]") in the messageKey for ' +
|
||||
'components that return an array, such as a checkboxgroup');
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
+26
-8
@@ -1,32 +1,50 @@
|
||||
{
|
||||
"name": "pebble-clay",
|
||||
"version": "0.1.4",
|
||||
"version": "1.0.2",
|
||||
"description": "Pebble Config Framework",
|
||||
"main": "dist/clay.js",
|
||||
"directories": {
|
||||
"example": "example"
|
||||
},
|
||||
"scripts": {
|
||||
"test-travis": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run --browsers chromeTravisCI && ./node_modules/.bin/eslint ./",
|
||||
"test-debug": "(export DEBUG=true && ./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --no-single-run)",
|
||||
"test": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run",
|
||||
"lint": "./node_modules/.bin/eslint ./",
|
||||
"build": "gulp",
|
||||
"dev": "gulp dev"
|
||||
"dev": "gulp dev",
|
||||
"pebble-clean": "rm -rf tmp src/js/index.js && pebble clean",
|
||||
"pebble-publish": "npm run pebble-clean && npm run build && pebble build && pebble package publish && npm run pebble-clean",
|
||||
"pebble-build": "npm run build && pebble build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pebble/clay.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Pebble",
|
||||
"Config"
|
||||
"pebble",
|
||||
"config",
|
||||
"configuration",
|
||||
"pebble-package"
|
||||
],
|
||||
"author": "Pebble Technology",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pebble/clay/issues"
|
||||
},
|
||||
"pebble": {
|
||||
"projectType": "package",
|
||||
"sdkVersion": "3",
|
||||
"targetPlatforms": [
|
||||
"aplite",
|
||||
"basalt",
|
||||
"chalk",
|
||||
"diorite",
|
||||
"emery"
|
||||
],
|
||||
"resources": {
|
||||
"media": []
|
||||
},
|
||||
"capabilities": [
|
||||
"configurable"
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/pebble/clay#readme",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^6.3.1",
|
||||
|
||||
@@ -8,7 +8,6 @@ module.exports = {
|
||||
defaults: {
|
||||
label: '',
|
||||
options: [],
|
||||
description: '',
|
||||
attributes: {}
|
||||
description: ''
|
||||
}
|
||||
};
|
||||
|
||||
@@ -116,12 +116,13 @@ module.exports = {
|
||||
function autoLayout() {
|
||||
if (!clay.meta.activeWatchInfo ||
|
||||
clay.meta.activeWatchInfo.firmware.major === 2 ||
|
||||
clay.meta.activeWatchInfo.platform === 'aplite' &&
|
||||
['aplite', 'diorite'].indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
!self.config.allowGray) {
|
||||
return standardLayouts.BLACK_WHITE;
|
||||
}
|
||||
|
||||
if (clay.meta.activeWatchInfo.platform === 'aplite' && self.config.allowGray) {
|
||||
if (['aplite', 'diorite'].indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
self.config.allowGray) {
|
||||
return standardLayouts.GRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ module.exports = {
|
||||
* @return {void}
|
||||
*/
|
||||
function setValueDisplay() {
|
||||
var value = self.get();
|
||||
var value = self.get().toFixed(self.precision);
|
||||
$value.set('value', value);
|
||||
$valuePad.set('innerHTML', value);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
* @typedef {Object} Clay~ConfigItem
|
||||
* @property {string} type
|
||||
* @property {string|boolean|number} defaultValue
|
||||
* @property {string} [appKey]
|
||||
* @property {string} [messageKey]
|
||||
* @property {string} [id]
|
||||
* @property {string} [label]
|
||||
* @property {Object} [attributes]
|
||||
* @property {Array} [options]
|
||||
* @property {Array} [items]
|
||||
* @property {Array} [capabilities]
|
||||
*/
|
||||
|
||||
var HTML = require('../vendor/minified').HTML;
|
||||
@@ -33,10 +34,22 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
var self = this;
|
||||
|
||||
var _settings = _.copyObj(settings);
|
||||
var _items = [];
|
||||
var _itemsById = {};
|
||||
var _itemsByAppKey = {};
|
||||
var _isBuilt = false;
|
||||
var _items;
|
||||
var _itemsById;
|
||||
var _itemsByMessageKey;
|
||||
var _isBuilt;
|
||||
|
||||
/**
|
||||
* Initialize the item arrays and objects
|
||||
* @private
|
||||
* @return {void}
|
||||
*/
|
||||
function _initializeItems() {
|
||||
_items = [];
|
||||
_itemsById = {};
|
||||
_itemsByMessageKey = {};
|
||||
_isBuilt = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add item(s) to the config
|
||||
@@ -49,34 +62,36 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
item.forEach(function(item) {
|
||||
_addItems(item, $container);
|
||||
});
|
||||
} else if (item.type === 'section') {
|
||||
var $wrapper = HTML('<div class="section">');
|
||||
$container.add($wrapper);
|
||||
_addItems(item.items, $wrapper);
|
||||
} else {
|
||||
var _item = _.copyObj(item);
|
||||
_item.clayId = _items.length;
|
||||
} else if (utils.includesCapability(meta.activeWatchInfo, item.capabilities)) {
|
||||
if (item.type === 'section') {
|
||||
var $wrapper = HTML('<div class="section">');
|
||||
$container.add($wrapper);
|
||||
_addItems(item.items, $wrapper);
|
||||
} else {
|
||||
var _item = _.copyObj(item);
|
||||
_item.clayId = _items.length;
|
||||
|
||||
var clayItem = new ClayItem(_item).initialize(self);
|
||||
var clayItem = new ClayItem(_item).initialize(self);
|
||||
|
||||
if (_item.id) {
|
||||
_itemsById[_item.id] = clayItem;
|
||||
if (_item.id) {
|
||||
_itemsById[_item.id] = clayItem;
|
||||
}
|
||||
|
||||
if (_item.messageKey) {
|
||||
_itemsByMessageKey[_item.messageKey] = clayItem;
|
||||
}
|
||||
|
||||
_items.push(clayItem);
|
||||
|
||||
// set the value of the item via the manipulator to ensure consistency
|
||||
var value = typeof _settings[_item.messageKey] !== 'undefined' ?
|
||||
_settings[_item.messageKey] :
|
||||
(_item.defaultValue || '');
|
||||
|
||||
clayItem.set(value);
|
||||
|
||||
$container.add(clayItem.$element);
|
||||
}
|
||||
|
||||
if (_item.appKey) {
|
||||
_itemsByAppKey[_item.appKey] = clayItem;
|
||||
}
|
||||
|
||||
_items.push(clayItem);
|
||||
|
||||
// set the value of the item via the manipulator to ensure consistency
|
||||
var value = typeof _settings[_item.appKey] !== 'undefined' ?
|
||||
_settings[_item.appKey] :
|
||||
(_item.defaultValue || '');
|
||||
|
||||
clayItem.set(value);
|
||||
|
||||
$container.add(clayItem.$element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +112,7 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
}
|
||||
|
||||
self.meta = meta;
|
||||
self.$rootContainer = $rootContainer;
|
||||
|
||||
self.EVENTS = {
|
||||
/**
|
||||
@@ -111,7 +127,21 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
* value set
|
||||
* @const
|
||||
*/
|
||||
AFTER_BUILD: 'AFTER_BUILD'
|
||||
AFTER_BUILD: 'AFTER_BUILD',
|
||||
|
||||
/**
|
||||
* Called if .build() is executed after the page has already been built and
|
||||
* before the existing content is destroyed
|
||||
* @const
|
||||
*/
|
||||
BEFORE_DESTROY: 'BEFORE_DESTROY',
|
||||
|
||||
/**
|
||||
* Called if .build() is executed after the page has already been built and after
|
||||
* the existing content is destroyed
|
||||
* @const
|
||||
*/
|
||||
AFTER_DESTROY: 'AFTER_DESTROY'
|
||||
};
|
||||
utils.updateProperties(self.EVENTS, {writable: false});
|
||||
|
||||
@@ -124,12 +154,12 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} appKey
|
||||
* @param {string} messageKey
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
self.getItemByAppKey = function(appKey) {
|
||||
_checkBuilt('getItemByAppKey');
|
||||
return _itemsByAppKey[appKey];
|
||||
self.getItemByMessageKey = function(messageKey) {
|
||||
_checkBuilt('getItemByMessageKey');
|
||||
return _itemsByMessageKey[messageKey];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -157,13 +187,16 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
*/
|
||||
self.serialize = function() {
|
||||
_checkBuilt('serialize');
|
||||
_.eachObj(_itemsByAppKey, function(appKey, item) {
|
||||
_settings[appKey] = {
|
||||
|
||||
_settings = {};
|
||||
|
||||
_.eachObj(_itemsByMessageKey, function(messageKey, item) {
|
||||
_settings[messageKey] = {
|
||||
value: item.get()
|
||||
};
|
||||
|
||||
if (item.precision) {
|
||||
_settings[appKey].precision = item.precision;
|
||||
_settings[messageKey].precision = item.precision;
|
||||
}
|
||||
});
|
||||
return _settings;
|
||||
@@ -172,18 +205,40 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
// @todo maybe don't do this and force the static method
|
||||
self.registerComponent = ClayConfig.registerComponent;
|
||||
|
||||
/**
|
||||
* Empties the root container
|
||||
* @returns {ClayConfig}
|
||||
*/
|
||||
self.destroy = function() {
|
||||
var el = $rootContainer[0];
|
||||
self.trigger(self.EVENTS.BEFORE_DESTROY);
|
||||
while (el.firstChild) {
|
||||
el.removeChild(el.firstChild);
|
||||
}
|
||||
_initializeItems();
|
||||
self.trigger(self.EVENTS.AFTER_DESTROY);
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the config page. This must be run before any of the get methods can be run
|
||||
* If you call this method after the page has already been built, teh page will be
|
||||
* destroyed and built again.
|
||||
* @returns {ClayConfig}
|
||||
*/
|
||||
self.build = function() {
|
||||
if (_isBuilt) {
|
||||
self.destroy();
|
||||
}
|
||||
self.trigger(self.EVENTS.BEFORE_BUILD);
|
||||
_addItems(config, $rootContainer);
|
||||
_addItems(self.config, $rootContainer);
|
||||
_isBuilt = true;
|
||||
self.trigger(self.EVENTS.AFTER_BUILD);
|
||||
return self;
|
||||
};
|
||||
|
||||
_initializeItems();
|
||||
|
||||
// attach event methods
|
||||
ClayEvents.call(self, $rootContainer);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ function ClayItem(config) {
|
||||
self.id = config.id || null;
|
||||
|
||||
/** @type {string|null} */
|
||||
self.appKey = config.appKey || null;
|
||||
self.messageKey = config.messageKey || null;
|
||||
|
||||
/** @type {Object} */
|
||||
self.config = config;
|
||||
|
||||
@@ -133,24 +133,27 @@ module.exports = {
|
||||
checkboxgroup: {
|
||||
get: function() {
|
||||
var result = [];
|
||||
this.$element.select('input:checked').each(function(item) {
|
||||
result.push(item.value);
|
||||
this.$element.select('input').each(function(item) {
|
||||
result.push(!!item.checked);
|
||||
});
|
||||
return result;
|
||||
},
|
||||
set: function(values) {
|
||||
var self = this;
|
||||
values = values || [];
|
||||
values = Array.isArray(values) ? values : [];
|
||||
|
||||
while (values.length < this.get().length) {
|
||||
values.push(false);
|
||||
}
|
||||
|
||||
if (_.equals(this.get(), values)) { return this; }
|
||||
|
||||
self.$element.select('input').set('checked', false);
|
||||
self.$element.select('input')
|
||||
.set('checked', false)
|
||||
.each(function(item, index) {
|
||||
item.checked = !!values[index];
|
||||
});
|
||||
|
||||
values.map(function(value) {
|
||||
self.$element
|
||||
.select('input[value="' + value.toString(10).replace('"', '\\"') + '"]')
|
||||
.set('checked', true);
|
||||
});
|
||||
return self.trigger('change');
|
||||
},
|
||||
disable: disable,
|
||||
|
||||
@@ -17,3 +17,119 @@ module.exports.updateProperties = function(obj, descriptor) {
|
||||
Object.defineProperty(obj, prop, descriptor);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.capabilityMap = {
|
||||
PLATFORM_APLITE: {
|
||||
platforms: ['aplite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_BASALT: {
|
||||
platforms: ['basalt'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_CHALK: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_DIORITE: {
|
||||
platforms: ['diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_EMERY: {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
BW: {
|
||||
platforms: ['aplite', 'diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
COLOR: {
|
||||
platforms: ['basalt', 'chalk', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
MICROPHONE: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
SMARTSTRAP: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 4
|
||||
},
|
||||
SMARTSTRAP_POWER: {
|
||||
platforms: ['basalt', 'chalk', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 4
|
||||
},
|
||||
HEALTH: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 10
|
||||
},
|
||||
RECT: {
|
||||
platforms: ['aplite', 'basalt', 'diorite', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
ROUND: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_144x168: {
|
||||
platforms: ['aplite', 'basalt', 'diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_180x180_ROUND: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_200x228: {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if all of the provided capabilities are compatible with the watch
|
||||
* @param {Object} activeWatchInfo
|
||||
* @param {Array<string>} [capabilities]
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports.includesCapability = function(activeWatchInfo, capabilities) {
|
||||
var notRegex = /^NOT_/;
|
||||
var result = [];
|
||||
|
||||
if (!capabilities || !capabilities.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = capabilities.length - 1; i >= 0; i--) {
|
||||
var capability = capabilities[i];
|
||||
var mapping = module.exports.capabilityMap[capability.replace(notRegex, '')];
|
||||
|
||||
if (!mapping ||
|
||||
mapping.platforms.indexOf(activeWatchInfo.platform) === -1 ||
|
||||
mapping.minFwMajor > activeWatchInfo.firmware.major ||
|
||||
mapping.minFwMajor === activeWatchInfo.firmware.major &&
|
||||
mapping.minFwMinor > activeWatchInfo.firmware.minor
|
||||
) {
|
||||
result.push(!!capability.match(notRegex));
|
||||
} else {
|
||||
result.push(!capability.match(notRegex));
|
||||
}
|
||||
}
|
||||
|
||||
return result.indexOf(false) === -1;
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
border-radius: $base-height / 2;
|
||||
box-shadow: $box-shadow-small-components;
|
||||
display: block;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.picker-wrap {
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
vertical-align: baseline;
|
||||
color: $color-white;
|
||||
font-size: inherit;
|
||||
appearance: none;
|
||||
min-height: $item-spacing-v + ($base-height + 0rem) ;
|
||||
|
||||
@include placeholder {
|
||||
color: $color-gray-8;
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: #000;
|
||||
width: 100%;
|
||||
border: none;
|
||||
margin:0;
|
||||
|
||||
@@ -3,13 +3,8 @@
|
||||
<div class="checkbox-group">
|
||||
{{each options}}
|
||||
<label class="tap-highlight">
|
||||
<span class="label">{{{this.label}}}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
value="{{this.value}}"
|
||||
name="clay-{{clayId}}"
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
<span class="label">{{{this}}}</span>
|
||||
<input type="checkbox" value="1" name="clay-{{clayId}}" />
|
||||
<i></i>
|
||||
</label>
|
||||
{{/each}}
|
||||
|
||||
@@ -4,7 +4,15 @@
|
||||
<span class="value"></span>
|
||||
<select data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}}>
|
||||
{{each options}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{if Array.isArray(this.value)}}
|
||||
<optgroup label="{{this.label}}">
|
||||
{{each this.value}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{/each}}
|
||||
</optgroup>
|
||||
{{else}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
+55
-1
@@ -53,7 +53,7 @@ module.exports.configItem = function(config, autoRegister) {
|
||||
|
||||
var result = _.extend({}, {
|
||||
label: config.type + '-label',
|
||||
appKey: 'appKey-' + idCounter,
|
||||
messageKey: 'messageKey-' + idCounter,
|
||||
id: 'id-' + idCounter
|
||||
}, config);
|
||||
|
||||
@@ -126,3 +126,57 @@ module.exports.clay = function(config, customFn, options, destroyLocalStorage) {
|
||||
}
|
||||
return new Clay(config, customFn, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} keys
|
||||
* @return {Object}
|
||||
*/
|
||||
module.exports.messageKeys = function(keys) {
|
||||
var counter = 10000;
|
||||
var result = {};
|
||||
|
||||
keys.forEach(function(key) {
|
||||
var matches = key.match(/(.+?)(?:\[(\d*)\])?$/);
|
||||
var parsedKey = matches[1];
|
||||
var length = parseInt(matches[2] || 1, 10);
|
||||
|
||||
result[parsedKey] = counter;
|
||||
|
||||
counter += length;
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} obj
|
||||
* @returns {Array}
|
||||
*/
|
||||
module.exports.messageKeysObjToArray = function(obj) {
|
||||
return Object.keys(obj).map(function(key) {
|
||||
return Array.isArray(obj[key]) ?
|
||||
key + '[' + obj[key].length + ']' :
|
||||
key;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} expected
|
||||
* @return {Object}
|
||||
*/
|
||||
module.exports.messageKeysExpected = function(expected) {
|
||||
var result = {};
|
||||
var messageKeys = module.exports.messageKeysObjToArray(expected);
|
||||
messageKeys = module.exports.messageKeys(messageKeys);
|
||||
|
||||
Object.keys(expected).forEach(function(key) {
|
||||
var expectedVal = Array.isArray(expected[key]) ? expected[key] : [expected[key]];
|
||||
expectedVal.forEach(function(val, index) {
|
||||
if (typeof val !== 'undefined') {
|
||||
result[messageKeys[key] + index] = val;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
+6
-1
@@ -53,7 +53,12 @@ module.exports = function(config) {
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
],
|
||||
configure: function(bundle) {
|
||||
bundle.on('prebundle', function() {
|
||||
bundle.ignore('message_keys');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"max-params": [0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,6 +434,28 @@ describe('component - color', function() {
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.BLACK_WHITE, false, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.GRAY, true, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
|
||||
testCustomLayout();
|
||||
testCustomLayout('COLOR');
|
||||
|
||||
@@ -21,4 +21,26 @@ describe('component - select', function() {
|
||||
selectItem.set('value-2');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 2');
|
||||
});
|
||||
|
||||
it('sets the value display to the correct value on change when using optgroups',
|
||||
function() {
|
||||
var clayConfig = fixture.clayConfig([
|
||||
{
|
||||
type: 'select',
|
||||
defaultValue: 'value-1',
|
||||
options: [
|
||||
{ label: 'label 1', value: 'value-1' },
|
||||
{ label: 'group', value: [
|
||||
{ label: 'label 2', value: 'value-2' },
|
||||
{ label: 'label 3', value: 'value-3' }
|
||||
]}
|
||||
]
|
||||
}
|
||||
]);
|
||||
var selectItem = clayConfig.getItemsByType('select')[0];
|
||||
var $valueDisplay = selectItem.$element.select('.value');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 1');
|
||||
selectItem.set('value-2');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,4 +65,31 @@ describe('component - slider', function() {
|
||||
|
||||
assert.strictEqual(sliderItem.precision, 2);
|
||||
});
|
||||
|
||||
it('always displays decimal when precision is less than 1', function() {
|
||||
var clayConfig = fixture.clayConfig([{
|
||||
type: 'slider',
|
||||
step: 0.05
|
||||
}]);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $valueDisplayPad = sliderItem.$element.select('.value-pad');
|
||||
var $slider = sliderItem.$element.select('.slider');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50.00');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '50.00');
|
||||
assert.strictEqual($slider.get('value'), '50');
|
||||
sliderItem.set(75);
|
||||
assert.strictEqual($valueDisplay.get('value'), '75.00');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '75.00');
|
||||
assert.strictEqual($slider.get('value'), '75');
|
||||
sliderItem.set(33.25);
|
||||
assert.strictEqual($valueDisplay.get('value'), '33.25');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '33.25');
|
||||
assert.strictEqual($slider.get('value'), '33.25');
|
||||
sliderItem.set(17.1);
|
||||
assert.strictEqual($valueDisplay.get('value'), '17.10');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '17.10');
|
||||
assert.strictEqual($slider.get('value'), '17.1');
|
||||
});
|
||||
});
|
||||
|
||||
+125
-16
@@ -23,6 +23,24 @@ function stubPebble() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array} keys
|
||||
* @return {Object}
|
||||
*/
|
||||
function stubMessageKeys(keys) {
|
||||
var messageKeys = require('message_keys');
|
||||
Object.keys(messageKeys).forEach(function(key) {
|
||||
delete messageKeys[key];
|
||||
});
|
||||
|
||||
var newKeys = fixture.messageKeys(keys);
|
||||
Object.keys(newKeys).forEach(function(key) {
|
||||
messageKeys[key] = newKeys[key];
|
||||
});
|
||||
|
||||
return messageKeys;
|
||||
}
|
||||
|
||||
describe('Clay', function() {
|
||||
describe('Clay constructor', function() {
|
||||
it('throws if the config is not an array', function() {
|
||||
@@ -31,6 +49,15 @@ describe('Clay', function() {
|
||||
}, /must be an Array/i);
|
||||
});
|
||||
|
||||
it('throws if the config contains appKeys', function() {
|
||||
assert.throws(function() {
|
||||
fixture.clay([
|
||||
{type: 'input', appKey: 'foo'},
|
||||
{type: 'someCustomComponent', appKey: 'bar'}
|
||||
]);
|
||||
}, /appKeys are no longer supported/i);
|
||||
});
|
||||
|
||||
it('throws if customFn is not a function', function() {
|
||||
assert.throws(function() {
|
||||
fixture.clay([], {});
|
||||
@@ -80,12 +107,16 @@ describe('Clay', function() {
|
||||
stubPebble();
|
||||
fixture.clay([]);
|
||||
var logStub = sinon.stub(console, 'log');
|
||||
var expected = {someSetting: 'value'};
|
||||
|
||||
stubMessageKeys(fixture.messageKeysObjToArray(expected));
|
||||
Pebble.addEventListener
|
||||
.withArgs('webviewclosed')
|
||||
.callArgWith(1, { response: '%7B%22appKey%22%3A%22value%22%7D' });
|
||||
.callArgWith(1, {response: encodeURIComponent(JSON.stringify(expected))});
|
||||
|
||||
var expectedAppMessage = fixture.messageKeysExpected(expected);
|
||||
assert(Pebble.addEventListener.calledWith('webviewclosed'));
|
||||
assert(Pebble.sendAppMessage.calledWith({ appKey: 'value' }));
|
||||
assert(Pebble.sendAppMessage.calledWith(expectedAppMessage));
|
||||
|
||||
Pebble.sendAppMessage.callArg(1);
|
||||
assert(logStub.calledWith('Sent config data to Pebble'));
|
||||
@@ -121,6 +152,14 @@ describe('Clay', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.version', function() {
|
||||
it('has the correct version', function() {
|
||||
var config = fixture.config(['input', 'text', 'color']);
|
||||
var clay = fixture.clay(config);
|
||||
assert.strictEqual(clay.version, require('../../package.json').version);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.config', function() {
|
||||
it('is a copy not a reference', function() {
|
||||
var config = fixture.config(['input', 'text', 'color']);
|
||||
@@ -157,7 +196,7 @@ describe('Clay', function() {
|
||||
describe('string substitutions', function() {
|
||||
var customFn = function() { this.getAllItems(); };
|
||||
var config = fixture.config(['input', 'color']);
|
||||
var settings = { appKey: 'value' };
|
||||
var settings = { messageKey: 'value' };
|
||||
var clay;
|
||||
var html;
|
||||
|
||||
@@ -231,7 +270,7 @@ describe('Clay', function() {
|
||||
});
|
||||
|
||||
describe('.getSettings', function() {
|
||||
it('stores the response to localStorage and returns the decoded data',
|
||||
it('it writes to localStorage and returns the data when input is encoded',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = encodeURIComponent(JSON.stringify({
|
||||
@@ -242,20 +281,48 @@ describe('Clay', function() {
|
||||
key1: 'value1',
|
||||
key2: 'value2'
|
||||
};
|
||||
|
||||
stubMessageKeys(fixture.messageKeysObjToArray(expected));
|
||||
|
||||
var result = clay.getSettings(settings);
|
||||
assert.equal(localStorage.getItem('clay-settings'), JSON.stringify(expected));
|
||||
assert.deepEqual(result, expected);
|
||||
assert.equal(
|
||||
localStorage.getItem('clay-settings'),
|
||||
JSON.stringify(expected)
|
||||
);
|
||||
assert.deepEqual(result, fixture.messageKeysExpected(expected));
|
||||
});
|
||||
|
||||
it('it writes to localStorage and returns the data when input is not encoded',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = JSON.stringify({
|
||||
key1: 'value1',
|
||||
key2: {value: 'value2%7Dbreaks'}
|
||||
});
|
||||
var expected = {
|
||||
key1: 'value1',
|
||||
key2: 'value2%7Dbreaks'
|
||||
};
|
||||
|
||||
stubMessageKeys(fixture.messageKeysObjToArray(expected));
|
||||
|
||||
var result = clay.getSettings(settings);
|
||||
assert.equal(
|
||||
localStorage.getItem('clay-settings'),
|
||||
JSON.stringify(expected)
|
||||
);
|
||||
assert.deepEqual(result, fixture.messageKeysExpected(expected));
|
||||
});
|
||||
|
||||
it('does not store the response if it is invalid JSON and logs an error',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
localStorage.setItem('clay-settings', '{"appKey":"value"}');
|
||||
localStorage.setItem('clay-settings', '{"messageKey":"value"}');
|
||||
|
||||
assert.throws(function() {
|
||||
clay.getSettings('not valid JSON');
|
||||
}, /Not Valid JSON/i);
|
||||
assert.equal(localStorage.getItem('clay-settings'), '{"appKey":"value"}');
|
||||
assert.equal(localStorage.getItem('clay-settings'), '{"messageKey":"value"}');
|
||||
});
|
||||
|
||||
it('Prepares the settings for sendAppMessage', function() {
|
||||
@@ -281,7 +348,7 @@ describe('Clay', function() {
|
||||
test1: 0,
|
||||
test2: 'val-2',
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0],
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [1, 0, 1],
|
||||
@@ -289,7 +356,12 @@ describe('Clay', function() {
|
||||
test9: [10, 20, 30, 40]
|
||||
};
|
||||
|
||||
assert.deepEqual(clay.getSettings(response), expected);
|
||||
stubMessageKeys(fixture.messageKeysObjToArray(expected));
|
||||
|
||||
assert.deepEqual(
|
||||
clay.getSettings(response),
|
||||
fixture.messageKeysExpected(expected)
|
||||
);
|
||||
});
|
||||
|
||||
it('does not prepare the settings for sendAppMessage if convert is false',
|
||||
@@ -380,6 +452,16 @@ describe('Clay', function() {
|
||||
});
|
||||
|
||||
describe('.prepareForAppMessage', function() {
|
||||
it('converts an array correctly when array contains strings', function() {
|
||||
assert.deepEqual(
|
||||
Clay.prepareForAppMessage(['one', 'two', 'three']),
|
||||
['one', 'two', 'three']
|
||||
);
|
||||
assert.deepEqual(
|
||||
Clay.prepareForAppMessage([{value: 'one'}, 'two', 'three']),
|
||||
['one', 'two', 'three']);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains numbers', function() {
|
||||
assert.deepEqual(Clay.prepareForAppMessage([1, 2, 3]), [1, 2, 3]);
|
||||
assert.deepEqual(Clay.prepareForAppMessage(
|
||||
@@ -441,13 +523,21 @@ describe('Clay', function() {
|
||||
precision: undefined
|
||||
}), 12);
|
||||
});
|
||||
|
||||
it('Handles sparse arrays', function() {
|
||||
var sparseArr = [];
|
||||
sparseArr[1] = 'two';
|
||||
sparseArr[2] = 'three';
|
||||
assert.deepEqual(Clay.prepareForAppMessage(sparseArr), sparseArr);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareSettingsForAppMessage', function() {
|
||||
it('converts the settings correctly', function() {
|
||||
var settings = {
|
||||
test1: false,
|
||||
test2: 'val-2',
|
||||
'test2[0]': 'val-1',
|
||||
'test2[1]': 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
@@ -456,20 +546,39 @@ describe('Clay', function() {
|
||||
test8: {
|
||||
precision: 2,
|
||||
value: 12.34
|
||||
}
|
||||
},
|
||||
'test9[1]': 'foo'
|
||||
};
|
||||
|
||||
var expected = {
|
||||
test1: 0,
|
||||
test2: 'val-2',
|
||||
test2: ['val-1', 'val-2'],
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0],
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [1, 0, 1],
|
||||
test8: 1234
|
||||
test8: 1234,
|
||||
test9: [undefined, 'foo']
|
||||
};
|
||||
|
||||
assert.deepEqual(Clay.prepareSettingsForAppMessage(settings), expected);
|
||||
stubMessageKeys(fixture.messageKeysObjToArray(expected));
|
||||
|
||||
var result = Clay.prepareSettingsForAppMessage(settings);
|
||||
|
||||
assert.deepEqual(result, fixture.messageKeysExpected(expected));
|
||||
});
|
||||
|
||||
it('throws if a 2 dimension array is present', function() {
|
||||
var settings = {
|
||||
'test1[1]': ['bad', 'developer!']
|
||||
};
|
||||
|
||||
stubMessageKeys(['test1[2]']);
|
||||
|
||||
assert.throws(function() {
|
||||
Clay.prepareSettingsForAppMessage(settings);
|
||||
}, /2 dimensional array/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+290
-20
@@ -12,7 +12,7 @@ describe('ClayConfig', function() {
|
||||
it('defines read-only properties', function() {
|
||||
var properties = [
|
||||
'EVENTS',
|
||||
'getItemByAppKey',
|
||||
'getItemByMessageKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'serialize',
|
||||
@@ -27,6 +27,191 @@ describe('ClayConfig', function() {
|
||||
checkReadOnly(clayConfig, properties);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests if the provided capabilities of the platform match
|
||||
* @param {string} platform
|
||||
* @param {number} fwMajor
|
||||
* @param {number} fwMinor
|
||||
* @param {Array} capabilities
|
||||
* @param {number} expected
|
||||
* @param {number} [notExpected] - defaults to the inverse of `expected`
|
||||
* @return {void}
|
||||
*/
|
||||
function testCapabilities(platform, fwMajor, fwMinor, capabilities, expected,
|
||||
notExpected) {
|
||||
it(platform + ' is' + (expected ? '' : ' not') + ' included on firmware ' +
|
||||
fwMajor + '.' + fwMinor + ' for capabilities ' + JSON.stringify(capabilities),
|
||||
function() {
|
||||
var item = {
|
||||
type: 'input',
|
||||
capabilities: capabilities
|
||||
};
|
||||
var meta = {
|
||||
activeWatchInfo: {
|
||||
platform: platform,
|
||||
model: 'qemu_platform_' + platform,
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: fwMajor,
|
||||
minor: fwMinor,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
var clayConfig = fixtures.clayConfig([item], true, true, null, meta);
|
||||
|
||||
assert.strictEqual(clayConfig.getAllItems().length, expected);
|
||||
|
||||
// now we test the NOT_ prefix
|
||||
item.capabilities = item.capabilities.map(function(capability) {
|
||||
return 'NOT_' + capability.replace(/^NOT_/, '');
|
||||
});
|
||||
|
||||
notExpected = typeof notExpected !== 'undefined' ? notExpected : ~expected + 2;
|
||||
clayConfig = fixtures.clayConfig([item], true, true, null, meta);
|
||||
assert.strictEqual(clayConfig.getAllItems().length, notExpected);
|
||||
});
|
||||
}
|
||||
|
||||
describe('capability filtering', function() {
|
||||
testCapabilities('aplite', 2, 9, ['BW'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['RECT'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 4, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('basalt', 3, 10, ['BW'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('basalt', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_BASALT'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('chalk', 3, 10, ['BW'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('chalk', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['RECT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['ROUND'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_180x180_ROUND'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_CHALK'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('diorite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('diorite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_DIORITE'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('emery', 3, 10, ['BW'], 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('emery', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('emery', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('emery', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('emery', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('emery', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_200x228'], 1);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_EMERY'], 1);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW', 'HEALTH'], 0, 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR', 'HEALTH'], 1);
|
||||
testCapabilities('emery', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_APLITE', 'PLATFORM_BASALT'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP', 'SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['COLOR', 'PLATFORM_APLITE'], 0, 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_APLITE', 'COLOR'], 0, 0);
|
||||
testCapabilities('aplite', 3, 10, ['BW', 'NOT_COLOR'], 1, 0);
|
||||
testCapabilities('aplite', 3, 10, ['NOT_BASALT', 'RECT'], 1, 0);
|
||||
testCapabilities('aplite', 3, 10, ['NOT_CHALK', 'BW', 'PLATFORM_APLITE'], 1, 0);
|
||||
});
|
||||
|
||||
describe('.meta', function() {
|
||||
it('populates meta', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input']);
|
||||
@@ -36,7 +221,7 @@ describe('ClayConfig', function() {
|
||||
|
||||
describe('throws when trying to run methods before being built', function() {
|
||||
[
|
||||
'getItemByAppKey',
|
||||
'getItemByMessageKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'serialize'
|
||||
@@ -64,14 +249,17 @@ describe('ClayConfig', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getItemByAppKey()', function() {
|
||||
describe('.getItemByMessageKey()', function() {
|
||||
it('it returns the correct item', function() {
|
||||
var config = fixtures.config([
|
||||
{type: 'input', appKey: 'test-app-key', clayId: 0},
|
||||
{type: 'input', appKey: undefined, clayId: 1}
|
||||
{type: 'input', messageKey: 'test-app-key', clayId: 0},
|
||||
{type: 'input', messageKey: undefined, clayId: 1}
|
||||
]);
|
||||
var clayConfig = fixtures.clayConfig(config);
|
||||
assert.deepEqual(clayConfig.getItemByAppKey('test-app-key').config, config[0]);
|
||||
assert.deepEqual(
|
||||
clayConfig.getItemByMessageKey('test-app-key').config,
|
||||
config[0]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,18 +290,18 @@ describe('ClayConfig', function() {
|
||||
describe('.serialize()', function() {
|
||||
it('returns the correct settings', function() {
|
||||
var config = [
|
||||
{type: 'input', appKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', appKey: 'test2', options: [
|
||||
{type: 'input', messageKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', messageKey: 'test2', options: [
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]},
|
||||
{type: 'toggle', appKey: 'test3'},
|
||||
{type: 'checkboxgroup', appKey: 'test4', options: [
|
||||
{label: 'label-1', value: 'cb-1'},
|
||||
{label: 'label-2', value: 'cb-2'},
|
||||
{label: 'label-2', value: 'cb-3'}
|
||||
{type: 'toggle', messageKey: 'test3'},
|
||||
{type: 'checkboxgroup', messageKey: 'test4', options: [
|
||||
'label-1',
|
||||
'label-2',
|
||||
'label-3'
|
||||
]},
|
||||
{type: 'slider', appKey: 'test5', step: 0.05, defaultValue: 12.5}
|
||||
{type: 'slider', messageKey: 'test5', step: 0.05, defaultValue: 12.5}
|
||||
];
|
||||
var settings = {
|
||||
test2: 'val-2'
|
||||
@@ -125,19 +313,19 @@ describe('ClayConfig', function() {
|
||||
test1: {value: 'default val'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: false},
|
||||
test4: {value: []},
|
||||
test4: {value: [false, false, false]},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
clayConfig.getItemByAppKey('test1').set('val-1');
|
||||
clayConfig.getItemByAppKey('test3').set(true);
|
||||
clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']);
|
||||
clayConfig.getItemByMessageKey('test1').set('val-1');
|
||||
clayConfig.getItemByMessageKey('test3').set(true);
|
||||
clayConfig.getItemByMessageKey('test4').set([true, false, true]);
|
||||
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: {value: 'val-1'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: true},
|
||||
test4: {value: ['cb-1', 'cb-3']},
|
||||
test4: {value: [true, false, true]},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
@@ -152,13 +340,33 @@ describe('ClayConfig', function() {
|
||||
test1: 'val-1',
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test4: [true, false, true],
|
||||
test5: 12.5
|
||||
});
|
||||
assert.doesNotThrow(function() {
|
||||
fixtures.clayConfig(config, true, true, loadedSettings);
|
||||
});
|
||||
});
|
||||
|
||||
it('only returns the settings present in the config', function() {
|
||||
var config = [
|
||||
{type: 'input', messageKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', messageKey: 'test2', options: [
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]}
|
||||
];
|
||||
var settings = {
|
||||
test2: 'val-2',
|
||||
notInTheConfig: 'Should not exist'
|
||||
};
|
||||
|
||||
var clayConfig = fixtures.clayConfig(config, true, true, settings);
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: {value: 'default val'},
|
||||
test2: {value: 'val-2'}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.registerComponent()', function() {
|
||||
@@ -254,7 +462,69 @@ describe('ClayConfig', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.destroy().', function() {
|
||||
it('Destroys all the items on the page and in the items array', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.build();
|
||||
clayConfig.destroy();
|
||||
|
||||
// this should throw because the config has not been built yet
|
||||
assert.throws(clayConfig.getAllItems);
|
||||
|
||||
// there should be no DOM inside the container
|
||||
assert.strictEqual(clayConfig.$rootContainer[0].children.length, 0);
|
||||
});
|
||||
|
||||
it('dispatches the BEFORE_DESTROY event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.BEFORE_DESTROY, function() {
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
done();
|
||||
});
|
||||
|
||||
clayConfig.build();
|
||||
clayConfig.destroy();
|
||||
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 0);
|
||||
});
|
||||
|
||||
it('dispatches the AFTER_DESTROY event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_DESTROY, function() {
|
||||
|
||||
// this should throw because the config has not been built yet
|
||||
assert.throws(clayConfig.getAllItems);
|
||||
done();
|
||||
});
|
||||
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
clayConfig.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.build()', function() {
|
||||
it('Destroys the config if called a consecutive time', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
var destroyHandlerSpy = sinon.spy();
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_DESTROY, destroyHandlerSpy);
|
||||
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
|
||||
clayConfig.config = fixtures.config(['select']);
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 1);
|
||||
assert(destroyHandlerSpy.calledOnce);
|
||||
|
||||
clayConfig.build();
|
||||
assert(destroyHandlerSpy.calledTwice);
|
||||
});
|
||||
|
||||
it('dispatches the BEFORE_BUILD event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
clayConfig.on(clayConfig.EVENTS.BEFORE_BUILD, function() {
|
||||
|
||||
+12
-10
@@ -12,7 +12,7 @@ describe('ClayItem', function() {
|
||||
it('defines read-only properties', function() {
|
||||
var properties = [
|
||||
'id',
|
||||
'appKey',
|
||||
'messageKey',
|
||||
'config',
|
||||
'$element',
|
||||
'$manipulatorTarget',
|
||||
@@ -53,24 +53,25 @@ describe('ClayItem', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.appKey', function() {
|
||||
it('sets appKey correctly', function() {
|
||||
describe('.messageKey', function() {
|
||||
it('sets messageKey correctly', function() {
|
||||
var config = fixture.configItem('input');
|
||||
var clayItem = new ClayItem(config);
|
||||
assert.strictEqual(clayItem.appKey, config.appKey);
|
||||
assert.strictEqual(clayItem.messageKey, config.messageKey);
|
||||
});
|
||||
|
||||
it('sets appKey to null if there is no appKey in the config', function() {
|
||||
var clayItem = fixture.clayItem({type: 'input', appKey: undefined});
|
||||
assert.strictEqual(clayItem.appKey, null);
|
||||
it('sets messageKey to null if there is no messageKey in the config',
|
||||
function() {
|
||||
var clayItem = fixture.clayItem({type: 'input', messageKey: undefined});
|
||||
assert.strictEqual(clayItem.messageKey, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.config', function() {
|
||||
it('sets appKey correctly', function() {
|
||||
it('sets messageKey correctly', function() {
|
||||
var config = fixture.configItem('input');
|
||||
var clayItem = new ClayItem(config);
|
||||
assert.strictEqual(clayItem.appKey, config.appKey);
|
||||
assert.strictEqual(clayItem.messageKey, config.messageKey);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,7 +105,8 @@ describe('ClayItem', function() {
|
||||
|
||||
it('returns itself for chaining', function() {
|
||||
var clayItem = fixture.clayItem('select');
|
||||
assert.strictEqual(clayItem.initialize(), clayItem);
|
||||
var clayConfig = fixture.clayConfig([]);
|
||||
assert.strictEqual(clayItem.initialize(clayConfig), clayItem);
|
||||
});
|
||||
|
||||
it('does nothing if there is no initialize function', function() {
|
||||
|
||||
@@ -225,17 +225,20 @@ describe('manipulators', function() {
|
||||
var type = {
|
||||
type: 'checkboxgroup',
|
||||
clayId: 1,
|
||||
defaultValue: ['two'],
|
||||
options: [
|
||||
{ label: '1', value: 'one' },
|
||||
{ label: '2', value: 'two' },
|
||||
{ label: '3', value: 'three "quote' }
|
||||
]
|
||||
defaultValue: [true, true, true],
|
||||
options: ['First', 'Second', 'Third']
|
||||
};
|
||||
testSetGet(type, ['one', 'two']);
|
||||
testSetGet(type, ['three "quote']);
|
||||
testSetGet(type, []);
|
||||
testSetGet(type, false, []);
|
||||
testSetGet(type, [false, false, true]);
|
||||
testSetGet(type, [true, false], [true, false, false]);
|
||||
testSetGet(type, [1, 0], [true, false, false]);
|
||||
testSetGet(type, [true], [true, false, false]);
|
||||
testSetGet(type, [1], [true, false, false]);
|
||||
testSetGet(type, [], [false, false, false]);
|
||||
|
||||
// any non-array values should result in all false
|
||||
testSetGet(type, false, [false, false, false]);
|
||||
testSetGet(type, true, [false, false, false]);
|
||||
testSetGet(type, null, [false, false, false]);
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# This file is the default set of rules to compile a Pebble project.
|
||||
#
|
||||
# Feel free to customize this to your needs.
|
||||
#
|
||||
import os
|
||||
import shutil
|
||||
import waflib
|
||||
|
||||
top = '.'
|
||||
out = 'build'
|
||||
|
||||
|
||||
def distclean(ctx):
|
||||
if os.path.exists('dist.zip'):
|
||||
os.remove('dist.zip')
|
||||
if os.path.exists('dist'):
|
||||
shutil.rmtree('dist')
|
||||
waflib.Scripting.distclean(ctx)
|
||||
|
||||
|
||||
def options(ctx):
|
||||
ctx.load('pebble_sdk_lib')
|
||||
|
||||
|
||||
def configure(ctx):
|
||||
ctx.load('pebble_sdk_lib')
|
||||
|
||||
|
||||
def build(ctx):
|
||||
ctx.load('pebble_sdk_lib')
|
||||
|
||||
cached_env = ctx.env
|
||||
for platform in ctx.env.TARGET_PLATFORMS:
|
||||
ctx.env = ctx.all_envs[platform]
|
||||
ctx.set_group(ctx.env.PLATFORM_NAME)
|
||||
lib_name = '{}/{}'.format(ctx.env.BUILD_DIR, ctx.env.PROJECT_INFO['name'])
|
||||
ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=lib_name, bin_type='lib')
|
||||
ctx.env = cached_env
|
||||
|
||||
ctx.set_group('bundle')
|
||||
ctx.pbl_bundle(includes=ctx.path.ant_glob('include/**/*.h'),
|
||||
js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']),
|
||||
bin_type='lib')
|
||||
|
||||
if ctx.cmd == 'clean':
|
||||
for n in ctx.path.ant_glob(['dist/**/*', 'dist.zip'], quiet=True):
|
||||
n.delete()
|
||||
Reference in New Issue
Block a user