|
0
|
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.0b1 |
|
|
6 |
build: 1163 |
|
|
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 |
} |
|
|
63 |
} |
|
|
64 |
return value; |
|
|
65 |
} |
|
|
66 |
}; |
|
|
67 |
|
|
|
68 |
Y.namespace("DataSchema").Base = SchemaBase; |
|
|
69 |
Y.namespace("Parsers"); |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
}, '3.0.0b1' ,{requires:['base']}); |