twitst4tz

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

items.jst (2630B)


      1 {{# def.definitions }}
      2 {{# def.errors }}
      3 {{# def.setupKeyword }}
      4 {{# def.setupNextLevel }}
      5 
      6 
      7 {{## def.validateItems:startFrom:
      8   for (var {{=$idx}} = {{=startFrom}}; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
      9     {{
     10       $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
     11       var $passData = $data + '[' + $idx + ']';
     12       $it.dataPathArr[$dataNxt] = $idx;
     13     }}
     14 
     15     {{# def.generateSubschemaCode }}
     16     {{# def.optimizeValidate }}
     17 
     18     {{? $breakOnError }}
     19       if (!{{=$nextValid}}) break;
     20     {{?}}
     21   }
     22 #}}
     23 
     24 {{
     25   var $idx = 'i' + $lvl
     26     , $dataNxt = $it.dataLevel = it.dataLevel + 1
     27     , $nextData = 'data' + $dataNxt
     28     , $currentBaseId = it.baseId;
     29 }}
     30 
     31 var {{=$errs}} = errors;
     32 var {{=$valid}};
     33 
     34 {{? Array.isArray($schema) }}
     35   {{ /* 'items' is an array of schemas */}}
     36   {{ var $additionalItems = it.schema.additionalItems; }}
     37   {{? $additionalItems === false }}
     38     {{=$valid}} = {{=$data}}.length <= {{= $schema.length }};
     39     {{
     40       var $currErrSchemaPath = $errSchemaPath;
     41       $errSchemaPath = it.errSchemaPath + '/additionalItems';      
     42     }}
     43     {{# def.checkError:'additionalItems' }}
     44     {{ $errSchemaPath = $currErrSchemaPath; }}
     45     {{# def.elseIfValid}}
     46   {{?}}
     47 
     48   {{~ $schema:$sch:$i }}
     49     {{? {{# def.nonEmptySchema:$sch }} }}
     50       {{=$nextValid}} = true;
     51 
     52       if ({{=$data}}.length > {{=$i}}) {
     53         {{
     54           var $passData = $data + '[' + $i + ']';
     55           $it.schema = $sch;
     56           $it.schemaPath = $schemaPath + '[' + $i + ']';
     57           $it.errSchemaPath = $errSchemaPath + '/' + $i;
     58           $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
     59           $it.dataPathArr[$dataNxt] = $i;
     60         }}
     61 
     62         {{# def.generateSubschemaCode }}
     63         {{# def.optimizeValidate }}
     64       }
     65 
     66       {{# def.ifResultValid }}
     67     {{?}}
     68   {{~}}
     69 
     70   {{? typeof $additionalItems == 'object' && {{# def.nonEmptySchema:$additionalItems }} }}
     71     {{
     72       $it.schema = $additionalItems;
     73       $it.schemaPath = it.schemaPath + '.additionalItems';
     74       $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
     75     }}
     76     {{=$nextValid}} = true;
     77 
     78     if ({{=$data}}.length > {{= $schema.length }}) {
     79       {{# def.validateItems: $schema.length }}
     80     }
     81 
     82     {{# def.ifResultValid }}
     83   {{?}}
     84 
     85 {{?? {{# def.nonEmptySchema:$schema }} }}
     86   {{ /* 'items' is a single schema */}}
     87   {{
     88     $it.schema = $schema;
     89     $it.schemaPath = $schemaPath;
     90     $it.errSchemaPath = $errSchemaPath;
     91   }}
     92   {{# def.validateItems: 0 }}
     93 {{?}}
     94 
     95 {{? $breakOnError }}
     96   {{= $closingBraces }}
     97   if ({{=$errs}} == errors) {
     98 {{?}}
     99 
    100 {{# def.cleanUp }}