|
1 /* |
|
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
3 Code licensed under the BSD License: |
|
4 http://developer.yahoo.net/yui/license.txt |
|
5 version: 3.0.0 |
|
6 build: 1549 |
|
7 */ |
|
8 YUI.add('dataschema-base', function(Y) { |
|
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 */ |
|
16 |
|
17 /** |
|
18 * Provides the base DataSchema implementation, which can be extended to |
|
19 * create DataSchemas for specific data formats, such XML, JSON, text and |
|
20 * arrays. |
|
21 * |
|
22 * @module dataschema |
|
23 * @submodule dataschema-base |
|
24 */ |
|
25 |
|
26 var LANG = Y.Lang, |
|
27 /** |
|
28 * Base class for the YUI DataSchema Utility. |
|
29 * @class DataSchema.Base |
|
30 * @static |
|
31 */ |
|
32 SchemaBase = { |
|
33 /** |
|
34 * Overridable method returns data as-is. |
|
35 * |
|
36 * @method apply |
|
37 * @param schema {Object} Schema to apply. |
|
38 * @param data {Object} Data. |
|
39 * @return {Object} Schema-parsed data. |
|
40 * @static |
|
41 */ |
|
42 apply: function(schema, data) { |
|
43 return data; |
|
44 }, |
|
45 |
|
46 /** |
|
47 * Applies field parser, if defined |
|
48 * |
|
49 * @method parse |
|
50 * @param value {Object} Original value. |
|
51 * @param field {Object} Field. |
|
52 * @return {Object} Type-converted value. |
|
53 */ |
|
54 parse: function(value, field) { |
|
55 if(field.parser) { |
|
56 var parser = (LANG.isFunction(field.parser)) ? |
|
57 field.parser : Y.Parsers[field.parser+'']; |
|
58 if(parser) { |
|
59 value = parser.call(this, value); |
|
60 } |
|
61 else { |
|
62 Y.log("Could not find parser for field " + Y.dump(field), "warn", "dataschema-json"); |
|
63 } |
|
64 } |
|
65 return value; |
|
66 } |
|
67 }; |
|
68 |
|
69 Y.namespace("DataSchema").Base = SchemaBase; |
|
70 Y.namespace("Parsers"); |
|
71 |
|
72 |
|
73 |
|
74 }, '3.0.0' ,{requires:['base']}); |