mjml-rails 4.2.3 → 4.2.4
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.tar.gz.sig +0 -0
- data/README.md +21 -7
- data/lib/mjml.rb +3 -1
- data/lib/mjml/parser.rb +3 -3
- data/lib/mjml/version.rb +1 -1
- data/test/parser_test.rb +17 -0
- metadata +2 -2
- 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: c9eb1e8e21d779a8ae7196740fa0042a79f152260995977b38cf078cd5eea5f1
|
4
|
+
data.tar.gz: a7158c5b24476fb99808bdfef9b0d001a15801275e9ee9577758077f4c98c151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0a5b00f83612d1a49539140b94fb0de2490b3dacbe06c5c5256e3f2189866cfba9e3959cf41b2889b3e80eac43b0cf2134854a1dffde9f83ef3a3ecb9b2d1c5
|
7
|
+
data.tar.gz: b6dd71b988f199565ab11f77fc45d6d8cf598c614b88f5f1459b3d4494ad90391f4120b3578c047dc9b6120a8c520f32d51c5d64d600f666b04cb20bc7d64060
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -74,25 +74,39 @@ If you're using ```:haml``` or any other Rails template language, create an init
|
|
74
74
|
# config/initializers/mjml.rb
|
75
75
|
Mjml.setup do |config|
|
76
76
|
config.template_language = :erb # :erb (default), :slim, :haml, or any other you are using
|
77
|
-
# Default is `false` (errors suppressed), set to `true` to enable error raising
|
78
|
-
# config.raise_render_exception = true
|
79
|
-
# config.mjml_binary_version_supported = "4."
|
80
77
|
end
|
81
|
-
# If you set a different MJML binary version, uncomment next line
|
82
|
-
# Mjml::BIN = Mjml.discover_mjml_bin
|
83
78
|
```
|
84
79
|
|
85
80
|
**Note:** If you’re using Haml/Slim layouts, please don’t put `<mjml>` in comments in your partial. Read more: [#34](https://github.com/sighmon/mjml-rails/issues/34).
|
86
81
|
|
87
|
-
If you'd like
|
82
|
+
If there are configurations you'd like change:
|
83
|
+
- render errors: defaults to `false` (errors suppressed)
|
84
|
+
- minify: defaults to `false` (not minified)
|
85
|
+
- beautify: defaults to `true` (beautified)
|
88
86
|
|
89
87
|
```ruby
|
90
88
|
Mjml.setup do |config|
|
91
|
-
#
|
89
|
+
# set to `true` to enable error raising
|
92
90
|
config.raise_render_exception = true
|
91
|
+
|
92
|
+
# optimize the size of your email
|
93
|
+
config.beautify = false
|
94
|
+
config.minify = true
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
If you’d like to specify a different MJML binary to run other than `4.`:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Mjml.setup do |config|
|
102
|
+
config.mjml_binary_version_supported = “3.3.5”
|
93
103
|
end
|
104
|
+
# If you set a different MJML binary version, you need to re-discover the binary
|
105
|
+
Mjml::BIN = Mjml.discover_mjml_bin
|
94
106
|
```
|
95
107
|
|
108
|
+
**Note:** If you set a different MJML binary you’ll see warnings in your logs of `already initialized constant Mjml::BIN`. Read more: [#39](https://github.com/sighmon/mjml-rails/issues/39#issuecomment-429151908)
|
109
|
+
|
96
110
|
### MJML v3.x & v4.x support
|
97
111
|
|
98
112
|
Version 4.x of this gem brings support for MJML 4.x
|
data/lib/mjml.rb
CHANGED
@@ -5,12 +5,14 @@ require "mjml/railtie"
|
|
5
5
|
require "rubygems"
|
6
6
|
|
7
7
|
module Mjml
|
8
|
-
mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string
|
8
|
+
mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string, :beautify, :minify
|
9
9
|
|
10
10
|
@@template_language = :erb
|
11
11
|
@@raise_render_exception = false
|
12
12
|
@@mjml_binary_version_supported = "4."
|
13
13
|
@@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
|
14
|
+
@@beautify = true
|
15
|
+
@@minify = false
|
14
16
|
|
15
17
|
def self.check_version(bin)
|
16
18
|
IO.popen("#{bin} --version") { |io| io.read.include?("mjml-core: #{Mjml.mjml_binary_version_supported}") }
|
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
|
25
|
+
run(in_tmp_file.path, Mjml.beautify, Mjml.minify)
|
26
26
|
rescue
|
27
27
|
raise if Mjml.raise_render_exception
|
28
28
|
""
|
@@ -33,9 +33,9 @@ module Mjml
|
|
33
33
|
# Exec mjml command
|
34
34
|
#
|
35
35
|
# @return [String] The result as string
|
36
|
-
def run(in_tmp_file)
|
36
|
+
def run(in_tmp_file, beautify=true, minify=false)
|
37
37
|
Tempfile.create(["out", ".html"]) do |out_tmp_file|
|
38
|
-
command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file.path}"
|
38
|
+
command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify}"
|
39
39
|
_, _, stderr, _ = Open3.popen3(command)
|
40
40
|
raise ParseError.new(stderr.read.chomp) unless stderr.eof?
|
41
41
|
out_tmp_file.read
|
data/lib/mjml/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -37,6 +37,23 @@ describe Mjml::Parser do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
describe 'can read beautify and minify configs' do
|
42
|
+
it 'use defaults if no config is set' do
|
43
|
+
expect(Mjml.beautify).equal?(true);
|
44
|
+
expect(Mjml.minify).equal?(false);
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'use setup config' do
|
48
|
+
Mjml.setup do |config|
|
49
|
+
config.beautify = false
|
50
|
+
config.minify = true
|
51
|
+
end
|
52
|
+
|
53
|
+
expect(Mjml.beautify).equal?(false);
|
54
|
+
expect(Mjml.minify).equal?(true);
|
55
|
+
end
|
56
|
+
end
|
40
57
|
end
|
41
58
|
|
42
59
|
describe '#run' do
|
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.2.
|
4
|
+
version: 4.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
2QfUTBQZBmdkzXtFEAAJQVPa0X6iKxer4Na0dbjQciqf+5FrNBrct94To8eEEgqJ
|
36
36
|
Yz5YuMu9yoVoBwOVkHs0NmbAKSv041eBwfQpzmm+reA=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2018-10-
|
38
|
+
date: 2018-10-13 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description: Render MJML + ERb template views in Rails
|
41
41
|
email: sighmon@sighmon.com
|
metadata.gz.sig
CHANGED
Binary file
|