mjml-rails 4.10.1 → 4.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +12 -1
- data/lib/mjml/parser.rb +15 -7
- data/lib/mjml/version.rb +1 -1
- data/lib/mjml.rb +12 -18
- data/test/mjml_test.rb +1 -2
- data/test/parser_test.rb +5 -1
- data.tar.gz.sig +0 -0
- metadata +24 -24
- 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: 2b6b7aed097a59ac30303aaf45d11b7f736e521d80f861b93fbf1886be6a15a0
|
4
|
+
data.tar.gz: 3d894ce65b6ba9c6f5818acfaf4d34dd57a85b29ed4a071870ff2c4cdc65c9ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3dd354857e11c5a8864365a1e19c591eaec48a1349d3f675522f6835e5c830d9dd0328957866cbb5e085f1fab6679dec1588f8233841a33626469e9d5eb17a1
|
7
|
+
data.tar.gz: be4f6c9bf8192a20bba52cf2f196e33e96b9d6d7546efccb5c7efec9fb8295fd8caebff39f4131b4e9444dfc254b9c8814e039e529c43bb18fe7714ff0e2acd2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -79,6 +79,9 @@ npm install -g mjml
|
|
79
79
|
|
80
80
|
# with yarn
|
81
81
|
yarn add mjml
|
82
|
+
|
83
|
+
# with bun
|
84
|
+
bun add mjml
|
82
85
|
```
|
83
86
|
|
84
87
|
MJML-Rails falls back to a global installation of MJML but it is strongly recommended to add MJML directly to your project.
|
@@ -152,6 +155,11 @@ MJML-Rails has the following settings with defaults:
|
|
152
155
|
- `use_mrml: false`
|
153
156
|
Enabling this will allow you to use Rust implementation of MJML via the `mrml` gem. It comes with prebuilt binaries instead of having to install MJML along with Node. When enabled the options `mjml_binary_version_supported`, `mjml_binary`, `minify`, `beautify` and `validation_level` are ignored.
|
154
157
|
|
158
|
+
- `fonts`
|
159
|
+
By default, MJML-Rails uses MJML default fonts, but enables you to override it.
|
160
|
+
Example : `config.fonts = { Raleway: 'https://fonts.googleapis.com/css?family=Raleway }`
|
161
|
+
|
162
|
+
|
155
163
|
```ruby
|
156
164
|
# config/initializers/mjml.rb
|
157
165
|
Mjml.setup do |config|
|
@@ -174,6 +182,9 @@ Mjml.setup do |config|
|
|
174
182
|
# Use custom MJML binary with custom version
|
175
183
|
config.mjml_binary = "/path/to/custom/mjml"
|
176
184
|
config.mjml_binary_version_supported = "3.3.5"
|
185
|
+
|
186
|
+
# Use default system fonts instead of google fonts
|
187
|
+
config.fonts = {}
|
177
188
|
end
|
178
189
|
```
|
179
190
|
|
@@ -203,7 +214,7 @@ npm install -g mjml@3.3.5
|
|
203
214
|
|
204
215
|
### How to guides
|
205
216
|
|
206
|
-
[
|
217
|
+
[Kitty Giraudel](https://twitter.com/KittyGiraudel) wrote a post on [using MJML in Rails](http://dev.edenspiekermann.com/2016/06/02/using-mjml-in-rails/).
|
207
218
|
|
208
219
|
## Using Email Layouts
|
209
220
|
|
data/lib/mjml/parser.rb
CHANGED
@@ -23,7 +23,7 @@ module Mjml
|
|
23
23
|
file.write(input)
|
24
24
|
file # return tempfile from block so #unlink works later
|
25
25
|
end
|
26
|
-
run(in_tmp_file.path
|
26
|
+
run(in_tmp_file.path)
|
27
27
|
rescue StandardError
|
28
28
|
raise if Mjml.raise_render_exception
|
29
29
|
|
@@ -35,12 +35,9 @@ module Mjml
|
|
35
35
|
# Exec mjml command
|
36
36
|
#
|
37
37
|
# @return [String] The result as string
|
38
|
-
|
39
|
-
def run(in_tmp_file, beautify = true, minify = false, validation_level = 'strict')
|
38
|
+
def run(in_tmp_file)
|
40
39
|
Tempfile.create(['out', '.html']) do |out_tmp_file|
|
41
|
-
|
42
|
-
"--config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
|
43
|
-
_, stderr, status = Mjml.run_mjml(command)
|
40
|
+
_, stderr, status = Mjml.run_mjml(build_command(in_tmp_file, out_tmp_file))
|
44
41
|
|
45
42
|
unless status.success?
|
46
43
|
# The process status ist quite helpful in case of dying processes without STDERR output.
|
@@ -52,6 +49,17 @@ module Mjml
|
|
52
49
|
out_tmp_file.read
|
53
50
|
end
|
54
51
|
end
|
55
|
-
|
52
|
+
|
53
|
+
# Build command string from config variables
|
54
|
+
#
|
55
|
+
# @return [String] Command string
|
56
|
+
def build_command(in_file, out_file)
|
57
|
+
command = "-r #{in_file} -o #{out_file.path} " \
|
58
|
+
"--config.beautify #{Mjml.beautify} " \
|
59
|
+
"--config.minify #{Mjml.minify} " \
|
60
|
+
"--config.validationLevel #{Mjml.validation_level}"
|
61
|
+
command += " --config.fonts '#{Mjml.fonts.to_json}'" unless Mjml.fonts.nil?
|
62
|
+
command
|
63
|
+
end
|
56
64
|
end
|
57
65
|
end
|
data/lib/mjml/version.rb
CHANGED
data/lib/mjml.rb
CHANGED
@@ -12,6 +12,7 @@ module Mjml
|
|
12
12
|
mattr_accessor \
|
13
13
|
:beautify,
|
14
14
|
:minify,
|
15
|
+
:fonts,
|
15
16
|
:mjml_binary,
|
16
17
|
:mjml_binary_error_string,
|
17
18
|
:mjml_binary_version_supported,
|
@@ -31,6 +32,7 @@ module Mjml
|
|
31
32
|
self.minify = false
|
32
33
|
self.validation_level = 'strict'
|
33
34
|
self.use_mrml = false
|
35
|
+
self.fonts = nil
|
34
36
|
|
35
37
|
def self.check_version(bin)
|
36
38
|
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
@@ -46,8 +48,7 @@ module Mjml
|
|
46
48
|
def self.valid_mjml_binary
|
47
49
|
self.valid_mjml_binary = @@valid_mjml_binary ||
|
48
50
|
check_for_custom_mjml_binary ||
|
49
|
-
|
50
|
-
check_for_npm_mjml_binary ||
|
51
|
+
check_for_package_mjml_binary ||
|
51
52
|
check_for_global_mjml_binary ||
|
52
53
|
check_for_mrml_binary
|
53
54
|
|
@@ -72,30 +73,23 @@ module Mjml
|
|
72
73
|
'it is a valid MJML binary. Please check your configuration.'
|
73
74
|
end
|
74
75
|
|
75
|
-
def self.
|
76
|
-
|
77
|
-
return if
|
76
|
+
def self.check_for_mjml_package(package_manager, bin_command, binary_path)
|
77
|
+
pm_bin = `which #{package_manager}`.chomp
|
78
|
+
return if pm_bin.blank?
|
78
79
|
|
79
|
-
stdout, _, status = Open3.capture3("#{
|
80
|
+
stdout, _, status = Open3.capture3("#{pm_bin} #{bin_command}")
|
80
81
|
return unless status.success?
|
81
82
|
|
82
|
-
mjml_bin = stdout.chomp
|
83
|
+
mjml_bin = File.join(stdout.chomp, *binary_path)
|
83
84
|
return mjml_bin if check_version(mjml_bin)
|
84
85
|
rescue Errno::ENOENT # package manager is not installed
|
85
86
|
nil
|
86
87
|
end
|
87
88
|
|
88
|
-
def self.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
stdout, _, status = Open3.capture3("#{npm_bin} root")
|
93
|
-
return unless status.success?
|
94
|
-
|
95
|
-
mjml_bin = File.join(stdout.chomp, '.bin', 'mjml')
|
96
|
-
return mjml_bin if check_version(mjml_bin)
|
97
|
-
rescue Errno::ENOENT # package manager is not installed
|
98
|
-
nil
|
89
|
+
def self.check_for_package_mjml_binary
|
90
|
+
check_for_mjml_package('bun', 'pm bin', ['mjml']) ||
|
91
|
+
check_for_mjml_package('npm', 'root', ['.bin', 'mjml']) ||
|
92
|
+
check_for_mjml_package('yarn', 'bin mjml', [])
|
99
93
|
end
|
100
94
|
|
101
95
|
def self.check_for_global_mjml_binary
|
data/test/mjml_test.rb
CHANGED
@@ -162,8 +162,7 @@ describe Mjml do
|
|
162
162
|
it 'can use MRML and check for a valid binary' do
|
163
163
|
Mjml.use_mrml = true
|
164
164
|
Mjml.stubs(:check_for_custom_mjml_binary).returns(false)
|
165
|
-
Mjml.stubs(:
|
166
|
-
Mjml.stubs(:check_for_npm_mjml_binary).returns(false)
|
165
|
+
Mjml.stubs(:check_for_package_mjml_binary).returns(false)
|
167
166
|
Mjml.stubs(:check_for_global_mjml_binary).returns(false)
|
168
167
|
expect(Mjml.valid_mjml_binary).must_equal(true)
|
169
168
|
|
data/test/parser_test.rb
CHANGED
@@ -37,11 +37,12 @@ describe Mjml::Parser do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe 'can read beautify, minify, and validation_level configs' do
|
40
|
+
describe 'can read beautify, minify, fonts and validation_level configs' do
|
41
41
|
it 'uses defaults if no config is set' do
|
42
42
|
expect(Mjml.beautify).must_equal(true)
|
43
43
|
expect(Mjml.minify).must_equal(false)
|
44
44
|
expect(Mjml.validation_level).must_equal('strict')
|
45
|
+
expect(Mjml.fonts).must_equal(nil)
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'uses setup config' do
|
@@ -49,16 +50,19 @@ describe Mjml::Parser do
|
|
49
50
|
config.beautify = false
|
50
51
|
config.minify = true
|
51
52
|
config.validation_level = 'soft'
|
53
|
+
config.fonts = { Mononoki: 'https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/mononoki.min.css' }
|
52
54
|
end
|
53
55
|
|
54
56
|
expect(Mjml.beautify).must_equal(false)
|
55
57
|
expect(Mjml.minify).must_equal(true)
|
56
58
|
expect(Mjml.validation_level).must_equal('soft')
|
59
|
+
expect(Mjml.fonts).must_equal({ Mononoki: 'https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/mononoki.min.css' })
|
57
60
|
|
58
61
|
Mjml.setup do |config|
|
59
62
|
config.beautify = true
|
60
63
|
config.minify = false
|
61
64
|
config.validation_level = 'strict'
|
65
|
+
config.fonts = nil
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
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.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -13,30 +13,30 @@ cert_chain:
|
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
14
|
MIIEdDCCAtygAwIBAgIBATANBgkqhkiG9w0BAQsFADBAMRAwDgYDVQQDDAdzaWdo
|
15
15
|
bW9uMRcwFQYKCZImiZPyLGQBGRYHc2lnaG1vbjETMBEGCgmSJomT8ixkARkWA2Nv
|
16
|
-
|
16
|
+
bTAeFw0yNDA4MjQxMDM4MTNaFw0yNTA4MjQxMDM4MTNaMEAxEDAOBgNVBAMMB3Np
|
17
17
|
Z2htb24xFzAVBgoJkiaJk/IsZAEZFgdzaWdobW9uMRMwEQYKCZImiZPyLGQBGRYD
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
18
|
+
Y29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAuEka244tMe80fy0y
|
19
|
+
YPZ8DXPWGV39QTdTmuTiz3sQ8bSP2ckTzmig/0eT8XKHzYQbkOB00auQX6mwYQpD
|
20
|
+
OphRHPhDcEnPdGRmSIObSXujAFD8tq3ZcVd2bGZ8w8aHHRn5wNDwezLFbTYIhtr2
|
21
|
+
xMdOsSSdcXtslyfxRrLM+am0uVnaGVYWruVGABx+sCTy4qPLzvbF5r+YToV2zl7G
|
22
|
+
y/ZD/YsYnqhrvHWcBt/5tdzvP340UXr3fqoDhfUMD3WrziQLspgYyV65lBA9MMNt
|
23
|
+
dNbXNJDk1nLt8UHuWN9r15GEdnFFs4XryrG0dmsvYAQ+JmVgFvVEFa5dFeTYhntB
|
24
|
+
/h6/1BUgbqtQBDi1e2T0fIi5BxoDd1Asp5OeulyiglDAaAVCIlGdXKGjMKKX1b2N
|
25
|
+
tHZj+9aj1US7cI/sGRsEenlMtoXTjew41x2UwXbHZssaOLsn/ubJr+HP3bLph9it
|
26
|
+
gD4VwPpzem66FPNH/uFfAF17H11961fbTvlPtxcVj39EFMH7AgMBAAGjeTB3MAkG
|
27
|
+
A1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBTo6MDHQYDOj+zwdyTsCljW
|
28
|
+
+zZwszAeBgNVHREEFzAVgRNzaWdobW9uQHNpZ2htb24uY29tMB4GA1UdEgQXMBWB
|
29
|
+
E3NpZ2htb25Ac2lnaG1vbi5jb20wDQYJKoZIhvcNAQELBQADggGBAAj8eUP4oTrt
|
30
|
+
Rnf7qJec8F2EA2mJLUz+PrGrM/eiP0jIVeGGrwfvn9hBtU+3IG6IPj16nb40T+/Q
|
31
|
+
iSNIYxOZHYxj2CZf2CKKIz5slESybSlfuX/3i6WgZ3GP9X+z5jZE43fA1zR9kWIN
|
32
|
+
xVl3McOoST+/UP+skagMdOl8S6qg8THdb9qTZLDT+XJVLNE8k7bcOiTKa6ef/hCR
|
33
|
+
A9C/1rxJJHehHewkQQPLJg5edufj2t+BVY0tnMT24TXVCS7qy9BjZ/f1hC+4jrUA
|
34
|
+
ezb/gRETp2GvGgoIrrZSiTiODKfIuhjifaxy1c+E/XfvN7gtO6awgTKHg+gt6y55
|
35
|
+
ECdz0FTGporEyMBWc+GqSpfIXKKlNUsWyEEo9J3mjDfED/1nP+bePK+B3wwc69sl
|
36
|
+
Qqk2dn/fFE9vdcl9OaOw2Zizne/1VFL/jkzXLqnLgbKD/q129mVCBgw2CKYnQfMN
|
37
|
+
4RwBjPyqnMxWnSq6Ycn7HdFEkgyf2cAxFfH5QtDsjEuca+/LAJMeAQ==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2024-
|
39
|
+
date: 2024-08-24 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: byebug
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
|
-
rubygems_version: 3.5.
|
195
|
+
rubygems_version: 3.5.11
|
196
196
|
signing_key:
|
197
197
|
specification_version: 4
|
198
198
|
summary: MJML + ERb templates
|
metadata.gz.sig
CHANGED
Binary file
|