mjml-rails 4.4.2 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8610d3313ee8297b7ac411aa8f23b8c99a85cf41940db1798529d91193fb37d
4
- data.tar.gz: c5099915099d3aeb6e050bf44b3cb81b8fe759686a06b85d61a197e65b7b4dfb
3
+ metadata.gz: 128c814314ffe1c725a9d46d0537c161a45098650f67cf063cf0e27325cd11d2
4
+ data.tar.gz: b23564a1cf6b824359019f60bf08cb1f97d6d7584f1e58a2220fc672a4dea77c
5
5
  SHA512:
6
- metadata.gz: 717f6819381d9f925ce597f05288cfc6f3c07417e353de40561de9ddffc6ac48331e4877ed775818b7b3dbd3836c27e2347bafcbcc9c0247b467565e944911ab
7
- data.tar.gz: ec6662022e6ed5f5e8b6732d61fa766de5af32dd57fcd43c508576bcb7f594b1f413b17452532fa4e7ee94b46d1c90427bb90e3cff1425ae39c05d46c38f371e
6
+ metadata.gz: 9c56d2b1b80bcb2f7ef36cf8e927d135fbdc26fd67f7ac2db52ece28065d1cb98010c89f9abae9176c7861ef3ab65ae099c8cb98ecabf371d06c42cff53f141d
7
+ data.tar.gz: 1eea404a1e315166fd132ec37b76257d4789f030af4853992067230cda800875861b68fde85a358e803ff283d15cb1d14c88ae778dd49e5f27f01109faf0e787
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -95,18 +95,20 @@ If there are configurations you'd like change:
95
95
  - render errors: defaults to `true` (errors raised)
96
96
  - minify: defaults to `false` (not minified)
97
97
  - beautify: defaults to `true` (beautified)
98
- - validation_level: defaults to `soft` (MJML syntax validation)
98
+ - validation_level: defaults to `strict` (abort on any template error, see [MJML validation documentation](https://github.com/mjmlio/mjml/tree/master/packages/mjml-validator#validating-mjml) for possible values)
99
99
 
100
100
  ```ruby
101
101
  # config/initializers/mjml.rb
102
102
  Mjml.setup do |config|
103
- # set to `false` to ignore errors silently
104
- config.raise_render_exception = true
103
+ # ignore errors silently
104
+ config.raise_render_exception = false
105
105
 
106
106
  # optimize the size of your email
107
107
  config.beautify = false
108
108
  config.minify = true
109
- config.validation_level = "strict"
109
+
110
+ # render illformed MJML templates, not recommended
111
+ config.validation_level = "soft"
110
112
  end
111
113
  ```
112
114
 
@@ -15,7 +15,7 @@ module Mjml
15
15
  @@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
16
16
  @@beautify = true
17
17
  @@minify = false
18
- @@validation_level = "soft"
18
+ @@validation_level = "strict"
19
19
 
20
20
  def self.check_version(bin)
21
21
  stdout, _, status = run_mjml('--version', mjml_bin: bin)
@@ -1,5 +1,3 @@
1
- require 'open3'
2
-
3
1
  module Mjml
4
2
  class Parser
5
3
  class ParseError < StandardError; end
@@ -33,11 +31,12 @@ module Mjml
33
31
  # Exec mjml command
34
32
  #
35
33
  # @return [String] The result as string
36
- def run(in_tmp_file, beautify=true, minify=false, validation_level="soft")
34
+ def run(in_tmp_file, beautify=true, minify=false, validation_level="strict")
37
35
  Tempfile.create(["out", ".html"]) do |out_tmp_file|
38
36
  command = "-r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
39
- _, stderr, _ = Mjml.run_mjml(command)
40
- raise ParseError.new(stderr.chomp) unless stderr.blank?
37
+ _, stderr, status = Mjml.run_mjml(command)
38
+ raise ParseError.new(stderr.chomp) unless status.success?
39
+ Mjml.logger.warn(stderr.chomp) unless stderr.blank?
41
40
  out_tmp_file.read
42
41
  end
43
42
  end
@@ -1,4 +1,4 @@
1
1
  module Mjml
2
2
  # Version number no longer matches MJML.io version
3
- VERSION = "4.4.2"
3
+ VERSION = "4.5.0"
4
4
  end
@@ -13,6 +13,15 @@ class NotifierMailer < ActionMailer::Base
13
13
  format.html
14
14
  end
15
15
  end
16
+
17
+ def invalid_template(recipient)
18
+ @recipient = recipient
19
+
20
+ mail(to: @recipient, from: "app@example.com") do |format|
21
+ format.html
22
+ format.text
23
+ end
24
+ end
16
25
  end
17
26
 
18
27
  class NoLayoutMailer < ActionMailer::Base
@@ -58,6 +67,22 @@ class NotifierMailerTest < ActiveSupport::TestCase
58
67
  assert email.text_part.body.match(/We inform you about something/)
59
68
  assert email.text_part.body.match(%r{Please visit https://www.example.com})
60
69
  end
70
+
71
+ test "Invalid template raises error with validation level strict" do
72
+ with_settings(validation_level: 'strict') do
73
+ email = NotifierMailer.invalid_template("user@example.com")
74
+ assert_raise(ActionView::Template::Error) { email.html_part.body.to_s }
75
+ end
76
+ end
77
+
78
+ test "Invalid template gets compiled with validation level soft" do
79
+ with_settings(validation_level: 'soft') do
80
+ email = NotifierMailer.invalid_template("user@example.com")
81
+ assert email.text_part.body.match(/This is valid/)
82
+ assert email.html_part.body.match(/This is valid/)
83
+ refute email.html_part.body.match(/This is invalid/)
84
+ end
85
+ end
61
86
  end
62
87
 
63
88
  class NotifierMailerTest < ActiveSupport::TestCase
@@ -13,54 +13,42 @@ describe Mjml::Parser do
13
13
  parser.stubs(:run).raises(error)
14
14
  end
15
15
 
16
- describe 'when render exception raising is enabled' do
17
- before do
18
- Mjml.setup do |config|
19
- config.raise_render_exception = true
20
- end
21
- end
22
-
23
- it 'raises exception' do
16
+ it 'raises exception with render exception enabled' do
17
+ with_settings(raise_render_exception: true) do
24
18
  err = expect { parser.render }.must_raise(custom_error_class)
25
19
  expect(err.message).must_equal error.message
26
20
  end
27
21
  end
28
22
 
29
- describe 'when render exception raising is disabled' do
30
- before do
31
- Mjml.setup do |config|
32
- config.raise_render_exception = false
33
- end
34
- end
35
-
36
- it 'returns empty string' do
23
+ it 'returns empty string with exception raising disabled' do
24
+ with_settings(raise_render_exception: false) do
37
25
  expect(parser.render).must_equal ''
38
26
  end
39
27
  end
40
28
  end
41
29
 
42
30
  describe 'can read beautify, minify, and validation_level configs' do
43
- it 'use defaults if no config is set' do
31
+ it 'uses defaults if no config is set' do
44
32
  expect(Mjml.beautify).must_equal(true)
45
33
  expect(Mjml.minify).must_equal(false)
46
- expect(Mjml.validation_level).must_equal('soft')
34
+ expect(Mjml.validation_level).must_equal('strict')
47
35
  end
48
36
 
49
- it 'use setup config' do
37
+ it 'uses setup config' do
50
38
  Mjml.setup do |config|
51
39
  config.beautify = false
52
40
  config.minify = true
53
- config.validation_level = 'strict'
41
+ config.validation_level = 'soft'
54
42
  end
55
43
 
56
44
  expect(Mjml.beautify).must_equal(false)
57
45
  expect(Mjml.minify).must_equal(true)
58
- expect(Mjml.validation_level).must_equal('strict')
46
+ expect(Mjml.validation_level).must_equal('soft')
59
47
 
60
48
  Mjml.setup do |config|
61
49
  config.beautify = true
62
50
  config.minify = false
63
- config.validation_level = 'soft'
51
+ config.validation_level = 'strict'
64
52
  end
65
53
  end
66
54
  end
@@ -25,3 +25,20 @@ I18n.enforce_available_locales = false
25
25
 
26
26
  ActionMailer::Base.delivery_method = :test
27
27
  ActionMailer::Base.perform_deliveries = true
28
+
29
+ def with_settings(settings)
30
+ original_settings =
31
+ settings.each_with_object({}) do |(key, _), agg|
32
+ agg[key] = Mjml.public_send(key)
33
+ end
34
+
35
+ settings.each do |key, value|
36
+ Mjml.public_send("#{key}=", value)
37
+ end
38
+
39
+ yield
40
+ ensure
41
+ original_settings.each do |key, value|
42
+ Mjml.public_send("#{key}=", value)
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.2
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Loffler
@@ -35,7 +35,7 @@ cert_chain:
35
35
  lsAqKbu4nrHhtGhkwdYbflf2URJTUxXGptrnPYV7okmEg4rsykK3RAsZ6kMNdKmx
36
36
  DcQ7RSt1TU5eck6c
37
37
  -----END CERTIFICATE-----
38
- date: 2020-11-27 00:00:00.000000000 Z
38
+ date: 2020-11-29 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description: Render MJML + ERb template views in Rails
41
41
  email: sighmon@sighmon.com
@@ -63,7 +63,7 @@ homepage: https://github.com/sighmon/mjml-rails
63
63
  licenses:
64
64
  - MIT
65
65
  metadata: {}
66
- post_install_message: "Don't forget to install MJML e.g. \n$ npm install -g mjml"
66
+ post_install_message: "Don't forget to install MJML e.g. \n$ npm install mjml"
67
67
  rdoc_options: []
68
68
  require_paths:
69
69
  - lib
metadata.gz.sig CHANGED
Binary file