mjml-validator
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -10,2 +10,6 @@ 'use strict'; | ||
var _concat = require('lodash/concat'); | ||
var _concat2 = _interopRequireDefault(_concat); | ||
var _keys = require('lodash/keys'); | ||
@@ -29,2 +33,4 @@ | ||
var WHITELIST = ['mj-class']; | ||
var validateAttribute = exports.validateAttribute = function validateAttribute(element) { | ||
@@ -40,3 +46,3 @@ var attributes = element.attributes; | ||
var avalaibleAttributes = (0, _keys2.default)(Component.defaultMJMLDefinition.attributes); | ||
var avalaibleAttributes = (0, _concat2.default)((0, _keys2.default)(Component.defaultMJMLDefinition.attributes), WHITELIST); | ||
var unknownAttributes = (0, _filter2.default)((0, _keys2.default)(attributes), function (attribute) { | ||
@@ -50,3 +56,3 @@ return !(0, _includes2.default)(avalaibleAttributes, attribute); | ||
return (0, _ruleError2.default)('Attributes ' + unknownAttributes.join(', ') + ' ' + (unknownAttributes.length > 1 ? "are illegals" : "is illegal"), element); | ||
return (0, _ruleError2.default)((unknownAttributes.length > 1 ? "Attributes" : "Attribute") + ' ' + unknownAttributes.join(', ') + ' ' + (unknownAttributes.length > 1 ? "are illegal" : "is illegal"), element); | ||
}; |
@@ -50,4 +50,4 @@ 'use strict'; | ||
return (0, _ruleError2.default)('Cannot be used inside ' + tagName + ', only in : ' + ChildComponent.parentTag.join(', '), child); | ||
return (0, _ruleError2.default)(ChildComponent.tagName + ' cannot be used inside ' + tagName + ', only in: ' + ChildComponent.parentTag.join(', '), child); | ||
})); | ||
}; |
{ | ||
"name": "mjml-validator", | ||
"description": "mjml-validator", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
# mjml-validator | ||
MJML provide a validation layer that help you building your email. It can detects if you misplaced or mispelled an element, same with attributes. It supports 3 level of validation : | ||
- skip : your document is not validated at all | ||
- soft (default) : your document is validated, but even if it has errors it will be rendered | ||
- strict : your document is validated but if it has errors it will not render anything | ||
MJML provides a validation layer that helps you building your email. It can detect if you misplaced or mispelled a MJML component, or if you used any unauthorised attribute on a specific component. It supports 3 levels of validation: | ||
- skip: your document is rendered without going through validation | ||
- soft (default): your document is going through validation and is rendered, even if it has errors | ||
- strict: your document is going through validation and is not rendered if it has any error | ||
## In cli | ||
## In CLI | ||
In `mjml` command line you can add a `-l` or `--level` with validation level you want. Ex: `mjml -l strict -r my_template.mjml` | ||
When using the `mjml` command line, you can add the option `-l` or `--level` with the validation level you want. Ex: `mjml -l strict -r my_template.mjml` | ||
## In Javascript | ||
In Javascript you can provide the level through the `options` params on `MJMLRenderer`. Ex: `new MJMLRenderer(inputMJML, { level: strict })` | ||
In Javascript, you can provide the level through the `options` parameters on `MJMLRenderer`. Ex: `new MJMLRenderer(inputMJML, { level: strict })` | ||
`strict` will raise an `MJMLValidationError` exception. This object has 2 methods: | ||
- `getErrors` that returns you an array of object with `line`, `message` and `tagName` and a `formattedMessage`. | ||
- `getMessages` that returns you an array of `formattedMessage`. | ||
`strict` will raise a `MJMLValidationError` exception. This object has 2 methods: | ||
- `getErrors` returns an array of objects with `line`, `message`, `tagName` as well as a `formattedMessage` which contains the `line`, `message` and `tagName` concatenated in a sentence. | ||
- `getMessages` returns an array of `formattedMessage`. | ||
`soft` will not raise an exception, instead you can find errors inside the object returned by `render` methods : `errors`. It the same object returned by `getErrors` on strict mode | ||
When using `soft`, no exception will be raised. You can get the errors using the object returned by the `render` method `errors`. It is the same object returned by `getErrors` on strict mode. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8079
153