mjml-rails 4.0.2 → 4.0.3
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 +5 -0
- data/lib/mjml.rb +5 -3
- data/lib/mjml/parser.rb +7 -3
- data/lib/mjml/version.rb +1 -1
- data/test/parser_test.rb +13 -0
- 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: 43e20e43c1008a376c9f8bc2f2656223d1b81a48
|
4
|
+
data.tar.gz: '0912c1df5e3e95760e823d836a54ea7c130a3966'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fd8af4d8a513fa306a6ee49da43f5c4b4b5c8b23a7e7b816057a3180f104e916a638c5d9e3532ae957de8d84c2475be5b5abb7386850d62b7f18316bb4e81ce
|
7
|
+
data.tar.gz: 7b0e44992a87b75ab1a33e9ce3fc35246d92fb81e406da5496e46a93f616214d5404a16c7ada7f5f7b48edbf930beae8d06358b793377cab8018e24f4b77cec5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -273,6 +273,11 @@ If you discover any bugs, feel free to create an issue on GitHub. Please add as
|
|
273
273
|
* Simon Loffler [github.com/sighmon](https://github.com/sighmon)
|
274
274
|
* Steven Pickles [github.com/thatpixguy](https://github.com/thatpixguy)
|
275
275
|
|
276
|
+
## Other similar gems
|
277
|
+
|
278
|
+
* [srghma/mjml-premailer](https://github.com/srghma/mjml-premailer) - supports `/app/views/layouts`
|
279
|
+
* [kolybasov/mjml-ruby/](https://github.com/kolybasov/mjml-ruby/)
|
280
|
+
|
276
281
|
## License
|
277
282
|
|
278
283
|
MIT License. Copyright 2016 Simon Loffler. [sighmon.com](http://sighmon.com)
|
data/lib/mjml.rb
CHANGED
@@ -5,13 +5,15 @@ require "mjml/railtie"
|
|
5
5
|
require "rubygems"
|
6
6
|
|
7
7
|
module Mjml
|
8
|
-
mattr_accessor :template_language, :raise_render_exception
|
8
|
+
mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string
|
9
9
|
|
10
10
|
@@template_language = :erb
|
11
11
|
@@raise_render_exception = false
|
12
|
+
@@mjml_binary_version_supported = "4.0."
|
13
|
+
@@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
|
12
14
|
|
13
15
|
def self.check_version(bin)
|
14
|
-
IO.popen("#{bin} --version") { |io| io.read.include?(
|
16
|
+
IO.popen("#{bin} --version") { |io| io.read.include?("mjml-core: #{Mjml.mjml_binary_version_supported}") }
|
15
17
|
rescue
|
16
18
|
false
|
17
19
|
end
|
@@ -26,7 +28,7 @@ module Mjml
|
|
26
28
|
mjml_bin = File.join(installer_path, 'mjml')
|
27
29
|
return mjml_bin if check_version(mjml_bin)
|
28
30
|
|
29
|
-
puts
|
31
|
+
puts Mjml.mjml_binary_error_string
|
30
32
|
nil
|
31
33
|
end
|
32
34
|
|
data/lib/mjml/parser.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Mjml
|
2
4
|
class Parser
|
5
|
+
class ParseError < StandardError; end
|
3
6
|
|
4
7
|
# Create new parser
|
5
8
|
#
|
6
9
|
# @param input [String] The string to transform in html
|
7
10
|
def initialize input
|
8
|
-
raise
|
11
|
+
raise Mjml.mjml_binary_error_string unless mjml_bin
|
9
12
|
file = File.open(in_tmp_file, 'w')
|
10
13
|
file.write(input)
|
11
14
|
file.close
|
@@ -28,8 +31,9 @@ module Mjml
|
|
28
31
|
# @return [String] The result as string
|
29
32
|
def run
|
30
33
|
command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file}"
|
31
|
-
|
32
|
-
|
34
|
+
_, _, stderr, _ = Open3.popen3(command)
|
35
|
+
raise ParseError.new(stderr.read.chomp) unless stderr.eof?
|
36
|
+
|
33
37
|
file = File.open(out_tmp_file, 'r')
|
34
38
|
str = file.read
|
35
39
|
file.close
|
data/lib/mjml/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -38,4 +38,17 @@ describe Mjml::Parser do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe '#run' do
|
43
|
+
describe 'when shell command is failed' do
|
44
|
+
let(:error) { 'shell error' }
|
45
|
+
let(:stderr) { mock('stderr', eof?: false, read: error) }
|
46
|
+
|
47
|
+
before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
|
48
|
+
|
49
|
+
it 'raises exception' do
|
50
|
+
-> { parser.run }.must_raise(Mjml::Parser::ParseError, error)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
41
54
|
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.0.3
|
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-05-28 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
|