twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

_limit.jst (3564B)


      1 {{# def.definitions }}
      2 {{# def.errors }}
      3 {{# def.setupKeyword }}
      4 {{# def.$data }}
      5 
      6 {{## def.setExclusiveLimit:
      7   $exclusive = true;
      8   $errorKeyword = $exclusiveKeyword;
      9   $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
     10 #}}
     11 
     12 {{
     13   var $isMax = $keyword == 'maximum'
     14     , $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
     15     , $schemaExcl = it.schema[$exclusiveKeyword]
     16     , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
     17     , $op = $isMax ? '<' : '>'
     18     , $notOp = $isMax ? '>' : '<'
     19     , $errorKeyword = undefined;
     20 }}
     21 
     22 {{? $isDataExcl }}
     23   {{
     24     var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
     25       , $exclusive = 'exclusive' + $lvl
     26       , $exclType = 'exclType' + $lvl
     27       , $exclIsNumber = 'exclIsNumber' + $lvl
     28       , $opExpr = 'op' + $lvl
     29       , $opStr = '\' + ' + $opExpr + ' + \'';
     30   }}
     31   var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
     32   {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
     33 
     34   var {{=$exclusive}};
     35   var {{=$exclType}} = typeof {{=$schemaValueExcl}};
     36   if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
     37     {{ var $errorKeyword = $exclusiveKeyword; }}
     38     {{# def.error:'_exclusiveLimit' }}
     39   } else if ({{# def.$dataNotType:'number' }}
     40             {{=$exclType}} == 'number'
     41               ? (
     42                   ({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
     43                     ? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
     44                     : {{=$data}} {{=$notOp}} {{=$schemaValue}}
     45                 )
     46               : (
     47                   ({{=$exclusive}} = {{=$schemaValueExcl}} === true)
     48                     ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
     49                     : {{=$data}} {{=$notOp}} {{=$schemaValue}}
     50                 )
     51             || {{=$data}} !== {{=$data}}) {
     52     var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
     53     {{
     54       if ($schema === undefined) {
     55         $errorKeyword = $exclusiveKeyword;
     56         $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
     57         $schemaValue = $schemaValueExcl;
     58         $isData = $isDataExcl;
     59       }
     60     }}
     61 {{??}}
     62   {{
     63     var $exclIsNumber = typeof $schemaExcl == 'number'
     64       , $opStr = $op;  /*used in error*/
     65   }}
     66 
     67   {{? $exclIsNumber && $isData }}
     68     {{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
     69     if ({{# def.$dataNotType:'number' }}
     70         ( {{=$schemaValue}} === undefined
     71           || {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
     72             ? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
     73             : {{=$data}} {{=$notOp}} {{=$schemaValue}} )
     74         || {{=$data}} !== {{=$data}}) {
     75   {{??}}
     76     {{
     77       if ($exclIsNumber && $schema === undefined) {
     78           {{# def.setExclusiveLimit }}
     79           $schemaValue = $schemaExcl;
     80           $notOp += '=';
     81       } else {
     82         if ($exclIsNumber)
     83           $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
     84 
     85         if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
     86           {{# def.setExclusiveLimit }}
     87           $notOp += '=';
     88         } else {
     89           $exclusive = false;
     90           $opStr += '=';
     91         }
     92       }
     93 
     94       var $opExpr = '\'' + $opStr + '\''; /*used in error*/
     95     }}
     96 
     97     if ({{# def.$dataNotType:'number' }}
     98         {{=$data}} {{=$notOp}} {{=$schemaValue}}
     99         || {{=$data}} !== {{=$data}}) {
    100   {{?}}
    101 {{?}}
    102     {{ $errorKeyword = $errorKeyword || $keyword; }}
    103     {{# def.error:'_limit' }}
    104   } {{? $breakOnError }} else { {{?}}