mjml-rails 4.4.0 → 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 +15 -7
- data/lib/mjml.rb +30 -16
- data/lib/mjml/parser.rb +5 -6
- data/lib/mjml/version.rb +1 -1
- data/test/mjml_test.rb +25 -0
- data/test/parser_test.rb +21 -30
- data/test/test_helper.rb +17 -0
- metadata +29 -29
- metadata.gz.sig +2 -3
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
@@ -66,13 +66,19 @@ Run the following command to install it:
|
|
66
66
|
bundle install
|
67
67
|
```
|
68
68
|
|
69
|
-
|
69
|
+
Add the MJML parser to your project with your favourite package manager:
|
70
70
|
|
71
71
|
```console
|
72
|
-
|
72
|
+
# with npm
|
73
|
+
npm install mjml
|
74
|
+
|
75
|
+
# with yarn
|
76
|
+
yarn add mjml
|
73
77
|
```
|
74
78
|
|
75
|
-
|
79
|
+
MJML-Rails falls back to a global installation of MJML but it is strongly recommended to add MJML directly to your project.
|
80
|
+
|
81
|
+
You'll need at least Node.js version 6 for MJML to function properly.
|
76
82
|
|
77
83
|
If you're using ```:haml``` or any other Rails template language, create an initializer to set it up:
|
78
84
|
|
@@ -89,18 +95,20 @@ If there are configurations you'd like change:
|
|
89
95
|
- render errors: defaults to `true` (errors raised)
|
90
96
|
- minify: defaults to `false` (not minified)
|
91
97
|
- beautify: defaults to `true` (beautified)
|
92
|
-
- 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)
|
93
99
|
|
94
100
|
```ruby
|
95
101
|
# config/initializers/mjml.rb
|
96
102
|
Mjml.setup do |config|
|
97
|
-
#
|
98
|
-
config.raise_render_exception =
|
103
|
+
# ignore errors silently
|
104
|
+
config.raise_render_exception = false
|
99
105
|
|
100
106
|
# optimize the size of your email
|
101
107
|
config.beautify = false
|
102
108
|
config.minify = true
|
103
|
-
|
109
|
+
|
110
|
+
# render illformed MJML templates, not recommended
|
111
|
+
config.validation_level = "soft"
|
104
112
|
end
|
105
113
|
```
|
106
114
|
|
data/lib/mjml.rb
CHANGED
@@ -15,36 +15,50 @@ 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
|
-
|
22
|
-
|
21
|
+
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
22
|
+
status.success? && stdout.include?("mjml-core: #{Mjml.mjml_binary_version_supported}")
|
23
|
+
rescue StandardError
|
23
24
|
false
|
24
25
|
end
|
25
26
|
|
27
|
+
def self.run_mjml(args, mjml_bin: nil)
|
28
|
+
mjml_bin ||= BIN
|
29
|
+
|
30
|
+
Open3.capture3("#{mjml_bin} #{args}")
|
31
|
+
end
|
32
|
+
|
26
33
|
def self.discover_mjml_bin
|
27
|
-
# Check for
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
installer_path = bin_path_from('npm') || bin_path_from('yarn')
|
33
|
-
unless installer_path
|
34
|
-
puts Mjml.mjml_binary_error_string
|
35
|
-
return nil
|
34
|
+
# Check for local install of MJML with yarn
|
35
|
+
yarn_bin = `which yarn`.chomp
|
36
|
+
if yarn_bin.present?
|
37
|
+
mjml_bin = "#{yarn_bin} run mjml"
|
38
|
+
return mjml_bin if check_version(mjml_bin)
|
36
39
|
end
|
37
40
|
|
38
|
-
|
39
|
-
|
41
|
+
# Check for a local install of MJML with npm
|
42
|
+
npm_bin = `which npm`.chomp
|
43
|
+
if npm_bin.present? && (installer_path = bin_path_from(npm_bin)).present?
|
44
|
+
mjml_bin = File.join(installer_path, 'mjml')
|
45
|
+
return mjml_bin if check_version(mjml_bin)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Check for a global install of MJML
|
49
|
+
mjml_bin = `which mjml`.chomp
|
50
|
+
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
|
40
51
|
|
41
52
|
puts Mjml.mjml_binary_error_string
|
42
53
|
nil
|
43
54
|
end
|
44
55
|
|
45
56
|
def self.bin_path_from(package_manager)
|
46
|
-
|
47
|
-
|
57
|
+
stdout, _, status = Open3.capture3("#{package_manager} bin")
|
58
|
+
|
59
|
+
return unless status.success?
|
60
|
+
|
61
|
+
stdout.chomp
|
48
62
|
rescue Errno::ENOENT # package manager is not installed
|
49
63
|
nil
|
50
64
|
end
|
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
|
-
command = "
|
39
|
-
_,
|
40
|
-
raise ParseError.new(stderr.
|
36
|
+
command = "-r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
|
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,61 +13,52 @@ describe Mjml::Parser do
|
|
13
13
|
parser.stubs(:run).raises(error)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'raises exception' do
|
24
|
-
-> { parser.render }.must_raise(custom_error_class, error.message)
|
16
|
+
it 'raises exception with render exception enabled' do
|
17
|
+
with_settings(raise_render_exception: true) do
|
18
|
+
err = expect { parser.render }.must_raise(custom_error_class)
|
19
|
+
expect(err.message).must_equal error.message
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
config.raise_render_exception = false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns empty string' do
|
36
|
-
parser.render.must_equal ''
|
23
|
+
it 'returns empty string with exception raising disabled' do
|
24
|
+
with_settings(raise_render_exception: false) do
|
25
|
+
expect(parser.render).must_equal ''
|
37
26
|
end
|
38
27
|
end
|
39
28
|
end
|
40
29
|
|
41
30
|
describe 'can read beautify, minify, and validation_level configs' do
|
42
|
-
it '
|
31
|
+
it 'uses defaults if no config is set' do
|
43
32
|
expect(Mjml.beautify).must_equal(true)
|
44
33
|
expect(Mjml.minify).must_equal(false)
|
45
|
-
expect(Mjml.validation_level).must_equal('
|
34
|
+
expect(Mjml.validation_level).must_equal('strict')
|
46
35
|
end
|
47
36
|
|
48
|
-
it '
|
37
|
+
it 'uses setup config' do
|
49
38
|
Mjml.setup do |config|
|
50
39
|
config.beautify = false
|
51
40
|
config.minify = true
|
52
|
-
config.validation_level = '
|
41
|
+
config.validation_level = 'soft'
|
53
42
|
end
|
54
43
|
|
55
44
|
expect(Mjml.beautify).must_equal(false)
|
56
45
|
expect(Mjml.minify).must_equal(true)
|
57
|
-
expect(Mjml.validation_level).must_equal('
|
46
|
+
expect(Mjml.validation_level).must_equal('soft')
|
47
|
+
|
48
|
+
Mjml.setup do |config|
|
49
|
+
config.beautify = true
|
50
|
+
config.minify = false
|
51
|
+
config.validation_level = 'strict'
|
52
|
+
end
|
58
53
|
end
|
59
54
|
end
|
60
55
|
end
|
61
56
|
|
62
57
|
describe '#run' do
|
63
|
-
describe 'when shell command
|
64
|
-
let(:error) { 'shell error' }
|
65
|
-
let(:stderr) { mock('stderr', eof?: false, read: error) }
|
66
|
-
|
67
|
-
before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
|
68
|
-
|
58
|
+
describe 'when shell command failed' do
|
69
59
|
it 'raises exception' do
|
70
|
-
|
60
|
+
err = expect { parser.run "/tmp/non_existent_file.mjml" }.must_raise(Mjml::Parser::ParseError)
|
61
|
+
expect(err.message).must_include 'Command line error'
|
71
62
|
end
|
72
63
|
end
|
73
64
|
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,41 +1,41 @@
|
|
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
|
8
8
|
- Steven Pickles
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
14
|
+
MIIEKDCCApCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAfMR0wGwYDVQQDDBR5b3Vy
|
15
|
+
L0RDPWVtYWlsL0RDPWNvbTAeFw0yMDExMjIwNTA5MjJaFw0yMTExMjIwNTA5MjJa
|
16
|
+
MB8xHTAbBgNVBAMMFHlvdXIvREM9ZW1haWwvREM9Y29tMIIBojANBgkqhkiG9w0B
|
17
|
+
AQEFAAOCAY8AMIIBigKCAYEAmYphpc2KJNqmKAAKTE53F59mnVv2aW8r5NFDZqG0
|
18
|
+
DF6V8N5rdWanaMLlo1HyU9r7D1f/h7O/LnjZemvgH6MROd19Qe64GIdIPRXC/ZxM
|
19
|
+
cTBNC7GMoZf9LomBmg8sXnoL0Z2enUP6BV716I00EecxrEb8drtvZlRwjUgRcZrv
|
20
|
+
iEaanYYp1Sw3+koyOsof/xYb3Pn2TAh9UE58lbVDpf88zc74ij3Vs3+LW/k+jZzh
|
21
|
+
pzo7qq47XeVNGWtVDGm3dk8QLrIyQdk28B2ZRJ+HeuLEgx7ASDYFVZc05QlAjehS
|
22
|
+
4k37CIgF0ODDnscoSNNb6toFzaiD/kU9+ManRj871qOAMDlc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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
|
@@ -78,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
81
|
+
rubygems_version: 3.1.4
|
82
|
+
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: MJML + ERb templates
|
85
85
|
test_files:
|
metadata.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
�
|
3
|
-
/V��iڇv��D'1|�8(�h�';�"W���N�
|
1
|
+
+��om����kw��O[�J�9ͬm)��mfh����R�JL�ZZĚ<��Cr@z�;�6)�w�ny� ��*����R���Ŏji��Ix���9��"@�T�[;�!�r�r��GG��Pu��C��8�!���:8���X9*��v�#�ͣ�W]���ztjHuJ�e��de���{J2�nq��c�Y�dU�<�_����)Ԡ�{Y�7�@,�ڼ�<Fͱ� ����)�+ALopX��F$'�� �WJ��q� ����k*�`��ϋ�?��L�g�x��:qj`�~o���w�&� K�R�D����XJ4��x
|
2
|
+
�1l�Ќ�S�&A�f�N���BH�o'٫�IHT�f��Iv��B5�1]��6BH��Ft��2���x�
|