mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-27 20:36:33 -04:00
Documentation! + some little fixes to add consistency between components
This commit is contained in:
@@ -1,340 +1,21 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
Copyright (c) 2016 Pebble Technology
|
||||
|
||||
Preamble
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@@ -1,3 +1,658 @@
|
||||
# Clay
|
||||
Clay is a JavaScript library that makes it super 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 is still in early development and missing some features. We would love your feedback so please submit any ideas or features you would like via GitHub issues.**
|
||||
|
||||
# Getting Started
|
||||
|
||||
Clay will eventually be built into the Pebble SDK. However while it is still in beta, you will need to follow some steps
|
||||
|
||||
1. Download the Clay distribution file from: [dist/clay.js](dist/clay.js)
|
||||
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 the 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*'))`
|
||||
5. Your `app.js` needs to `require` clay and your config file, then be initialized:
|
||||
```javascript
|
||||
var Clay = require('clay');
|
||||
var clayConfig = require('config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
6. Now in your `showConfiguration` handler you let clay generate the URL for you. It should look something like:
|
||||
```javascript
|
||||
Pebble.addEventListener('showConfiguration', function(e) {
|
||||
Pebble.openURL(clay.generateUrl());
|
||||
});
|
||||
```
|
||||
7. In order for your Pebble app to receive the configuration, you need to get the settings from Clay. Your `webviewclosed` handler should now look something like:
|
||||
```javascript
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
// Send settings to Pebble watchapp
|
||||
Pebble.sendAppMessage(clay.getSettings(e.response), function(e) {
|
||||
console.log('Sent config data to Pebble');
|
||||
}, function() {
|
||||
console.log('Failed to send config data!');
|
||||
console.log(JSON.stringify(e));
|
||||
});
|
||||
});
|
||||
```
|
||||
8. Next is the fun part. Creating your config page. Edit your `config.json` file using the instructions below
|
||||
|
||||
# Creating Your Config File
|
||||
|
||||
Clay uses javascript objects (or JSON) to generate the config page for you. The structure of the page is totally up to you, but you do need to follow some basic rules.
|
||||
|
||||
## Basic JSON structure
|
||||
|
||||
Your root element should be an array. This represents the entire page. Inside this array you place your config items. Each config item is an object with some properties that configure how each item should be displayed.
|
||||
|
||||
#### Example:
|
||||
```javascript
|
||||
[
|
||||
{ type: 'heading', defaultValue: 'Example Config Page' },
|
||||
{ type: 'text', defaultValue: 'Clay makes things easy.' }
|
||||
//... etc etc
|
||||
]
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
### Section
|
||||
|
||||
Sections help divide up the page into logical separations. It is recommended that you place all your input based items in a section for maximum prettiness.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | set to "section"
|
||||
| items | array | array of items to include in the section
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
{
|
||||
"type": "heading",
|
||||
"defaultValue": "This is a section"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"label": "Email"
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "enableThings",
|
||||
"label": "Enable things"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Heading
|
||||
|
||||
**Manipulator:** `html`
|
||||
|
||||
Headings can be used in anywhere and can have their size adjusted to suit the context. If you place a heading item at the first position of a **section's** `items` array then it will automatically be styled as a header for that section.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| defaultValue | string/HTML | The heading 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)
|
||||
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "heading",
|
||||
"id": "main-heading",
|
||||
"defaultValue": "My Cool Watchface",
|
||||
"size": 1,
|
||||
"attributes": {
|
||||
""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Text
|
||||
|
||||
**Manipulator:** `html`
|
||||
|
||||
Text is used to provide descriptions of sections or to explain complex parts of your page. Feel free to add any extra HTML you require to the `defaultValue`
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| defaultValue | string/HTML | The content of the text.
|
||||
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "An explanation of how things work",
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Input
|
||||
|
||||
**Manipulator:** `val`
|
||||
|
||||
Standard text input field.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | string | The default value of the text field
|
||||
| attributes | object | A hash of HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attributes such as `required` or `type` .
|
||||
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Email",
|
||||
"attributes": {
|
||||
"placeholder": "eg: name@domain.com",
|
||||
"limit": 10,
|
||||
"required": "required",
|
||||
"type": "email"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### Toggle
|
||||
|
||||
**Manipulator:** `checked`
|
||||
|
||||
Switch for a single item.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | boolean | The default value of the toggle. Defaults to `false`
|
||||
| attributes | object | A hash of HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`.
|
||||
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "invert",
|
||||
"label": "Invert Colors",
|
||||
"defaultValue": true,
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### Select
|
||||
|
||||
**Manipulator:** `val`
|
||||
|
||||
A dropdown menu
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | string | The default value of dropdown. Must match a value in the `options` array
|
||||
| attributes | object | A hash of 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. Each option is an object with a `label` and `value` property.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "select",
|
||||
"appKey": "flavor",
|
||||
"defaultValue": "grape",
|
||||
"label": "Favorite Flavor",
|
||||
"options": [
|
||||
{ "label": "", "value": "" },
|
||||
{ "label": "Berry", "value": "berry" },
|
||||
{ "label": "Grape", "value": "grape" },
|
||||
{ "label": "Banana", "value": "banana" }
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### Color
|
||||
|
||||
**Manipulator:** `color`
|
||||
|
||||
A color picker.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | string OR int | The default color. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally.
|
||||
| sunlight | boolean | Switch between uncorrected and sunlight color palette. Defaults to `true`
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"defaultValue": "FF0000",
|
||||
"label": "Background Color",
|
||||
"sunlight": true
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### RadioGroup
|
||||
|
||||
**Manipulator:** `radiogroup`
|
||||
|
||||
A list of options where a user can only choose one
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | string | The default selected item. Must match a value in the `options` array
|
||||
| attributes | object | A hash of 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. Each option is an object with a `label` and `value` property.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "radiogroup",
|
||||
"appKey": "favorite_food",
|
||||
"label": "Favorite Food",
|
||||
"options": [
|
||||
{ "label": "Sushi", "value": "sushi" },
|
||||
{ "label": "Pizza", "value": "pizza" },
|
||||
{ "label": "Burgers", "value": "burgers" }
|
||||
]
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### CheckboxGroup
|
||||
|
||||
**Manipulator:** `checkboxgroup`
|
||||
|
||||
A list of options where a user may choose multiple
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| 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.
|
||||
| appKey | string (unique) | The appKey matching what is 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 saved after the user closes the config page.
|
||||
| label | string | The label that should appear next to the item
|
||||
| defaultValue | array of strings | The default selected items. Must match the values in the `options` array
|
||||
| attributes | object | A hash of 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. Each option is an object with a `label` and `value` property.
|
||||
|
||||
##### Example
|
||||
```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" }
|
||||
]
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Submit
|
||||
|
||||
**Manipulator:** `html`
|
||||
|
||||
The submit button for the page. You **MUST** include this component somewhere or users will not be able to save the form.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
|----------|------|-------------
|
||||
| type | string | set to "submit"
|
||||
| defaultValue | string | The text displayed in the button
|
||||
| attributes | object | A hash of HTML attributes to set on the input field.
|
||||
|
||||
##### Example
|
||||
```javascript
|
||||
{
|
||||
"type": "submit",
|
||||
"label": "Save"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Coming Soon...
|
||||
|
||||
- Range Slider
|
||||
- Generic Button
|
||||
- Tabs
|
||||
- Footer
|
||||
- dynamic + draggable list
|
||||
|
||||
---
|
||||
|
||||
## Manipulators
|
||||
|
||||
Each component has a **manipulator.** This is a set of methods used to talk to the item on the page. At a minimum, manipulators must have a `.get()` and `.set(value)` method. When the config page is closed, the `.get()` method is run on all components registered with an `appKey`. Many of these methods fire an event when the method is called. You can listen for these events with `ClayItem.on()`
|
||||
|
||||
#### html
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [string/HTML] value)` | `ClayItem` | `change` | sets the content of the item
|
||||
| `.get()` | `string` | | gets the content of the item
|
||||
|
||||
#### val
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [string] value)` | `ClayItem` | `change` | sets the value of the item
|
||||
| `.get()` | `string` | | gets the content of the item
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents the item from being edited by the user
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows the item to be edited by the user
|
||||
|
||||
#### checked
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [boolean] value)` | `ClayItem` | `change` | check/uncheck the state of the item
|
||||
| `.get()` | `string` | | gets the content of the item
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents the item from being edited by the user
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows the item to be edited by the user
|
||||
|
||||
#### color
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [string \| int] value)` | `ClayItem` | `change` | sets the color picker to the provided color. If the value is a string, it must be provided in hex notation eg `'FF0000'`.
|
||||
| `.get()` | `int` | | The color is returned as an int in order to make it easy to be used on the watch side using `GColorFromHEX()`
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents the item from being edited by the user
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows the item to be edited by the user
|
||||
|
||||
#### radiogroup
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [string] value)` | `ClayItem` | `change` | checks the radio button that corresponds to the provided value
|
||||
| `.get()` | `string` | | gets the value of the checked radio button in the list
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents the item from being edited by the user
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows the item to be edited by the user
|
||||
|
||||
#### checkboxgroup
|
||||
| Method | Returns | Event Fired | Description
|
||||
|---
|
||||
| `.set( [Array] value)` | `ClayItem` | `change` | checks the checkboxes that corresponds to the provided list of values
|
||||
| `.get()` | `string` | | gets the value of the checked radio button in the list
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents the item from being edited by the user
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows the item to be edited by the user
|
||||
|
||||
|
||||
# Extending Clay
|
||||
|
||||
Clay is built to allow developers to add their own basic interactivity to the config page. This is done in a number of ways:
|
||||
|
||||
## Custom Function
|
||||
|
||||
When initializing Clay in your `app.js`, you can optionally provide a function that will be copied and run on the generated config page. **IMPORTANT:** This function is injected by running `.toString()` on it. If you are making use of `require` or any other dynamic features, they will not work. You must make sure that everything the function needs to execute is available in the function body itself.
|
||||
|
||||
This function, when injected into the config page will be run with `ClayConfig` as its context (`this`), and **Minified** as its first parameter. Read below for more information on **Minified**
|
||||
|
||||
#### Example
|
||||
|
||||
##### app.js
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var clayConfig = require('./config');
|
||||
var customClay = require('./custom-clay');
|
||||
var clay = new Clay(clayConfig, customClay);
|
||||
```
|
||||
|
||||
##### custom-clay.js
|
||||
|
||||
```javascript
|
||||
module.exports = function(minified) {
|
||||
var Clay = this;
|
||||
var _ = minified._;
|
||||
var $ = minified.$;
|
||||
var HTML = minified.HTML;
|
||||
|
||||
function toggleBackground() {
|
||||
if (this.get()) {
|
||||
Clay.getItemByAppKey('background').enable();
|
||||
} else {
|
||||
Clay.getItemByAppKey('background').disable();
|
||||
}
|
||||
}
|
||||
|
||||
Clay.on(Clay.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = Clay.getItemByAppKey('cool_stuff');
|
||||
toggleBackground.call(coolStuffToggle);
|
||||
coolStuffToggle.on('change', toggleBackground);
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
## Clay API
|
||||
|
||||
### `ClayConfig([Object] settings, [Array] config, [$Minified] $rootContainer)`
|
||||
|
||||
This is the main way of talking to your generated config page. A reference to the instance of `ClayConfig` is passed to
|
||||
|
||||
#### Properties
|
||||
|
||||
| Property | Type | Description
|
||||
| ---
|
||||
| `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page.
|
||||
| `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page.
|
||||
| `.config` | Array | Reference to the config passed to the constructer and used for generating the page.
|
||||
|
||||
|
||||
#### Methods
|
||||
|
||||
| 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`
|
||||
| `.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`
|
||||
| `.getSettings()` | `Object` - a hash representing all items with an `appKey` where the key is the `appKey` and the value is the result of running `.get()` on the Clay item.
|
||||
| `.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`
|
||||
| `.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`
|
||||
| `.registerComponent( [ClayComponent] component )` <br> Registers a component. You must register all components prior to calling `.build()`. This method is available statically as well | `Boolean` - `true` if the component was registered successfully, otherwise `false`.
|
||||
|
||||
---
|
||||
|
||||
### `ClayItem( [Object] config )`
|
||||
|
||||
#### Properties
|
||||
|
||||
| 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.
|
||||
| `.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` | 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.
|
||||
|
||||
|
||||
#### Methods
|
||||
|
||||
| Method | Returns
|
||||
| ---
|
||||
| `.initialize( [ClayConfig] clay)` <br> You shouldn't ever need to run this method manually as it will automatically be called when the config is built | `ConfigItem`
|
||||
| `.on( [string] events, [function] handler )` <br> Register an event to the provided handler. The handler will be called with this instance of `ClayItem` as the context. If you wish to register multiple events to the same handler, then separate the events with a space. Events will be registered against the `$manipulatorTarget` so most DOM events such as **"change"** or **"click"** can be listened for. | `ClayItem`
|
||||
| `.off( [function] handler )` <br> Remove the given event handler. **NOTE:** This will remove the handler from all registered events | `ClayItem`
|
||||
| `.trigger( [string] name, [object] eventObj={} )` <br> Trigger the provided event and optionally pass extra data to the handler. | `ClayItem`
|
||||
|
||||
In addition to the methods above, all the methods from the item's manipulator will be attached to the `CLayItem`. This includes `.set()` and `.get()`
|
||||
|
||||
---
|
||||
|
||||
## Custom Components
|
||||
|
||||
Clay is also able to be extended using custom components. This allows developers to share components with each other.
|
||||
|
||||
### Component Structure
|
||||
|
||||
Components are simple objects with the following properties:
|
||||
|
||||
#### `ClayComponent`
|
||||
|
||||
| Property | Type | Required | Description
|
||||
|---
|
||||
| name | string | yes | This is the unique way to identify the component and what will be used by the config item's `type`
|
||||
| template | string (HTML) | yes | This is the actual HTML content of the component. Make sure there is only **one** root node in the HTML. This HTML will be passed to minified's `HTML()` method. Any properties provided by the config item will be made available to the template, eg: `label`. The template will also be provided with `clayId` as a unique way to set input `name` attributes.
|
||||
| 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. eg `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` as the first 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 = new Clay(clayConfig);
|
||||
|
||||
clay.registerComponent(require('./my-custom-component'));
|
||||
```
|
||||
|
||||
## Minified
|
||||
|
||||
Minified is a super light JQuery-like library. We only bundle in a small subset of its functionality. Visit the [Minified Docs](http://minifiedjs.com/api/) for more info on how to use minified. Below is the subset of methods available.
|
||||
|
||||
- `$()`
|
||||
- `$$()`
|
||||
- `.get()`
|
||||
- `.select()`
|
||||
- `.set()`
|
||||
- `.add()`
|
||||
- `.ht()`
|
||||
- `HTML()`
|
||||
- `$.request()`
|
||||
- `promise.always()`
|
||||
- `promise.error()`
|
||||
- `$.off()`
|
||||
- `$.ready()`
|
||||
- `$.wait()`
|
||||
- `.on()`
|
||||
- `.each()`
|
||||
- `.find()`
|
||||
- `_()`
|
||||
- `_.copyObj()`
|
||||
- `_.eachObj()`
|
||||
- `_.extend()`
|
||||
- `_.format()`
|
||||
- `_.formatHtml()`
|
||||
- `_.template()`
|
||||
- `_.isObject()`
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
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 local storage.
|
||||
|
||||
#### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page. It is its responsibility to pass 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
|
||||
|
||||
`$ npm run build` packages up the entire Clay project into `dist/clay.js` to be required in the developer's `app.js`
|
||||
|
||||
#### Development Mode
|
||||
|
||||
`$ npm run dev` 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 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 Pebble SDK emulator play nice with Clay
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions.
|
||||
|
||||
## 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()`, `.getItemByAppKey()`, `.getItemById()`, `.getItemsByType()`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+8
-5
@@ -64,7 +64,6 @@ module.exports = [
|
||||
{
|
||||
"type": "radiogroup",
|
||||
"appKey": "radiogroup-test",
|
||||
"defaultValue": "quote' \"test",
|
||||
"label": "Radio test",
|
||||
"options": [
|
||||
{ "label": "Test thing one", "value": "one" },
|
||||
@@ -91,9 +90,9 @@ module.exports = [
|
||||
"type": "input",
|
||||
"appKey": "date",
|
||||
"defaultValue": "",
|
||||
"label": "Date",
|
||||
"label": "Range",
|
||||
"attributes": {
|
||||
type: "date"
|
||||
type: "range"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -102,15 +101,19 @@ module.exports = [
|
||||
"defaultValue": "grape",
|
||||
"label": "Favorite Flavor",
|
||||
"options": [
|
||||
{ "label": "", "value": "" },
|
||||
{ "label": "Berry", "value": "berry" },
|
||||
{ "label": "Grape", "value": "grape" },
|
||||
{ "label": "Banana", "value": "banana" }
|
||||
]
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "submit",
|
||||
"label": "Save"
|
||||
"defaultValue": "Save"
|
||||
}
|
||||
];
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
window.returnTo = '$$RETURN_TO$$';
|
||||
window.returnTo = '#';
|
||||
window.clayConfig = require('./config.js');
|
||||
window.claySettings = {};
|
||||
window.customFn = require('./custom-fn.js');
|
||||
|
||||
Vendored
+3
-627
File diff suppressed because one or more lines are too long
@@ -14,6 +14,7 @@ var autoprefixer = require('gulp-autoprefixer');
|
||||
var uglify = require('gulp-uglify');
|
||||
var sassify = require('sassify');
|
||||
var autoprefixify = require('./src/scripts/vendor/autoprefixify');
|
||||
var insert = require('gulp-insert');
|
||||
|
||||
var sassIncludePaths = [].concat(
|
||||
require('bourbon').includePaths,
|
||||
@@ -35,6 +36,9 @@ var autoprefixerOptions = {
|
||||
};
|
||||
|
||||
var stringifyOptions = ['.html', '.tpl'];
|
||||
var versionMessage = '/* Clay - https://github.com/pebble/clay - Version: ' +
|
||||
require('./package.json').version +
|
||||
' - Build Date: ' + new Date().toISOString() + ' */\n';
|
||||
|
||||
gulp.task('clean-js', function() {
|
||||
return del(['tmp/config-page.js']);
|
||||
@@ -90,6 +94,7 @@ gulp.task('clay', ['inlineHtml'], function() {
|
||||
.pipe(source('clay.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify())
|
||||
.pipe(insert.prepend(versionMessage))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
|
||||
+3
-2
@@ -22,8 +22,8 @@
|
||||
"Pebble",
|
||||
"Config"
|
||||
],
|
||||
"author": "Keegan Lillo",
|
||||
"license": "GPL",
|
||||
"author": "Pebble Technology",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pebble/clay/issues"
|
||||
},
|
||||
@@ -43,6 +43,7 @@
|
||||
"gulp-autoprefixer": "^3.1.0",
|
||||
"gulp-htmlmin": "^1.3.0",
|
||||
"gulp-inline": "0.0.15",
|
||||
"gulp-insert": "^0.5.0",
|
||||
"gulp-sass": "^2.1.1",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-uglify": "^1.5.2",
|
||||
|
||||
@@ -7,6 +7,7 @@ module.exports = {
|
||||
manipulator: 'checkboxgroup',
|
||||
defaults: {
|
||||
label: '',
|
||||
options: []
|
||||
options: [],
|
||||
attributes: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,5 @@
|
||||
module.exports = {
|
||||
name: 'footer',
|
||||
template: require('../../templates/components/footer.tpl'),
|
||||
manipulator: 'html',
|
||||
defaults: {
|
||||
attributes: {}
|
||||
}
|
||||
manipulator: 'html'
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@ module.exports = {
|
||||
template: require('../../templates/components/heading.tpl'),
|
||||
manipulator: 'html',
|
||||
defaults: {
|
||||
attributes: {},
|
||||
size: 4
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ module.exports = {
|
||||
manipulator: 'radiogroup',
|
||||
defaults: {
|
||||
label: '',
|
||||
options: []
|
||||
options: [],
|
||||
attributes: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,8 @@ module.exports = {
|
||||
manipulator: 'val',
|
||||
defaults: {
|
||||
label: '',
|
||||
options: []
|
||||
options: [],
|
||||
attributes: {}
|
||||
},
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
module.exports = {
|
||||
name: 'submit',
|
||||
template: require('../../templates/components/submit.tpl'),
|
||||
manipulator: 'val',
|
||||
manipulator: 'html',
|
||||
defaults: {
|
||||
label: '',
|
||||
attributes: {}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,5 @@
|
||||
module.exports = {
|
||||
name: 'text',
|
||||
template: require('../../templates/components/text.tpl'),
|
||||
manipulator: 'html',
|
||||
defaults: {
|
||||
attributes: {}
|
||||
}
|
||||
manipulator: 'html'
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
utils.updateProperties(self.EVENTS, {writable: false});
|
||||
|
||||
/**
|
||||
* @returns {ClayItem}
|
||||
* @returns {Array.<ClayItem>}
|
||||
*/
|
||||
self.getAllItems = function() {
|
||||
_checkBuilt('getAllItems');
|
||||
@@ -121,21 +121,21 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {string} appKey
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
self.getItemByAppKey = function(key) {
|
||||
self.getItemByAppKey = function(appKey) {
|
||||
_checkBuilt('getItemByAppKey');
|
||||
return _itemsByAppKey[key];
|
||||
return _itemsByAppKey[appKey];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {string} id
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
self.getItemById = function(key) {
|
||||
self.getItemById = function(id) {
|
||||
_checkBuilt('getItemById');
|
||||
return _itemsById[key];
|
||||
return _itemsById[id];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -181,6 +181,9 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
// prevent external modifications of properties
|
||||
utils.updateProperties(self, { writable: false, configurable: false });
|
||||
|
||||
// expose the config to allow developers to update it before the build is run
|
||||
self.config = config;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +194,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
* @param {string|{}} component.manipulator - methods to attach to the component
|
||||
* @param {function} component.manipulator.set - set manipulator method
|
||||
* @param {function} component.manipulator.get - get manipulator method
|
||||
* @param {{}} component.defaults - template defaults
|
||||
* @param {{}} [component.defaults] - template defaults
|
||||
* @param {function} [component.initialize] - method to scaffold the component
|
||||
* @return {boolean} - Returns true if component was registered correctly
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ function ClayItem(config) {
|
||||
'Make sure to register it with ClayConfig.registerComponent()');
|
||||
}
|
||||
|
||||
var _templateData = _.extend({}, _component.defaults, config);
|
||||
var _templateData = _.extend({}, _component.defaults || {}, config);
|
||||
|
||||
/** @type {string|null} */
|
||||
self.id = config.id || null;
|
||||
|
||||
Vendored
-3
@@ -43,9 +43,6 @@ module.exports = function (file, options) {
|
||||
}
|
||||
|
||||
if (typeof file !== 'string') {
|
||||
// Factory: return a function.
|
||||
// Set options variable here so it is ready for when browserifyTransform
|
||||
// is called. Note: first argument is the options.
|
||||
options = file;
|
||||
return browserifyTransform;
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
}
|
||||
|
||||
input {
|
||||
display: none;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
i {
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
}
|
||||
|
||||
input {
|
||||
display: none;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
i {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
value="{{this.value}}"
|
||||
name="clay-{{clayId}}"
|
||||
data-manipulator-target
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
<i></i>
|
||||
</label>
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
<div
|
||||
data-manipulator-target
|
||||
class="item-container-footer"
|
||||
{{each attributes}} {{this.key}}="{{this.value}}" {{/each}}
|
||||
></div>
|
||||
<footer data-manipulator-target class="component component-footer"></footer>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<div class="component component-heading">
|
||||
<h{{size}} data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}}></h{{size}}>
|
||||
<h{{size}} data-manipulator-target></h{{size}}>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
value="{{this.value}}"
|
||||
name="clay-{{clayId}}"
|
||||
data-manipulator-target
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
<i></i>
|
||||
</label>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<label class="component component-select">
|
||||
<span class="label">{{{label}}}</span>
|
||||
<span class="value"></span>
|
||||
<select data-manipulator-target>
|
||||
<select data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}}>
|
||||
{{each options}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{/each}}
|
||||
|
||||
@@ -3,7 +3,5 @@
|
||||
data-manipulator-target
|
||||
type="submit"
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
>
|
||||
{{{label}}}
|
||||
</button>
|
||||
></button>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<div class="component component-text">
|
||||
<p data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}}></p>
|
||||
<p data-manipulator-target></p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user