mjml-rails 4.10.1 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 321f6e1eaed15dffa0b3c65283a095a92ac80cae3b3d3df4f395d446fbc4e490
4
- data.tar.gz: 96cce85167d65a6c20cc62ad3d5690ed7e4c166af37311190a0729f33b6a315d
3
+ metadata.gz: 37fc78307ca3c1e85b631b150aed387a37db392786125cea2336d9696cd9669f
4
+ data.tar.gz: 98c17ccd57b004df6d0a03bdeae92de3e4de73f2242335f0f85f84ce006918f2
5
5
  SHA512:
6
- metadata.gz: fc6708c231290dea0a14a04c03d977f58dd34c5d64116c7aba01601191ebbda08642cf0039bc2ab060b7174a5e8f5fa728dae2da14bceeaa3351f8bb4073b721
7
- data.tar.gz: 6f32e5c076fac3d45c69c2e8dfcc6880ef8d73dbf32e1c87dfb51442f466b90917d9591c08fa5bbfd7f748845d2672b35befa3ea8210c6edec104f56398dd5b5
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, Mjml.beautify, Mjml.minify, Mjml.validation_level)
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
- # rubocop:disable Style/OptionalBooleanParameter: Fixing this offense would imply a change in the public API.
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
- command = "-r #{in_tmp_file} -o #{out_tmp_file.path} " \
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
- # rubocop:enable Style/OptionalBooleanParameter
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mjml
4
4
  # Version number no longer matches MJML.io version
5
- VERSION = '4.10.1'
5
+ VERSION = '4.11.0'
6
6
  end
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)
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.10.1
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-02-01 00:00:00.000000000 Z
39
+ date: 2024-04-06 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
metadata.gz.sig CHANGED
Binary file