diff --git a/lib/dot/custom.def b/lib/dot/custom.jst similarity index 94% rename from lib/dot/custom.def rename to lib/dot/custom.jst index e84e509..68e7d0f 100644 --- a/lib/dot/custom.def +++ b/lib/dot/custom.jst @@ -1,10 +1,11 @@ +{{# def.definitions }} +{{# def.errors }} +{{# def.setupKeyword }} + {{ - var $schema = it.schema[$rule.keyword] + var $rule = this , $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it) , $ruleErrs = $ruleValidate.code + '.errors' - , $schemaPath = it.schemaPath + '.' + $rule.keyword - , $errSchemaPath = it.errSchemaPath + '/' + $rule.keyword - , $errs = 'errs' + $lvl , $i = 'i' + $lvl , $ruleErr = 'ruleErr' + $lvl , $rDef = $rule.definition @@ -16,6 +17,7 @@ throw new Error('async keyword in sync schema'); }} + {{? !($inline || $macro) }}{{=$ruleErrs}} = null;{{?}} var {{=$errs}} = errors; var valid{{=$lvl}}; @@ -146,6 +148,5 @@ if (!{{# def.ruleValidationResult }}) { } {{?}} {{?}} - {{ $errorKeyword = undefined; }} } {{? $breakOnError }} else { {{?}} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index f42da13..9e033ca 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -106,11 +106,7 @@ {{?}} {{~ $rulesGroup.rules:$rule }} {{? $shouldUseRule($rule) }} - {{? $rule.custom }} - {{# def.custom }} - {{??}} - {{= $rule.code(it, $rule.keyword) }} - {{?}} + {{= $rule.code(it, $rule.keyword) }} {{? $breakOnError }} {{ $closingBraces1 += '}'; }} {{?}} diff --git a/lib/keyword.js b/lib/keyword.js index a40d5d3..38209f7 100644 --- a/lib/keyword.js +++ b/lib/keyword.js @@ -1,6 +1,7 @@ 'use strict'; var IDENTIFIER = /^[a-z_$][a-z0-9_$]*$/i; +var customRuleCode = require('./dotjs/custom'); /** * Define custom keyword @@ -51,7 +52,12 @@ module.exports = function addKeyword(keyword, definition) { self.RULES.push(ruleGroup); } - var rule = { keyword: keyword, definition: definition, custom: true }; + var rule = { + keyword: keyword, + definition: definition, + custom: true, + code: customRuleCode + }; ruleGroup.rules.push(rule); }