1 | "use strict";
|
2 |
|
3 | var Util = require("./boilerplate.util");
|
4 |
|
5 | module.exports = function( cls ) {
|
6 | |
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | cls.prototype.parseConverter = parseConverter;
|
17 | return cls;
|
18 | };
|
19 |
|
20 |
|
21 | function parseConverter( type ) {
|
22 | if( typeof type === 'string' ) return convString.call( this, type );
|
23 | if( Array.isArray( type ) ) return convArray.call( this, type );
|
24 | if( Util.isSpecial( type, "const" ) ) return convConst.call( this, type );
|
25 | if( Util.isSpecial( type, "behind" ) ) return convBehind.call( this, type );
|
26 | if( Util.isSpecial( type, "|" ) ) return convPipe.call( this, type );
|
27 | if( Util.isSpecial( type, "*" ) ) return convArgs.call( this, type );
|
28 | throw "Bad converter syntax: " + JSON.stringify( type );
|
29 | };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function convConst( type ) {
|
35 |
|
36 | }
|
37 |
|
38 |
|
39 | function convString( type ) {
|
40 | if( CONVERTERS.args0.indexOf( type ) === -1 ) {
|
41 | throw "Unknown simple converter `" + type + "`!\nAvailable simple converters are: "
|
42 | + CONVERTERS.args0.join(", ") + ".";
|
43 | }
|
44 |
|
45 | var name = `conv_${type}`;
|
46 | if( this.addName( name ) ) {
|
47 | this.sections.converters.push(
|
48 | `var ${name} = Converters.get('${type}');`
|
49 | );
|
50 | }
|
51 | this.sections.requires.Converters = "require('tfw.binding.converters');";
|
52 | return name;
|
53 | }
|
54 |
|
55 | function convArray( type ) {
|
56 | var name = this.getFreeName( "conv_enum" );
|
57 | this.sections.converters.push(
|
58 | `var ${name} = Converters.get('enum')(${JSON.stringify( type )});`
|
59 | );
|
60 | this.sections.requires.Converters = "require('tfw.binding.converters');";
|
61 | return name;
|
62 | }
|
63 |
|
64 | function convBehind( type ) {
|
65 |
|
66 | }
|
67 |
|
68 | function convPipe( type ) {
|
69 | }
|
70 |
|
71 | function convArgs( type ) {
|
72 | }
|
73 |
|
74 |
|
75 | var CONVERTERS = {
|
76 | args0: [
|
77 | "array",
|
78 | "boolean",
|
79 | "booleans",
|
80 | "color",
|
81 | "intl",
|
82 | "isEmpty",
|
83 | "isNotEmpty",
|
84 | "keys",
|
85 | "length",
|
86 | "list",
|
87 | "multilang",
|
88 | "not",
|
89 | "sortedKeys",
|
90 | "string",
|
91 | "strings",
|
92 | "unit",
|
93 | "units",
|
94 | "validator"
|
95 | ]
|
96 | };
|