|
| 1 | +# TOC |
| 2 | + - [merge.js](#mergejs) |
| 3 | + - [merge](#mergejs-merge) |
| 4 | + - [schema-defaults.js](#schema-defaultsjs) |
| 5 | + - [createDefaults](#schema-defaultsjs-createdefaults) |
| 6 | + - [defaultForm](#schema-defaultsjs-defaultform) |
| 7 | +<a name=""></a> |
| 8 | + |
| 9 | +<a name="mergejs"></a> |
| 10 | +# merge.js |
| 11 | +should contain a function for merging schema and form definitions. |
| 12 | + |
| 13 | +```js |
| 14 | +_merge.merge.should.be.an('function'); |
| 15 | +``` |
| 16 | + |
| 17 | +<a name="mergejs-merge"></a> |
| 18 | +## merge |
| 19 | +should combine a schema and form definition, regardless of order. |
| 20 | + |
| 21 | +```js |
| 22 | +(0, _merge.merge)(schema, ['name', 'gender']).should.be.deep.equal(stdForm.form); |
| 23 | +(0, _merge.merge)(schema, ['gender']).should.be.deep.equal([stdForm.form[1]]); |
| 24 | +(0, _merge.merge)(schema, ['gender', 'name']).should.be.deep.equal([stdForm.form[1], stdForm.form[0]]); |
| 25 | +``` |
| 26 | + |
| 27 | +should handle a wildcard * in the form definition. |
| 28 | + |
| 29 | +```js |
| 30 | +(0, _merge.merge)(schema, ['*']).should.be.deep.equal(stdForm.form); |
| 31 | +``` |
| 32 | + |
| 33 | +should allow items that are not in the schema. |
| 34 | + |
| 35 | +```js |
| 36 | +(0, _merge.merge)(schema, ['*', { type: 'fieldset' }]).should.be.deep.equal(stdForm.form.concat([{ type: 'fieldset' }])); |
| 37 | +``` |
| 38 | + |
| 39 | +<a name="schema-defaultsjs"></a> |
| 40 | +# schema-defaults.js |
| 41 | +should hold functions for generating a default form schema from defaults it creates. |
| 42 | + |
| 43 | +```js |
| 44 | +_schemaDefaults.defaultForm.should.be.an('function'); |
| 45 | +_schemaDefaults.createDefaults.should.be.an('function'); |
| 46 | +``` |
| 47 | + |
| 48 | +<a name="schema-defaultsjs-createdefaults"></a> |
| 49 | +## createDefaults |
| 50 | +should create default rules. |
| 51 | + |
| 52 | +```js |
| 53 | +var rules = (0, _schemaDefaults.createDefaults)(); |
| 54 | +rules.should.be.an('object'); |
| 55 | +``` |
| 56 | + |
| 57 | +<a name="schema-defaultsjs-defaultform"></a> |
| 58 | +## defaultForm |
| 59 | +should generate default form def from a schema. |
| 60 | + |
| 61 | +```js |
| 62 | +var schema = { |
| 63 | + 'type': 'object', |
| 64 | + 'properties': { |
| 65 | + 'name': { |
| 66 | + 'title': 'Name', |
| 67 | + 'description': 'Gimme yea name lad', |
| 68 | + 'type': 'string' |
| 69 | + }, |
| 70 | + 'gender': { |
| 71 | + 'title': 'Choose', |
| 72 | + 'type': 'string', |
| 73 | + 'enum': ['undefined', 'null', 'NaN'] |
| 74 | + }, |
| 75 | + 'overEighteen': { |
| 76 | + 'title': 'Are you over 18 years old?', |
| 77 | + 'type': 'boolean', |
| 78 | + 'default': false |
| 79 | + }, |
| 80 | + 'attributes': { |
| 81 | + 'type': 'object', |
| 82 | + 'required': ['eyecolor'], |
| 83 | + 'properties': { |
| 84 | + 'eyecolor': { 'type': 'string', 'title': 'Eye color' }, |
| 85 | + 'haircolor': { 'type': 'string', 'title': 'Hair color' }, |
| 86 | + 'shoulders': { |
| 87 | + 'type': 'object', |
| 88 | + 'title': 'Shoulders', |
| 89 | + 'properties': { |
| 90 | + 'left': { 'type': 'string' }, |
| 91 | + 'right': { 'type': 'string' } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | +}; |
| 98 | +var form = [{ |
| 99 | + 'title': 'Name', |
| 100 | + 'description': 'Gimme yea name lad', |
| 101 | + 'schema': { |
| 102 | + 'title': 'Name', |
| 103 | + 'description': 'Gimme yea name lad', |
| 104 | + 'type': 'string' |
| 105 | + }, |
| 106 | + 'ngModelOptions': {}, |
| 107 | + 'key': ['name'], |
| 108 | + 'type': 'text' |
| 109 | +}, { |
| 110 | + 'title': 'Choose', |
| 111 | + 'schema': { |
| 112 | + 'title': 'Choose', |
| 113 | + 'type': 'string', |
| 114 | + 'enum': ['undefined', 'null', 'NaN'] |
| 115 | + }, |
| 116 | + 'ngModelOptions': {}, |
| 117 | + 'key': ['gender'], |
| 118 | + 'type': 'select', |
| 119 | + 'titleMap': [{ |
| 120 | + 'name': 'undefined', |
| 121 | + 'value': 'undefined' |
| 122 | + }, { |
| 123 | + 'name': 'null', |
| 124 | + 'value': 'null' |
| 125 | + }, { |
| 126 | + 'name': 'NaN', |
| 127 | + 'value': 'NaN' |
| 128 | + }] |
| 129 | +}, { |
| 130 | + 'title': 'Are you over 18 years old?', |
| 131 | + 'schema': { |
| 132 | + 'title': 'Are you over 18 years old?', |
| 133 | + 'type': 'boolean', |
| 134 | + 'default': false |
| 135 | + }, |
| 136 | + 'ngModelOptions': {}, |
| 137 | + 'key': ['overEighteen'], |
| 138 | + 'type': 'checkbox' |
| 139 | +}, { |
| 140 | + 'title': 'attributes', |
| 141 | + 'schema': { |
| 142 | + 'type': 'object', |
| 143 | + 'required': ['eyecolor'], |
| 144 | + 'properties': { |
| 145 | + 'eyecolor': { |
| 146 | + 'type': 'string', |
| 147 | + 'title': 'Eye color' |
| 148 | + }, |
| 149 | + 'haircolor': { |
| 150 | + 'type': 'string', |
| 151 | + 'title': 'Hair color' |
| 152 | + }, |
| 153 | + 'shoulders': { |
| 154 | + 'type': 'object', |
| 155 | + 'title': 'Shoulders', |
| 156 | + 'properties': { |
| 157 | + 'left': { |
| 158 | + 'type': 'string' |
| 159 | + }, |
| 160 | + 'right': { |
| 161 | + 'type': 'string' |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + }, |
| 167 | + 'ngModelOptions': {}, |
| 168 | + 'key': ['attributes'], |
| 169 | + 'type': 'fieldset', |
| 170 | + 'items': [{ |
| 171 | + 'title': 'Eye color', |
| 172 | + 'required': true, |
| 173 | + 'schema': { |
| 174 | + 'type': 'string', |
| 175 | + 'title': 'Eye color' |
| 176 | + }, |
| 177 | + 'ngModelOptions': {}, |
| 178 | + 'key': ['attributes', 'eyecolor'], |
| 179 | + 'type': 'text' |
| 180 | + }, { |
| 181 | + 'title': 'Hair color', |
| 182 | + 'schema': { |
| 183 | + 'type': 'string', |
| 184 | + 'title': 'Hair color' |
| 185 | + }, |
| 186 | + 'ngModelOptions': {}, |
| 187 | + 'key': ['attributes', 'haircolor'], |
| 188 | + 'type': 'text' |
| 189 | + }, { |
| 190 | + 'title': 'Shoulders', |
| 191 | + 'schema': { |
| 192 | + 'type': 'object', |
| 193 | + 'title': 'Shoulders', |
| 194 | + 'properties': { |
| 195 | + 'left': { |
| 196 | + 'type': 'string' |
| 197 | + }, |
| 198 | + 'right': { |
| 199 | + 'type': 'string' |
| 200 | + } |
| 201 | + } |
| 202 | + }, |
| 203 | + 'ngModelOptions': {}, |
| 204 | + 'key': ['attributes', 'shoulders'], |
| 205 | + 'type': 'fieldset', |
| 206 | + 'items': [{ |
| 207 | + 'title': 'left', |
| 208 | + 'schema': { |
| 209 | + 'type': 'string' |
| 210 | + }, |
| 211 | + 'ngModelOptions': {}, |
| 212 | + 'key': ['attributes', 'shoulders', 'left'], |
| 213 | + 'type': 'text' |
| 214 | + }, { |
| 215 | + 'title': 'right', |
| 216 | + 'schema': { |
| 217 | + 'type': 'string' |
| 218 | + }, |
| 219 | + 'ngModelOptions': {}, |
| 220 | + 'key': ['attributes', 'shoulders', 'right'], |
| 221 | + 'type': 'text' |
| 222 | + }] |
| 223 | + }] |
| 224 | +}]; |
| 225 | +var f = (0, _schemaDefaults.defaultForm)(schema, (0, _schemaDefaults.createDefaults)()); |
| 226 | +f.form.should.be.deep.equal(form); |
| 227 | +``` |
| 228 | + |
0 commit comments