mjml-rails 4.3.0 → 4.4.2
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 +5 -3
- data/README.md +25 -9
- data/lib/mjml.rb +38 -10
- data/lib/mjml/parser.rb +5 -5
- data/lib/mjml/version.rb +1 -1
- data/test/parser_test.rb +20 -14
- metadata +28 -29
- 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: a8610d3313ee8297b7ac411aa8f23b8c99a85cf41940db1798529d91193fb37d
|
4
|
+
data.tar.gz: c5099915099d3aeb6e050bf44b3cb81b8fe759686a06b85d61a197e65b7b4dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717f6819381d9f925ce597f05288cfc6f3c07417e353de40561de9ddffc6ac48331e4877ed775818b7b3dbd3836c27e2347bafcbcc9c0247b467565e944911ab
|
7
|
+
data.tar.gz: ec6662022e6ed5f5e8b6732d61fa766de5af32dd57fcd43c508576bcb7f594b1f413b17452532fa4e7ee94b46d1c90427bb90e3cff1425ae39c05d46c38f371e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
�
|
1
|
+
&=V��߀��\�c�~ʻ�!_mAzߪϣRQ��!�bN�{8{Q�%����(���|�授2v
|
2
|
+
���ZP������*��an����Nj��L�U
|
3
|
+
���Y��QN\m5fm0��iw�����Ⱦ����a��Njg�G-=�Q�K=�.�W -r��`���aX��7>�z�wK~P.=i*��@A�E_���yoõ�
|
4
|
+
\�$W�P���O�q����G�hމ�p�E��pn��v f�m.�/|��
|
5
|
+
��)|���f*��>�`k��"~v�u��e �x�]EFC��B({*�w��Q,rE�*Kg�w3�Ft�p���'���?���'f��<�!�PZՃO"
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ And the partial:
|
|
34
34
|
|
35
35
|
* Notice you can use ERB and partials inside the template.
|
36
36
|
|
37
|
-
Your `user_mailer.rb` might look like this
|
37
|
+
Your `user_mailer.rb` might look like this:
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
# ./app/mailers/user_mailer.rb
|
@@ -48,6 +48,10 @@ class UserMailer < ActionMailer::Base
|
|
48
48
|
end
|
49
49
|
```
|
50
50
|
|
51
|
+
## Example application
|
52
|
+
|
53
|
+
* [MJML with Rails 6](https://github.com/dyanagi/example_mjml_rails): Renders HTML emails with MJML layout, view, and partial.
|
54
|
+
|
51
55
|
## Installation
|
52
56
|
|
53
57
|
Add it to your Gemfile.
|
@@ -62,13 +66,19 @@ Run the following command to install it:
|
|
62
66
|
bundle install
|
63
67
|
```
|
64
68
|
|
65
|
-
|
69
|
+
Add the MJML parser to your project with your favourite package manager:
|
66
70
|
|
67
71
|
```console
|
68
|
-
|
72
|
+
# with npm
|
73
|
+
npm install mjml
|
74
|
+
|
75
|
+
# with yarn
|
76
|
+
yarn add mjml
|
69
77
|
```
|
70
78
|
|
71
|
-
|
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.
|
72
82
|
|
73
83
|
If you're using ```:haml``` or any other Rails template language, create an initializer to set it up:
|
74
84
|
|
@@ -85,8 +95,10 @@ If there are configurations you'd like change:
|
|
85
95
|
- render errors: defaults to `true` (errors raised)
|
86
96
|
- minify: defaults to `false` (not minified)
|
87
97
|
- beautify: defaults to `true` (beautified)
|
98
|
+
- validation_level: defaults to `soft` (MJML syntax validation)
|
88
99
|
|
89
100
|
```ruby
|
101
|
+
# config/initializers/mjml.rb
|
90
102
|
Mjml.setup do |config|
|
91
103
|
# set to `false` to ignore errors silently
|
92
104
|
config.raise_render_exception = true
|
@@ -94,14 +106,16 @@ Mjml.setup do |config|
|
|
94
106
|
# optimize the size of your email
|
95
107
|
config.beautify = false
|
96
108
|
config.minify = true
|
109
|
+
config.validation_level = "strict"
|
97
110
|
end
|
98
111
|
```
|
99
112
|
|
100
113
|
If you’d like to specify a different MJML binary to run other than `4.`:
|
101
114
|
|
102
115
|
```ruby
|
116
|
+
# config/initializers/mjml.rb
|
103
117
|
Mjml.setup do |config|
|
104
|
-
config.mjml_binary_version_supported =
|
118
|
+
config.mjml_binary_version_supported = "3.3.5"
|
105
119
|
end
|
106
120
|
# If you set a different MJML binary version, you need to re-discover the binary
|
107
121
|
Mjml::BIN = Mjml.discover_mjml_bin
|
@@ -151,12 +165,14 @@ class MyMailer < ActionMailer::Base
|
|
151
165
|
@recipient = user
|
152
166
|
|
153
167
|
mail(to: user.email, from: "app@example.com") do |format|
|
154
|
-
format.html
|
168
|
+
format.html # This will look for "default.html.erb" and then "default.html.mjml"
|
155
169
|
end
|
156
170
|
end
|
157
171
|
end
|
158
172
|
```
|
159
173
|
|
174
|
+
Note: If `default.html.erb` exists, email will be rendered as ERB, and MJML tags will not be compiled.
|
175
|
+
|
160
176
|
Email layout:
|
161
177
|
```html
|
162
178
|
<!-- views/layouts/default.html.mjml -->
|
@@ -169,7 +185,7 @@ Email layout:
|
|
169
185
|
|
170
186
|
Email view:
|
171
187
|
```html
|
172
|
-
<!-- views/my_mailer/foo_bar.html.erb -->
|
188
|
+
<!-- views/my_mailer/foo_bar.html.mjml (or foo_bar.html.erb) -->
|
173
189
|
<%= render partial: "to" %>
|
174
190
|
|
175
191
|
<mj-section>
|
@@ -183,7 +199,7 @@ Email view:
|
|
183
199
|
|
184
200
|
Email partial:
|
185
201
|
```html
|
186
|
-
<!-- views/my_mailer/_to.html.erb -->
|
202
|
+
<!-- views/my_mailer/_to.html.mjml (or _to.html.erb) -->
|
187
203
|
<mj-section>
|
188
204
|
<mj-column>
|
189
205
|
<mj-text>
|
@@ -251,7 +267,7 @@ Next you'll need to setup a `package.json` file in the root, something like this
|
|
251
267
|
"test": "test"
|
252
268
|
},
|
253
269
|
"dependencies": {
|
254
|
-
"mjml": "^4.0.0"
|
270
|
+
"mjml": "^4.0.0"
|
255
271
|
},
|
256
272
|
"repository": {
|
257
273
|
"type": "git",
|
data/lib/mjml.rb
CHANGED
@@ -4,9 +4,10 @@ require "action_view/template"
|
|
4
4
|
require "mjml/mjmltemplate"
|
5
5
|
require "mjml/railtie"
|
6
6
|
require "rubygems"
|
7
|
+
require "open3"
|
7
8
|
|
8
9
|
module Mjml
|
9
|
-
mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string, :beautify, :minify
|
10
|
+
mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string, :beautify, :minify, :validation_level
|
10
11
|
|
11
12
|
@@template_language = :erb
|
12
13
|
@@raise_render_exception = true
|
@@ -14,27 +15,54 @@ module Mjml
|
|
14
15
|
@@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
|
15
16
|
@@beautify = true
|
16
17
|
@@minify = false
|
18
|
+
@@validation_level = "soft"
|
17
19
|
|
18
20
|
def self.check_version(bin)
|
19
|
-
|
20
|
-
|
21
|
+
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
22
|
+
status.success? && stdout.include?("mjml-core: #{Mjml.mjml_binary_version_supported}")
|
23
|
+
rescue StandardError
|
21
24
|
false
|
22
25
|
end
|
23
26
|
|
27
|
+
def self.run_mjml(args, mjml_bin: nil)
|
28
|
+
mjml_bin ||= BIN
|
29
|
+
|
30
|
+
Open3.capture3("#{mjml_bin} #{args}")
|
31
|
+
end
|
32
|
+
|
24
33
|
def self.discover_mjml_bin
|
25
|
-
# Check for
|
26
|
-
|
27
|
-
|
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)
|
39
|
+
end
|
40
|
+
|
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
|
28
47
|
|
29
|
-
# Check for a
|
30
|
-
|
31
|
-
mjml_bin
|
32
|
-
return mjml_bin if check_version(mjml_bin)
|
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)
|
33
51
|
|
34
52
|
puts Mjml.mjml_binary_error_string
|
35
53
|
nil
|
36
54
|
end
|
37
55
|
|
56
|
+
def self.bin_path_from(package_manager)
|
57
|
+
stdout, _, status = Open3.capture3("#{package_manager} bin")
|
58
|
+
|
59
|
+
return unless status.success?
|
60
|
+
|
61
|
+
stdout.chomp
|
62
|
+
rescue Errno::ENOENT # package manager is not installed
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
38
66
|
BIN = discover_mjml_bin
|
39
67
|
|
40
68
|
class Handler
|
data/lib/mjml/parser.rb
CHANGED
@@ -22,7 +22,7 @@ module Mjml
|
|
22
22
|
file.write(input)
|
23
23
|
file # return tempfile from block so #unlink works later
|
24
24
|
end
|
25
|
-
run(in_tmp_file.path, Mjml.beautify, Mjml.minify)
|
25
|
+
run(in_tmp_file.path, Mjml.beautify, Mjml.minify, Mjml.validation_level)
|
26
26
|
rescue
|
27
27
|
raise if Mjml.raise_render_exception
|
28
28
|
""
|
@@ -33,11 +33,11 @@ module Mjml
|
|
33
33
|
# Exec mjml command
|
34
34
|
#
|
35
35
|
# @return [String] The result as string
|
36
|
-
def run(in_tmp_file, beautify=true, minify=false)
|
36
|
+
def run(in_tmp_file, beautify=true, minify=false, validation_level="soft")
|
37
37
|
Tempfile.create(["out", ".html"]) do |out_tmp_file|
|
38
|
-
command = "
|
39
|
-
_,
|
40
|
-
raise ParseError.new(stderr.
|
38
|
+
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?
|
41
41
|
out_tmp_file.read
|
42
42
|
end
|
43
43
|
end
|
data/lib/mjml/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -21,7 +21,8 @@ describe Mjml::Parser do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'raises exception' do
|
24
|
-
|
24
|
+
err = expect { parser.render }.must_raise(custom_error_class)
|
25
|
+
expect(err.message).must_equal error.message
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -33,38 +34,43 @@ describe Mjml::Parser do
|
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'returns empty string' do
|
36
|
-
parser.render.must_equal ''
|
37
|
+
expect(parser.render).must_equal ''
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
describe 'can read beautify and
|
42
|
+
describe 'can read beautify, minify, and validation_level configs' do
|
42
43
|
it 'use defaults if no config is set' do
|
43
|
-
expect(Mjml.beautify).
|
44
|
-
expect(Mjml.minify).
|
44
|
+
expect(Mjml.beautify).must_equal(true)
|
45
|
+
expect(Mjml.minify).must_equal(false)
|
46
|
+
expect(Mjml.validation_level).must_equal('soft')
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'use setup config' do
|
48
50
|
Mjml.setup do |config|
|
49
51
|
config.beautify = false
|
50
52
|
config.minify = true
|
53
|
+
config.validation_level = 'strict'
|
51
54
|
end
|
52
55
|
|
53
|
-
expect(Mjml.beautify).
|
54
|
-
expect(Mjml.minify).
|
56
|
+
expect(Mjml.beautify).must_equal(false)
|
57
|
+
expect(Mjml.minify).must_equal(true)
|
58
|
+
expect(Mjml.validation_level).must_equal('strict')
|
59
|
+
|
60
|
+
Mjml.setup do |config|
|
61
|
+
config.beautify = true
|
62
|
+
config.minify = false
|
63
|
+
config.validation_level = 'soft'
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
69
|
describe '#run' do
|
60
|
-
describe 'when shell command
|
61
|
-
let(:error) { 'shell error' }
|
62
|
-
let(:stderr) { mock('stderr', eof?: false, read: error) }
|
63
|
-
|
64
|
-
before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
|
65
|
-
|
70
|
+
describe 'when shell command failed' do
|
66
71
|
it 'raises exception' do
|
67
|
-
|
72
|
+
err = expect { parser.run "/tmp/non_existent_file.mjml" }.must_raise(Mjml::Parser::ParseError)
|
73
|
+
expect(err.message).must_include 'Command line error'
|
68
74
|
end
|
69
75
|
end
|
70
76
|
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.4.2
|
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
|
+
MIIEKDCCApCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAfMR0wGwYDVQQDDBR5b3V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m7w02B02OGugXNzwbetG56gogFy
|
30
|
+
aJ4VJ95aiPEwDmGORLg7RmZcL/07ikDfb96ebPn3v2REYN2lWrqu4fT1MdTmA+hZ
|
31
|
+
vhfqJeSuWM5wNsWxA66SgbQe8BMHcsqV1CTG+Ir8FIAHzfa+c7CNke/28htRKYJV
|
32
|
+
6+lk55Ueov5TjjgLTUvjdqbAEtyCZpgxe2e0o3xqKh5d5YjWVQ4mSNvBsqK7UXOx
|
33
|
+
MGsePVBV9lnSFEJkGB3iOvavQSVUvqybF+yk6DrJR9iZtKCvAqd96PjkcFoM19dG
|
34
|
+
5ofv88TRZwXM9lWn4UKuekSSF1ElH3UBVDbH4zEHaOzrOvgfnZw3VteDigwfmmwF
|
35
|
+
lsAqKbu4nrHhtGhkwdYbflf2URJTUxXGptrnPYV7okmEg4rsykK3RAsZ6kMNdKmx
|
36
|
+
DcQ7RSt1TU5eck6c
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2020-11-27 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description: Render MJML + ERb template views in Rails
|
41
41
|
email: sighmon@sighmon.com
|
@@ -78,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
|
82
|
-
|
83
|
-
signing_key:
|
81
|
+
rubygems_version: 3.1.4
|
82
|
+
signing_key:
|
84
83
|
specification_version: 4
|
85
84
|
summary: MJML + ERb templates
|
86
85
|
test_files:
|
metadata.gz.sig
CHANGED
Binary file
|