Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default validation level to strict and honor validation_level #72

Merged
merged 4 commits into from
Nov 29, 2020

Conversation

doits
Copy link

@doits doits commented Nov 27, 2020

Note: This is based on top of #71. Please first look at #71, so hopefully #71 can be merged and then there will be fewer changes here. Then you can take a look at this one.

Second note: If this is merged and released, there should be a major version bump (I'd say 4.5) with a changelog entry, because it is a possible backwards incompatible change if somebody has:

  • manually set validation level to soft (e.g. is not using the default config) and
  • relies on MJML-Rails raising an error on any template error, which it wouldn't do then anymore

Before this commit MJML-Rails always raised an exception if there is any
template validation error.

In MJML there are two validation levels though (besides disabling
validation completely):

  • strict: Raise an error if there are any problems, abort
  • soft: Do your best and compile what you can, but do not raise any
    error. Output errors on stderr.

Right now it does not matter what validation level is used in
MJML-Rails: It always raises an error if something is wrong with the
template, which actually makes the setting MJML.validation_level
superfluous.

With this commit, MJML-Rails follows the MJML convention to only abort
if the validation level is strict. If it is soft, it lets MJML do
what it can and only logs the errors, like MJML does.

To prevent apps using the default configuration from breaking, the
default validation level is changed to strict, too. This means it
raises an error on an invalid template like it did before.

`with_settings` can be used to change MJML-Rails settings only for the
duration of the block. It is passed a hash with settings to change.

```ruby
puts Mjml.validation_level
# => 'soft'

with_settings(validation_level: 'strict') do
  puts Mjml.validation_level
  # => 'strict'
end

puts Mjml.validation_level
# => 'soft'
```
Before this commit MJML-Rails *always* raised an exception if there is any
template validation error.

In MJML there are two validation levels though (besides disabling
validation at all):

- `strict`: Raise an error if there are any problems, abort
- `soft`: Do your best and compile what you can, but do not raise any
  error. Output errors on stderr.

Right now it does not matter what validation level is used in
MJML-Rails: It always raises an error if something is wrong with the
template, which actually makes the setting `MJML.validation_level`
superfluous.

With this commit, MJML-Rails follows the MJML convention to only abort
if the validation level is `strict`. If it is `soft`, it lets MJML do
what it can and only logs the errors, like MJML does.

To prevent apps using the default configuration from breaking, the
default validation level is changed to `strict`, too. This means it
raises an error on an invalid template like it did before.
@sighmon sighmon closed this Nov 28, 2020
@sighmon sighmon reopened this Nov 29, 2020
@sighmon sighmon merged commit 3c190e4 into sighmon:master Nov 29, 2020
@sighmon
Copy link
Owner

sighmon commented Nov 29, 2020

@doits Looks good, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants