mjml-rails 4.0.3 → 4.1.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 +1 -2
- data.tar.gz.sig +0 -0
- data/README.md +7 -11
- data/lib/mjml.rb +1 -1
- data/lib/mjml/parser.rb +17 -49
- data/lib/mjml/version.rb +1 -1
- data/test/parser_test.rb +1 -1
- data/test/template_test.rb +2 -2
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf24f6bc544ed49f738f3afb6dd288be522a8eac
|
4
|
+
data.tar.gz: 0e4f7e9b607039a2619c12f34202e3c63be9ec91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 169a7f232e534cbcb29a660ea166b0b7c54eee8f2c327b611131996ae9747f2a6c2617be96d02b62bb8d7e5181c5307f50c7bc933015c02eb8d343822bb53e7c
|
7
|
+
data.tar.gz: 7e679743fb0053909d30237d31ca300258b4114679eb39cf107b778f2477b272d077cfb65e3b8ff77ff6797a27f2bfa8499e87c873abc8b3e5c3c5d20d1d3467
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�\� ;OI�aǍ|,Qt����E���oJ:}7~'��r�r2Љ龉b��d5�����g���C���V�_���/jEp���6K�a�=:�/1dH�����@/%nF�G� ��grw�F���r�|��L�L
|
1
|
+
���y�l��ga�.���~p�v���2�xR#�t6����0<ۏi���_���;�����
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -13,14 +13,12 @@ An example template might look like:
|
|
13
13
|
<mj-preview>Hello World</mj-preview>
|
14
14
|
</mj-head>
|
15
15
|
<mj-body>
|
16
|
-
<mj-
|
17
|
-
<mj-
|
18
|
-
<mj-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
</mj-section>
|
23
|
-
</mj-container>
|
16
|
+
<mj-section>
|
17
|
+
<mj-column>
|
18
|
+
<mj-text>Hello World</mj-text>
|
19
|
+
<%= render :partial => 'info', :formats => [:html] %>
|
20
|
+
</mj-column>
|
21
|
+
</mj-section>
|
24
22
|
</mj-body>
|
25
23
|
</mjml>
|
26
24
|
```
|
@@ -151,9 +149,7 @@ Email layout:
|
|
151
149
|
<!-- views/layouts/default.mjml -->
|
152
150
|
<mjml>
|
153
151
|
<mj-body>
|
154
|
-
|
155
|
-
<%= yield %>
|
156
|
-
</mj-container>
|
152
|
+
<%= yield %>
|
157
153
|
</mj-body>
|
158
154
|
</mjml>
|
159
155
|
```
|
data/lib/mjml.rb
CHANGED
@@ -9,7 +9,7 @@ module Mjml
|
|
9
9
|
|
10
10
|
@@template_language = :erb
|
11
11
|
@@raise_render_exception = false
|
12
|
-
@@mjml_binary_version_supported = "4.
|
12
|
+
@@mjml_binary_version_supported = "4.1."
|
13
13
|
@@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
|
14
14
|
|
15
15
|
def self.check_version(bin)
|
data/lib/mjml/parser.rb
CHANGED
@@ -4,78 +4,46 @@ module Mjml
|
|
4
4
|
class Parser
|
5
5
|
class ParseError < StandardError; end
|
6
6
|
|
7
|
+
attr_reader :input
|
8
|
+
|
7
9
|
# Create new parser
|
8
10
|
#
|
9
11
|
# @param input [String] The string to transform in html
|
10
12
|
def initialize input
|
11
13
|
raise Mjml.mjml_binary_error_string unless mjml_bin
|
12
|
-
|
13
|
-
file.write(input)
|
14
|
-
file.close
|
14
|
+
@input = input
|
15
15
|
end
|
16
16
|
|
17
17
|
# Render mjml template
|
18
18
|
#
|
19
19
|
# @return [String]
|
20
20
|
def render
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
in_tmp_file = Tempfile.open(["in", ".mjml"]) do |file|
|
22
|
+
file.write(input)
|
23
|
+
file # return tempfile from block so #unlink works later
|
24
|
+
end
|
25
|
+
run in_tmp_file.path
|
24
26
|
rescue
|
25
27
|
raise if Mjml.raise_render_exception
|
26
28
|
""
|
29
|
+
ensure
|
30
|
+
in_tmp_file.unlink
|
27
31
|
end
|
28
32
|
|
29
33
|
# Exec mjml command
|
30
34
|
#
|
31
35
|
# @return [String] The result as string
|
32
|
-
def run
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
file.close
|
40
|
-
str
|
36
|
+
def run(in_tmp_file)
|
37
|
+
Tempfile.create(["out", ".html"]) do |out_tmp_file|
|
38
|
+
command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file.path}"
|
39
|
+
_, _, stderr, _ = Open3.popen3(command)
|
40
|
+
raise ParseError.new(stderr.read.chomp) unless stderr.eof?
|
41
|
+
out_tmp_file.read
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
44
46
|
|
45
|
-
# Remove tmp files
|
46
|
-
#
|
47
|
-
# @return nil
|
48
|
-
def remove_tmp_files
|
49
|
-
FileUtils.rm(in_tmp_file)
|
50
|
-
FileUtils.rm(out_tmp_file)
|
51
|
-
nil
|
52
|
-
end
|
53
|
-
|
54
|
-
# Return tmp dir
|
55
|
-
#
|
56
|
-
# @return [String]
|
57
|
-
def tmp_dir
|
58
|
-
"/tmp"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Get parser tpm file to store result
|
62
|
-
#
|
63
|
-
# @return [String]
|
64
|
-
def out_tmp_file
|
65
|
-
|
66
|
-
@_out_tmp_file ||= "#{tmp_dir}/out_#{(0...8).map { (65 + rand(26)).chr }.join}.html"
|
67
|
-
end
|
68
|
-
|
69
|
-
# Get parser tpm file to get result
|
70
|
-
#
|
71
|
-
# @return [String]
|
72
|
-
def in_tmp_file
|
73
|
-
|
74
|
-
@_in_tmp_file ||= "#{tmp_dir}/in_#{(0...8).map { (65 + rand(26)).chr }.join}.mjml"
|
75
|
-
# puts @_in_tmp_file
|
76
|
-
return @_in_tmp_file
|
77
|
-
end
|
78
|
-
|
79
47
|
# Get mjml bin path
|
80
48
|
#
|
81
49
|
# @return [String]
|
data/lib/mjml/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -47,7 +47,7 @@ describe Mjml::Parser do
|
|
47
47
|
before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
|
48
48
|
|
49
49
|
it 'raises exception' do
|
50
|
-
-> { parser.run }.must_raise(Mjml::Parser::ParseError, error)
|
50
|
+
-> { parser.run "/tmp/input_file.mjml" }.must_raise(Mjml::Parser::ParseError, error)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/test/template_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class MjmlTest < ActiveSupport::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
test 'with Mjmltemplate processor' do
|
6
|
-
assert_not_equal "<mj-body></mj-body>", Mjml::Mjmltemplate.to_html("<mjml><mj-body><mj-
|
6
|
+
assert_not_equal "<mj-body></mj-body>", Mjml::Mjmltemplate.to_html("<mjml><mj-body><mj-section><mj-column></mj-column></mj-section></mj-body></mjml>").strip
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
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.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
IUdCp7zF7QpeLz6cgerOpdG0NLHQOEPcWqHpt4yM++TieNrYOuJlkkSd11Ypvgsc
|
32
32
|
RRE0kJj2aO7haTBQ7uQl3cTv2c1s4bLu
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2018-
|
34
|
+
date: 2018-06-29 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description: Render MJML + ERb template views in Rails
|
37
37
|
email: sighmon@sighmon.com
|
metadata.gz.sig
CHANGED
Binary file
|