diff --git a/README.md b/README.md index c78e01b..347e009 100755 --- a/README.md +++ b/README.md @@ -899,7 +899,39 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000); | `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})`
`config` - an Array representing your config
`customFn` - function to be run in the context of the generated page
`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 )`
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)`
`response` - the response object provided to the "webviewclosed" event
`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. 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)`
`response` - the response object provided to the "webviewclosed" event
`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.

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; + + +``` --- diff --git a/index.js b/index.js index d223733..9b437f9 100755 --- a/index.js +++ b/index.js @@ -230,8 +230,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 @@ -239,7 +239,7 @@ 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