mjml-rails 4.10.0 → 4.11.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/README.md +8 -0
- data/lib/mjml/parser.rb +15 -7
- data/lib/mjml/version.rb +1 -1
- data/lib/mjml.rb +11 -1
- data/test/mjml_test.rb +16 -0
- data/test/parser_test.rb +5 -1
- data.tar.gz.sig +0 -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: 37fc78307ca3c1e85b631b150aed387a37db392786125cea2336d9696cd9669f
|
4
|
+
data.tar.gz: 98c17ccd57b004df6d0a03bdeae92de3e4de73f2242335f0f85f84ce006918f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357492e9fd6db87e71e4151f36b55b24407e40c6d91462bd2d471c2bd084d3fdca096f4413b02754f7292522f7f8529b6ea202bdef150c6777d5a35d26960da1
|
7
|
+
data.tar.gz: 1ccac9f8f3270d7eb1746e711583b73feb1ae0a97f2bf092d5826cfc4f6eb2f5d3d61d371ab6f7aa6d98726fb3035c4650c57a25c2ea1bb2418dcc2e30a40462
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -151,6 +151,11 @@ MJML-Rails has the following settings with defaults:
|
|
151
151
|
|
152
152
|
- `use_mrml: false`
|
153
153
|
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
|
+
|
155
|
+
- `fonts`
|
156
|
+
By default, MJML-Rails uses MJML default fonts, but enables you to override it.
|
157
|
+
Example : `config.fonts = { Raleway: 'https://fonts.googleapis.com/css?family=Raleway }`
|
158
|
+
|
154
159
|
|
155
160
|
```ruby
|
156
161
|
# config/initializers/mjml.rb
|
@@ -174,6 +179,9 @@ Mjml.setup do |config|
|
|
174
179
|
# Use custom MJML binary with custom version
|
175
180
|
config.mjml_binary = "/path/to/custom/mjml"
|
176
181
|
config.mjml_binary_version_supported = "3.3.5"
|
182
|
+
|
183
|
+
# Use default system fonts instead of google fonts
|
184
|
+
config.fonts = {}
|
177
185
|
end
|
178
186
|
```
|
179
187
|
|
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)
|
@@ -48,7 +50,8 @@ module Mjml
|
|
48
50
|
check_for_custom_mjml_binary ||
|
49
51
|
check_for_yarn_mjml_binary ||
|
50
52
|
check_for_npm_mjml_binary ||
|
51
|
-
check_for_global_mjml_binary
|
53
|
+
check_for_global_mjml_binary ||
|
54
|
+
check_for_mrml_binary
|
52
55
|
|
53
56
|
return @@valid_mjml_binary if @@valid_mjml_binary
|
54
57
|
|
@@ -102,6 +105,13 @@ module Mjml
|
|
102
105
|
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
|
103
106
|
end
|
104
107
|
|
108
|
+
def self.check_for_mrml_binary
|
109
|
+
MRML.present?
|
110
|
+
rescue NameError
|
111
|
+
Mjml.mjml_binary_error_string = 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
105
115
|
def self.discover_mjml_bin
|
106
116
|
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
|
107
117
|
'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
|
data/test/mjml_test.rb
CHANGED
@@ -119,11 +119,13 @@ describe Mjml do
|
|
119
119
|
before do
|
120
120
|
Mjml.mjml_binary = nil
|
121
121
|
Mjml.valid_mjml_binary = nil
|
122
|
+
Mjml.use_mrml = nil
|
122
123
|
end
|
123
124
|
|
124
125
|
after do
|
125
126
|
Mjml.mjml_binary = nil
|
126
127
|
Mjml.valid_mjml_binary = nil
|
128
|
+
Mjml.use_mrml = nil
|
127
129
|
end
|
128
130
|
|
129
131
|
it 'can be set to a custom value with mjml_binary if version is correct' do
|
@@ -156,5 +158,19 @@ describe Mjml do
|
|
156
158
|
assert(err.message.start_with?("MJML.mjml_binary is set to 'set by mjml_binary' " \
|
157
159
|
'but MJML-Rails could not validate that it is a valid MJML binary'))
|
158
160
|
end
|
161
|
+
|
162
|
+
it 'can use MRML and check for a valid binary' do
|
163
|
+
Mjml.use_mrml = true
|
164
|
+
Mjml.stubs(:check_for_custom_mjml_binary).returns(false)
|
165
|
+
Mjml.stubs(:check_for_yarn_mjml_binary).returns(false)
|
166
|
+
Mjml.stubs(:check_for_npm_mjml_binary).returns(false)
|
167
|
+
Mjml.stubs(:check_for_global_mjml_binary).returns(false)
|
168
|
+
expect(Mjml.valid_mjml_binary).must_equal(true)
|
169
|
+
|
170
|
+
Mjml.valid_mjml_binary = nil
|
171
|
+
MRML.stubs(:present?).raises(NameError)
|
172
|
+
assert_nil(Mjml.valid_mjml_binary)
|
173
|
+
expect(Mjml.mjml_binary_error_string).must_equal 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
|
174
|
+
end
|
159
175
|
end
|
160
176
|
end
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
RhdbGYd5Hku1QRVeQ+tN2OYG1/vZeRTqZ4MGLdl6r4iO5XGtWWoR2alg8kKc6yLx
|
37
37
|
P5J+9tLKId50fAv4voQg//wRwePPNiWIXsLUa1LPYWTAznKTvi3dAQ==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2024-
|
39
|
+
date: 2024-04-06 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.
|
195
|
+
rubygems_version: 3.5.3
|
196
196
|
signing_key:
|
197
197
|
specification_version: 4
|
198
198
|
summary: MJML + ERb templates
|
metadata.gz.sig
CHANGED
Binary file
|