|
8 | 8 | * @module Polymer Elements
|
9 | 9 | */
|
10 | 10 | /**
|
11 |
| - * polymer-meta is used to manage metadata. When an instance of polymer-meta |
12 |
| - * is created, it's automatically registered and add to the metaData storage given an id |
13 |
| - * is set on the element. Use byId() to retrive a specific polymer-meta and |
14 |
| - * the property "list" to retrieve all registered polymer-meta's. |
| 11 | + * The `polymer-meta` elements provides a method of constructing a |
| 12 | + * self-organizing database. It is useful to collate element meta-data for |
| 13 | + * things like catalogs and for sandbox. |
| 14 | + * |
| 15 | + * Example, an element folder has a `metadata.html` file in it, that contains a |
| 16 | + * polymer-meta, something like this: |
| 17 | + * |
| 18 | + * <polymer-meta id="my-element"> |
| 19 | + * <property name="color" type="color"></property> |
| 20 | + * </polymer-meta> |
| 21 | + * |
| 22 | + * An application can import as many of these files as it wants, and then use |
| 23 | + * polymer-meta again to access the collected data. |
| 24 | + * |
| 25 | + * <script> |
| 26 | + * var meta = document.createElement('polymer-meta'); |
| 27 | + * console.log(meta.list); // dump a list of all meta-data elements that have been created |
| 28 | + * </script> |
| 29 | + * |
| 30 | + * Use `byId(id)` to retrive a specific polymer-meta. |
| 31 | + * |
| 32 | + * <script> |
| 33 | + * var meta = document.createElement('polymer-meta'); |
| 34 | + * console.log(meta.byId('my-element')); |
| 35 | + * </script> |
| 36 | + * |
| 37 | + * By default all meta-data are stored in a signle databse. If your meta-data |
| 38 | + * have different types and want them to be stored separately, use `type` to |
| 39 | + * differentiate them. |
15 | 40 | *
|
16 | 41 | * @class polymer-meta
|
17 | 42 | */
|
|
26 | 51 |
|
27 | 52 | Polymer('polymer-meta', {
|
28 | 53 | alwaysPrepare: true,
|
| 54 | + /** |
| 55 | + * The type of meta-data. All meta-data with the same type with be |
| 56 | + * stored together. |
| 57 | + * |
| 58 | + * @attribute type |
| 59 | + * @type string |
| 60 | + * @default 'default' |
| 61 | + */ |
29 | 62 | type: 'default',
|
30 | 63 | ready: function() {
|
31 | 64 | this.idChanged();
|
|
58 | 91 | this.metaArray.splice(i, 1);
|
59 | 92 | }
|
60 | 93 | },
|
| 94 | + /** |
| 95 | + * Returns a list of all meta-data elements with the same type. |
| 96 | + * |
| 97 | + * @attribute list |
| 98 | + * @type array |
| 99 | + * @default [] |
| 100 | + */ |
61 | 101 | get list() {
|
62 | 102 | return this.metaArray;
|
63 | 103 | },
|
| 104 | + /** |
| 105 | + * Returns the first `<template>` in the `<polymer-meta>` subtree. This |
| 106 | + * is useful to store element example. |
| 107 | + * |
| 108 | + * <polymer-meta id="polymer-ui-toolbar" label="Polymer Toolbar"> |
| 109 | + * <template> |
| 110 | + * <polymer-ui-toolbar theme="polymer-ui-light-theme"> |
| 111 | + * <polymer-ui-icon-button icon="menu"></polymer-ui-icon-button> |
| 112 | + * <div flex>Title</div> |
| 113 | + * <polymer-ui-icon-button icon="add"></polymer-ui-icon-button> |
| 114 | + * </polymer-ui-toolbar> |
| 115 | + * </template> |
| 116 | + * </polymer-meta> |
| 117 | + * |
| 118 | + * @attribute archetype |
| 119 | + * @type node |
| 120 | + * @default null |
| 121 | + */ |
64 | 122 | get archetype() {
|
65 | 123 | return this.querySelector('template');
|
66 | 124 | },
|
| 125 | + /** |
| 126 | + * Retrieves meta-data by ID. |
| 127 | + * |
| 128 | + * @method byId |
| 129 | + * @param {String} id The ID of the meta-data to be returned. |
| 130 | + * @returns Returns meta-data. |
| 131 | + */ |
67 | 132 | byId: function(id) {
|
68 | 133 | return this.metaData[id];
|
69 | 134 | },
|
|
0 commit comments