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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +6 -4
- data/lib/mjml.rb +1 -1
- data/lib/mjml/parser.rb +4 -5
- data/lib/mjml/version.rb +1 -1
- data/test/mjml_test.rb +25 -0
- data/test/parser_test.rb +10 -22
- data/test/test_helper.rb +17 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 128c814314ffe1c725a9d46d0537c161a45098650f67cf063cf0e27325cd11d2
|
4
|
+
data.tar.gz: b23564a1cf6b824359019f60bf08cb1f97d6d7584f1e58a2220fc672a4dea77c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c56d2b1b80bcb2f7ef36cf8e927d135fbdc26fd67f7ac2db52ece28065d1cb98010c89f9abae9176c7861ef3ab65ae099c8cb98ecabf371d06c42cff53f141d
|
7
|
+
data.tar.gz: 1eea404a1e315166fd132ec37b76257d4789f030af4853992067230cda800875861b68fde85a358e803ff283d15cb1d14c88ae778dd49e5f27f01109faf0e787
|
checksums.yaml.gz.sig
CHANGED
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 `
|
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
|
-
#
|
104
|
-
config.raise_render_exception =
|
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
|
-
|
109
|
+
|
110
|
+
# render illformed MJML templates, not recommended
|
111
|
+
config.validation_level = "soft"
|
110
112
|
end
|
111
113
|
```
|
112
114
|
|
data/lib/mjml.rb
CHANGED
@@ -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 = "
|
18
|
+
@@validation_level = "strict"
|
19
19
|
|
20
20
|
def self.check_version(bin)
|
21
21
|
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
data/lib/mjml/parser.rb
CHANGED
@@ -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="
|
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,
|
40
|
-
raise ParseError.new(stderr.chomp) unless
|
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
|
data/lib/mjml/version.rb
CHANGED
data/test/mjml_test.rb
CHANGED
@@ -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
|
data/test/parser_test.rb
CHANGED
@@ -13,54 +13,42 @@ describe Mjml::Parser do
|
|
13
13
|
parser.stubs(:run).raises(error)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
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
|
-
|
30
|
-
|
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 '
|
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('
|
34
|
+
expect(Mjml.validation_level).must_equal('strict')
|
47
35
|
end
|
48
36
|
|
49
|
-
it '
|
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 = '
|
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('
|
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 = '
|
51
|
+
config.validation_level = 'strict'
|
64
52
|
end
|
65
53
|
end
|
66
54
|
end
|
data/test/test_helper.rb
CHANGED
@@ -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
|
+
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-
|
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
|
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
|