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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43e20e43c1008a376c9f8bc2f2656223d1b81a48
4
- data.tar.gz: '0912c1df5e3e95760e823d836a54ea7c130a3966'
3
+ metadata.gz: bf24f6bc544ed49f738f3afb6dd288be522a8eac
4
+ data.tar.gz: 0e4f7e9b607039a2619c12f34202e3c63be9ec91
5
5
  SHA512:
6
- metadata.gz: 3fd8af4d8a513fa306a6ee49da43f5c4b4b5c8b23a7e7b816057a3180f104e916a638c5d9e3532ae957de8d84c2475be5b5abb7386850d62b7f18316bb4e81ce
7
- data.tar.gz: 7b0e44992a87b75ab1a33e9ce3fc35246d92fb81e406da5496e46a93f616214d5404a16c7ada7f5f7b48edbf930beae8d06358b793377cab8018e24f4b77cec5
6
+ metadata.gz: 169a7f232e534cbcb29a660ea166b0b7c54eee8f2c327b611131996ae9747f2a6c2617be96d02b62bb8d7e5181c5307f50c7bc933015c02eb8d343822bb53e7c
7
+ data.tar.gz: 7e679743fb0053909d30237d31ca300258b4114679eb39cf107b778f2477b272d077cfb65e3b8ff77ff6797a27f2bfa8499e87c873abc8b3e5c3c5d20d1d3467
@@ -1,2 +1 @@
1
- s����uaR���U�/ٸ�+"D��%'z�d����Q��)'[��>��4 ��+�A&���Z>�����*k�Ɵ.@Brٳ���-}e��
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���2xR#�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-container>
17
- <mj-section>
18
- <mj-column>
19
- <mj-text>Hello World</mj-text>
20
- <%= render :partial => 'info', :formats => [:html] %>
21
- </mj-column>
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
- <mj-container>
155
- <%= yield %>
156
- </mj-container>
152
+ <%= yield %>
157
153
  </mj-body>
158
154
  </mjml>
159
155
  ```
@@ -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.0."
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)
@@ -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
- file = File.open(in_tmp_file, 'w')
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
- result = run
22
- remove_tmp_files
23
- result
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
- command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file}"
34
- _, _, stderr, _ = Open3.popen3(command)
35
- raise ParseError.new(stderr.read.chomp) unless stderr.eof?
36
-
37
- file = File.open(out_tmp_file, 'r')
38
- str = file.read
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]
@@ -1,4 +1,4 @@
1
1
  module Mjml
2
2
  # Version number no longer matches MJML.io version
3
- VERSION = "4.0.3"
3
+ VERSION = "4.1.0"
4
4
  end
@@ -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
@@ -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-container><mj-section><mj-column></mj-column></mj-section></mj-container></mj-body></mjml>").strip
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.3
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-05-28 00:00:00.000000000 Z
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