diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-02-16 16:06:35 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-02-19 15:21:14 -0500 |
commit | a52cbcea4140a50d84fb472062247851ce9c6708 (patch) | |
tree | 750312bf1ae900d14d1f423b5fe34f6fabc26f9d | |
parent | 9e421daf679dfb39251a9325f8ad97ea479afbe6 (diff) | |
download | tame-a52cbcea4140a50d84fb472062247851ce9c6708.tar.gz tame-a52cbcea4140a50d84fb472062247851ce9c6708.tar.bz2 tame-a52cbcea4140a50d84fb472062247851ce9c6708.zip |
Correct param initialization
-rw-r--r-- | src/current/compiler/js.xsl | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl index 95541cd..0d9b6f4 100644 --- a/src/current/compiler/js.xsl +++ b/src/current/compiler/js.xsl @@ -273,6 +273,23 @@ <value-of select="@default" /> <text>',</text> + <text>depth: </text> + <!-- TODO: this logic is duplicated multiple places --> + <choose> + <when test="@set = 'vector'"> + <sequence select="1" /> + </when> + + <when test="@set = 'matrix'"> + <sequence select="2" /> + </when> + + <otherwise> + <sequence select="0" /> + </otherwise> + </choose> + <text>,</text> + <text>required: </text> <!-- param is required if the attribute is present, not non-empty --> <value-of select="string( not( boolean( @default ) ) )" /> @@ -1877,31 +1894,34 @@ { for ( var param in params ) { - var val = params[ param ]['default']; - if ( !val ) - { - continue; - } + var param_data = params[ param ]; + var val = param_data['default'] || 0; + var depth = param_data.depth || 0; - args[ param ] = set_defaults( args[ param ], val ); + args[ param ] = set_defaults( args[ param ], val, +depth ); } } - function set_defaults( input, value ) + function set_defaults( input, value, depth ) { // scalar - if ( !( typeof input === 'object' ) ) + if ( depth === 0 ) { return ( input === '' || input === undefined ) ? value : input; } - // otherwise, assume array - var i = input.length; + input = input || []; + + // vector or matrix + var i = input.length || 1; var ret = []; + var value = ( depth === 2 ) ? [ value ] : value; + while ( i-- ) { - ret[i] = ( input[i] === '' ) ? value : input[i]; + ret[i] = ( input[i] === '' || input[i] === undefined ) ? value : input[i]; } + return ret; } ]]> |