|
1 /* |
|
2 YUI 3.10.3 (build 2fb5187) |
|
3 Copyright 2013 Yahoo! Inc. All rights reserved. |
|
4 Licensed under the BSD License. |
|
5 http://yuilibrary.com/license/ |
|
6 */ |
|
7 |
|
8 YUI.add('dataschema-base', function (Y, NAME) { |
|
9 |
|
10 /** |
|
11 * The DataSchema utility provides a common configurable interface for widgets to |
|
12 * apply a given schema to a variety of data. |
|
13 * |
|
14 * @module dataschema |
|
15 * @main dataschema |
|
16 */ |
|
17 |
|
18 /** |
|
19 * Provides the base DataSchema implementation, which can be extended to |
|
20 * create DataSchemas for specific data formats, such XML, JSON, text and |
|
21 * arrays. |
|
22 * |
|
23 * @module dataschema |
|
24 * @submodule dataschema-base |
|
25 */ |
|
26 |
|
27 var LANG = Y.Lang, |
|
28 /** |
|
29 * Base class for the YUI DataSchema Utility. |
|
30 * @class DataSchema.Base |
|
31 * @static |
|
32 */ |
|
33 SchemaBase = { |
|
34 /** |
|
35 * Overridable method returns data as-is. |
|
36 * |
|
37 * @method apply |
|
38 * @param schema {Object} Schema to apply. |
|
39 * @param data {Object} Data. |
|
40 * @return {Object} Schema-parsed data. |
|
41 * @static |
|
42 */ |
|
43 apply: function(schema, data) { |
|
44 return data; |
|
45 }, |
|
46 |
|
47 /** |
|
48 * Applies field parser, if defined |
|
49 * |
|
50 * @method parse |
|
51 * @param value {Object} Original value. |
|
52 * @param field {Object} Field. |
|
53 * @return {Object} Type-converted value. |
|
54 */ |
|
55 parse: function(value, field) { |
|
56 if(field.parser) { |
|
57 var parser = (LANG.isFunction(field.parser)) ? |
|
58 field.parser : Y.Parsers[field.parser+'']; |
|
59 if(parser) { |
|
60 value = parser.call(this, value); |
|
61 } |
|
62 else { |
|
63 } |
|
64 } |
|
65 return value; |
|
66 } |
|
67 }; |
|
68 |
|
69 Y.namespace("DataSchema").Base = SchemaBase; |
|
70 Y.namespace("Parsers"); |
|
71 |
|
72 |
|
73 }, '3.10.3', {"requires": ["base"]}); |