refactor: convert custom.def partial into custom.jst function (for better encapsulation)
parent
1a6e4b576c
commit
caf7557bc0
|
@ -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 { {{?}}
|
|
@ -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 += '}'; }}
|
||||
{{?}}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue