defaults.def 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {{## def.assignDefault:
  2. {{? it.compositeRule }}
  3. {{
  4. if (it.opts.strictDefaults) {
  5. var $defaultMsg = 'default is ignored for: ' + $passData;
  6. if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
  7. else throw new Error($defaultMsg);
  8. }
  9. }}
  10. {{??}}
  11. if ({{=$passData}} === undefined
  12. {{? it.opts.useDefaults == 'empty' }}
  13. || {{=$passData}} === null
  14. || {{=$passData}} === ''
  15. {{?}}
  16. )
  17. {{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
  18. {{= it.useDefault($sch.default) }}
  19. {{??}}
  20. {{= JSON.stringify($sch.default) }}
  21. {{?}};
  22. {{?}}
  23. #}}
  24. {{## def.defaultProperties:
  25. {{
  26. var $schema = it.schema.properties
  27. , $schemaKeys = Object.keys($schema); }}
  28. {{~ $schemaKeys:$propertyKey }}
  29. {{ var $sch = $schema[$propertyKey]; }}
  30. {{? $sch.default !== undefined }}
  31. {{ var $passData = $data + it.util.getProperty($propertyKey); }}
  32. {{# def.assignDefault }}
  33. {{?}}
  34. {{~}}
  35. #}}
  36. {{## def.defaultItems:
  37. {{~ it.schema.items:$sch:$i }}
  38. {{? $sch.default !== undefined }}
  39. {{ var $passData = $data + '[' + $i + ']'; }}
  40. {{# def.assignDefault }}
  41. {{?}}
  42. {{~}}
  43. #}}