mjml-rails 4.6.1 → 4.7.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 +0 -0
- data/README.md +2 -2
- data/lib/generators/mjml/mailer/mailer_generator.rb +6 -4
- data/lib/mjml/handler.rb +15 -8
- data/lib/mjml/parser.rb +17 -9
- data/lib/mjml/railtie.rb +5 -3
- data/lib/mjml/version.rb +4 -2
- data/lib/mjml-rails.rb +5 -1
- data/lib/mjml.rb +29 -23
- data/test/generator_test.rb +16 -14
- data/test/mjml_test.rb +50 -45
- data/test/parser_test.rb +3 -1
- data/test/test_helper.rb +23 -22
- data.tar.gz.sig +0 -0
- metadata +126 -28
- 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: 7b9582e0d35041cd78aa95808af7d2808ce467eb1b70eb511b57f39679b661af
|
4
|
+
data.tar.gz: 402a1cf82168f58d8abde20ad280473e897eb0d0489d88281c72d52e830c71c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31edb6ed2fbfaa8e1888a97e6a07334e0551b67ab1ed66153445be516ca2f916b76e4cf0d378915d7ee3cb5082cdd307570bfc1191760bb19243472e4758b757
|
7
|
+
data.tar.gz: 85be7ae9d1be8adeac4020cfed26e9a30fa917bb7c051b88b3c9c14a1a204b9ad64d37c3a5920d72a9593fc6389fd71cad59ae0baf3b0bdc5f9cb7892c8501c6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
An example template might look like:
|
10
10
|
|
11
11
|
```erb
|
12
|
-
<!-- ./app/views/user_mailer/
|
12
|
+
<!-- ./app/views/user_mailer/user_signup_confirmation.mjml -->
|
13
13
|
<mjml>
|
14
14
|
<mj-head>
|
15
15
|
<mj-preview>Hello World</mj-preview>
|
@@ -18,7 +18,7 @@ An example template might look like:
|
|
18
18
|
<mj-section>
|
19
19
|
<mj-column>
|
20
20
|
<mj-text>Hello World</mj-text>
|
21
|
-
<%= render partial: "info" %>
|
21
|
+
<%= render partial: "info", formats: [:html] %>
|
22
22
|
</mj-column>
|
23
23
|
</mj-section>
|
24
24
|
</mj-body>
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/erb/mailer/mailer_generator'
|
2
4
|
|
3
5
|
module Mjml
|
4
6
|
module Generators
|
5
7
|
class MailerGenerator < Erb::Generators::MailerGenerator
|
6
|
-
source_root File.expand_path(
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
7
9
|
|
8
10
|
private
|
9
11
|
|
@@ -26,8 +28,8 @@ module Mjml
|
|
26
28
|
def filename_with_extensions(name, file_format = format)
|
27
29
|
# Due to MJML single-pass processing nature
|
28
30
|
# layout files MUST have .mjml extension, but views/templates cannot
|
29
|
-
is_layout_file = name.in?([:layout,
|
30
|
-
[name, file_format, is_layout_file ? handler : view_handler].compact.join(
|
31
|
+
is_layout_file = name.in?([:layout, 'mailer'])
|
32
|
+
[name, file_format, is_layout_file ? handler : view_handler].compact.join('.')
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/mjml/handler.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'action_view'
|
2
4
|
require 'action_view/template'
|
3
5
|
require 'rails/version'
|
@@ -12,12 +14,7 @@ module Mjml
|
|
12
14
|
# Beginning with Rails 6 template handlers get the source of the template as the second
|
13
15
|
# parameter.
|
14
16
|
def call(template, source = nil)
|
15
|
-
compiled_source =
|
16
|
-
if Rails::VERSION::MAJOR >= 6
|
17
|
-
template_handler.call(template, source)
|
18
|
-
else
|
19
|
-
template_handler.call(template)
|
20
|
-
end
|
17
|
+
compiled_source = compile_source(source, template)
|
21
18
|
|
22
19
|
# Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
|
23
20
|
# If we get here and template source doesn't start with one it means
|
@@ -25,12 +22,22 @@ module Mjml
|
|
25
22
|
# Therefore we skip MJML processing and return raw compiled source. It will be processed
|
26
23
|
# by MJML library when top-level layout/template is rendered
|
27
24
|
#
|
28
|
-
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/
|
29
|
-
if
|
25
|
+
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/components_1.md#mjml
|
26
|
+
if /<mjml.*?>/i.match?(compiled_source)
|
30
27
|
"Mjml::Parser.new(begin;#{compiled_source};end).render.html_safe"
|
31
28
|
else
|
32
29
|
compiled_source
|
33
30
|
end
|
34
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def compile_source(source, template)
|
36
|
+
if Rails::VERSION::MAJOR >= 6
|
37
|
+
template_handler.call(template, source)
|
38
|
+
else
|
39
|
+
template_handler.call(template)
|
40
|
+
end
|
41
|
+
end
|
35
42
|
end
|
36
43
|
end
|
data/lib/mjml/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mjml
|
2
4
|
class Parser
|
3
5
|
class ParseError < StandardError; end
|
@@ -7,8 +9,9 @@ module Mjml
|
|
7
9
|
# Create new parser
|
8
10
|
#
|
9
11
|
# @param input [String] The string to transform in html
|
10
|
-
def initialize
|
12
|
+
def initialize(input)
|
11
13
|
raise Mjml.mjml_binary_error_string unless Mjml.valid_mjml_binary
|
14
|
+
|
12
15
|
@input = input
|
13
16
|
end
|
14
17
|
|
@@ -16,14 +19,15 @@ module Mjml
|
|
16
19
|
#
|
17
20
|
# @return [String]
|
18
21
|
def render
|
19
|
-
in_tmp_file = Tempfile.open([
|
22
|
+
in_tmp_file = Tempfile.open(['in', '.mjml']) do |file|
|
20
23
|
file.write(input)
|
21
24
|
file # return tempfile from block so #unlink works later
|
22
25
|
end
|
23
26
|
run(in_tmp_file.path, Mjml.beautify, Mjml.minify, Mjml.validation_level)
|
24
|
-
rescue
|
27
|
+
rescue StandardError
|
25
28
|
raise if Mjml.raise_render_exception
|
26
|
-
|
29
|
+
|
30
|
+
''
|
27
31
|
ensure
|
28
32
|
in_tmp_file.unlink
|
29
33
|
end
|
@@ -31,14 +35,18 @@ module Mjml
|
|
31
35
|
# Exec mjml command
|
32
36
|
#
|
33
37
|
# @return [String] The result as string
|
34
|
-
|
35
|
-
|
36
|
-
|
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')
|
40
|
+
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}"
|
37
43
|
_, stderr, status = Mjml.run_mjml(command)
|
38
|
-
raise ParseError
|
39
|
-
|
44
|
+
raise ParseError, stderr.chomp unless status.success?
|
45
|
+
|
46
|
+
Mjml.logger.warn(stderr.chomp) if stderr.present?
|
40
47
|
out_tmp_file.read
|
41
48
|
end
|
42
49
|
end
|
50
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
43
51
|
end
|
44
52
|
end
|
data/lib/mjml/railtie.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mjml
|
2
4
|
class Railtie < Rails::Railtie
|
3
5
|
config.mjml = Mjml
|
4
|
-
config.app_generators.mailer :
|
6
|
+
config.app_generators.mailer template_engine: :mjml
|
5
7
|
|
6
|
-
initializer
|
8
|
+
initializer 'mjml-rails.register_template_handler' do
|
7
9
|
ActionView::Template.register_template_handler :mjml, Mjml::Handler.new
|
8
|
-
Mime::Type.register_alias
|
10
|
+
Mime::Type.register_alias 'text/html', :mjml
|
9
11
|
end
|
10
12
|
|
11
13
|
config.to_prepare do
|
data/lib/mjml/version.rb
CHANGED
data/lib/mjml-rails.rb
CHANGED
data/lib/mjml.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
require "open3"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'rubygems'
|
4
|
+
require 'open3'
|
6
5
|
|
7
|
-
require
|
6
|
+
require 'mjml/handler'
|
7
|
+
require 'mjml/parser'
|
8
|
+
|
9
|
+
require 'mjml/railtie' if defined?(Rails)
|
8
10
|
|
9
11
|
module Mjml
|
10
12
|
mattr_accessor \
|
@@ -19,13 +21,14 @@ module Mjml
|
|
19
21
|
|
20
22
|
mattr_writer :valid_mjml_binary
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
self.template_language = :erb
|
25
|
+
self.raise_render_exception = true
|
26
|
+
self.mjml_binary_version_supported = '4.'
|
27
|
+
self.mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.." \
|
28
|
+
' have you run $ npm install mjml?'
|
29
|
+
self.beautify = true
|
30
|
+
self.minify = false
|
31
|
+
self.validation_level = 'strict'
|
29
32
|
|
30
33
|
def self.check_version(bin)
|
31
34
|
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
@@ -39,11 +42,11 @@ module Mjml
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def self.valid_mjml_binary
|
42
|
-
@@valid_mjml_binary
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
self.valid_mjml_binary = @@valid_mjml_binary ||
|
46
|
+
check_for_custom_mjml_binary ||
|
47
|
+
check_for_yarn_mjml_binary ||
|
48
|
+
check_for_npm_mjml_binary ||
|
49
|
+
check_for_global_mjml_binary
|
47
50
|
|
48
51
|
return @@valid_mjml_binary if @@valid_mjml_binary
|
49
52
|
|
@@ -52,21 +55,23 @@ module Mjml
|
|
52
55
|
|
53
56
|
def self.check_for_custom_mjml_binary
|
54
57
|
if const_defined?('BIN') && Mjml::BIN.present?
|
55
|
-
logger.warn('Setting `Mjml::BIN` is deprecated and will be removed in a future version!
|
58
|
+
logger.warn('Setting `Mjml::BIN` is deprecated and will be removed in a future version! ' \
|
59
|
+
'Please use `Mjml.mjml_binary=` instead.')
|
56
60
|
self.mjml_binary = Mjml::BIN
|
57
61
|
remove_const 'BIN'
|
58
62
|
end
|
59
63
|
|
60
|
-
return
|
64
|
+
return if mjml_binary.blank?
|
61
65
|
|
62
66
|
return mjml_binary if check_version(mjml_binary)
|
63
67
|
|
64
|
-
raise "MJML.mjml_binary is set to '#{mjml_binary}' but MJML-Rails could not validate that
|
68
|
+
raise "MJML.mjml_binary is set to '#{mjml_binary}' but MJML-Rails could not validate that " \
|
69
|
+
'it is a valid MJML binary. Please check your configuration.'
|
65
70
|
end
|
66
71
|
|
67
72
|
def self.check_for_yarn_mjml_binary
|
68
73
|
yarn_bin = `which yarn`.chomp
|
69
|
-
return
|
74
|
+
return if yarn_bin.blank?
|
70
75
|
|
71
76
|
mjml_bin = "#{yarn_bin} run mjml"
|
72
77
|
return mjml_bin if check_version(mjml_bin)
|
@@ -96,7 +101,8 @@ module Mjml
|
|
96
101
|
end
|
97
102
|
|
98
103
|
def self.discover_mjml_bin
|
99
|
-
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore!
|
104
|
+
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
|
105
|
+
'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
|
100
106
|
end
|
101
107
|
|
102
108
|
def self.setup
|
@@ -108,7 +114,7 @@ module Mjml
|
|
108
114
|
|
109
115
|
def logger
|
110
116
|
@logger ||= Logger.new($stdout).tap do |log|
|
111
|
-
log.progname =
|
117
|
+
log.progname = name
|
112
118
|
end
|
113
119
|
end
|
114
120
|
end
|
data/test/generator_test.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'generators/mjml/mailer/mailer_generator'
|
3
5
|
|
4
6
|
class GeneratorTest < Rails::Generators::TestCase
|
5
7
|
tests Mjml::Generators::MailerGenerator
|
6
|
-
destination File.expand_path(
|
8
|
+
destination File.expand_path('tmp', __dir__)
|
7
9
|
setup :prepare_destination
|
8
10
|
|
9
|
-
test
|
10
|
-
run_generator %w
|
11
|
+
test 'assert all views are properly created with given name' do
|
12
|
+
run_generator %w[notifier foo bar baz]
|
11
13
|
|
12
|
-
assert_file
|
13
|
-
assert_match
|
14
|
-
assert_match
|
15
|
-
assert_match
|
14
|
+
assert_file 'app/views/layouts/mailer.html.mjml' do |mailer|
|
15
|
+
assert_match '<mjml>', mailer
|
16
|
+
assert_match '<mj-body>', mailer
|
17
|
+
assert_match '<%= yield %>', mailer
|
16
18
|
end
|
17
19
|
|
18
|
-
assert_file
|
19
|
-
assert_match
|
20
|
-
assert_match
|
20
|
+
assert_file 'app/views/notifier_mailer/foo.html.erb' do |template|
|
21
|
+
assert_match '<%= @greeting %>', template
|
22
|
+
assert_match 'app/views/notifier_mailer/foo.html.erb', template
|
21
23
|
end
|
22
24
|
|
23
|
-
assert_file
|
24
|
-
assert_file
|
25
|
+
assert_file 'app/views/notifier_mailer/bar.html.erb'
|
26
|
+
assert_file 'app/views/notifier_mailer/baz.html.erb'
|
25
27
|
end
|
26
28
|
end
|
data/test/mjml_test.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
|
3
5
|
class NotifierMailer < ActionMailer::Base
|
4
|
-
self.view_paths = File.expand_path(
|
6
|
+
self.view_paths = File.expand_path('views', __dir__)
|
5
7
|
|
6
|
-
layout
|
8
|
+
layout 'default'
|
7
9
|
|
8
10
|
def inform_contact(recipient)
|
9
11
|
@recipient = recipient
|
10
12
|
|
11
|
-
mail(to: @recipient, from:
|
13
|
+
mail(to: @recipient, from: 'app@example.com') do |format|
|
12
14
|
format.text
|
13
15
|
format.html
|
14
16
|
end
|
@@ -17,7 +19,7 @@ class NotifierMailer < ActionMailer::Base
|
|
17
19
|
def invalid_template(recipient)
|
18
20
|
@recipient = recipient
|
19
21
|
|
20
|
-
mail(to: @recipient, from:
|
22
|
+
mail(to: @recipient, from: 'app@example.com') do |format|
|
21
23
|
format.html
|
22
24
|
format.text
|
23
25
|
end
|
@@ -25,91 +27,90 @@ class NotifierMailer < ActionMailer::Base
|
|
25
27
|
end
|
26
28
|
|
27
29
|
class NoLayoutMailer < ActionMailer::Base
|
28
|
-
self.view_paths = File.expand_path(
|
30
|
+
self.view_paths = File.expand_path('views', __dir__)
|
29
31
|
|
30
32
|
layout nil
|
31
33
|
|
32
34
|
def inform_contact(recipient)
|
33
35
|
@recipient = recipient
|
34
36
|
|
35
|
-
mail(to: @recipient, from:
|
36
|
-
format.mjml
|
37
|
-
end
|
37
|
+
mail(to: @recipient, from: 'app@example.com', &:mjml)
|
38
38
|
end
|
39
39
|
|
40
40
|
def with_owa(recipient)
|
41
41
|
@recipient = recipient
|
42
42
|
|
43
|
-
mail(to: @recipient, from:
|
44
|
-
format.mjml
|
45
|
-
end
|
43
|
+
mail(to: @recipient, from: 'app@example.com', &:mjml)
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
47
|
class NotifierMailerTest < ActiveSupport::TestCase
|
50
|
-
test
|
51
|
-
email = NotifierMailer.inform_contact(
|
48
|
+
test 'MJML layout based multipart email is generated correctly' do
|
49
|
+
email = NotifierMailer.inform_contact('user@example.com')
|
52
50
|
|
53
|
-
assert_equal
|
51
|
+
assert_equal 'multipart/alternative', email.mime_type
|
54
52
|
|
55
53
|
# To debug tests:
|
56
54
|
# Mjml.logger.info email.mime_type
|
57
55
|
# Mjml.logger.info email.to_s
|
58
56
|
# Mjml.logger.info email.html_part.body
|
59
57
|
|
60
|
-
|
61
|
-
assert email.html_part.body.
|
58
|
+
assert_not email.html_part.body.match(%r{</?mj.+?>})
|
59
|
+
assert email.html_part.body.include?('<body')
|
62
60
|
assert email.html_part.body.match(/Hello, user@example.com!/)
|
63
|
-
assert email.html_part.body.
|
61
|
+
assert email.html_part.body.include?('<h2>We inform you about something</h2>')
|
64
62
|
assert email.html_part.body.match(%r{<a href="https://www.example.com">this link</a>})
|
65
|
-
assert email.html_part.body.
|
63
|
+
assert email.html_part.body.include?('tracking-code-123')
|
66
64
|
|
67
|
-
assert email.text_part.body.
|
65
|
+
assert email.text_part.body.include?('We inform you about something')
|
68
66
|
assert email.text_part.body.match(%r{Please visit https://www.example.com})
|
69
67
|
end
|
70
68
|
|
71
|
-
test
|
69
|
+
test 'Invalid template raises error with validation level strict' do
|
72
70
|
with_settings(validation_level: 'strict') do
|
73
|
-
email = NotifierMailer.invalid_template(
|
71
|
+
email = NotifierMailer.invalid_template('user@example.com')
|
74
72
|
assert_raise(ActionView::Template::Error) { email.html_part.body.to_s }
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
|
-
test
|
76
|
+
test 'Invalid template gets compiled with validation level soft' do
|
77
|
+
# suppress warning of MJML binary
|
78
|
+
Mjml.logger.stubs(:warn)
|
79
|
+
|
79
80
|
with_settings(validation_level: 'soft') do
|
80
|
-
email = NotifierMailer.invalid_template(
|
81
|
-
assert email.text_part.body.
|
82
|
-
assert email.html_part.body.
|
83
|
-
|
81
|
+
email = NotifierMailer.invalid_template('user@example.com')
|
82
|
+
assert email.text_part.body.include?('This is valid')
|
83
|
+
assert email.html_part.body.include?('This is valid')
|
84
|
+
assert_not email.html_part.body.include?('This is invalid')
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
class NotifierMailerTest < ActiveSupport::TestCase
|
89
|
-
test
|
90
|
-
email = NoLayoutMailer.inform_contact(
|
90
|
+
test 'old mjml-rails configuration style MJML template is rendered correctly' do
|
91
|
+
email = NoLayoutMailer.inform_contact('user@example.com')
|
91
92
|
|
92
|
-
assert_equal
|
93
|
+
assert_equal 'text/html', email.mime_type
|
93
94
|
|
94
|
-
|
95
|
-
assert email.body.
|
95
|
+
assert_not email.body.match(%r{</?mj.+?>})
|
96
|
+
assert email.body.include?('<body')
|
96
97
|
assert email.body.match(/Welcome, user@example.com!/)
|
97
|
-
assert email.body.
|
98
|
+
assert email.body.include?('<h2>We inform you about something</h2>')
|
98
99
|
assert email.body.match(%r{<a href="https://www.example.com">this link</a>})
|
99
|
-
|
100
|
+
assert_not email.body.include?('tracking-code-123')
|
100
101
|
end
|
101
102
|
|
102
|
-
test
|
103
|
-
email = NoLayoutMailer.with_owa(
|
103
|
+
test 'old mjml-rails MJML template with owa is rendered correctly' do
|
104
|
+
email = NoLayoutMailer.with_owa('user@example.com')
|
104
105
|
|
105
|
-
assert_equal
|
106
|
+
assert_equal 'text/html', email.mime_type
|
106
107
|
|
107
|
-
|
108
|
-
assert email.body.
|
108
|
+
assert_not email.body.match(%r{</?mj.+?>})
|
109
|
+
assert email.body.include?('<body')
|
109
110
|
assert email.body.match(/Welcome, user@example.com!/)
|
110
|
-
assert email.body.
|
111
|
+
assert email.body.include?('<h2>We inform you about something</h2>')
|
111
112
|
assert email.body.match(%r{<a href="https://www.example.com">this link</a>})
|
112
|
-
|
113
|
+
assert_not email.body.include?('tracking-code-123')
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
@@ -135,13 +136,16 @@ describe Mjml do
|
|
135
136
|
it 'raises an error if mjml_binary is invalid' do
|
136
137
|
Mjml.mjml_binary = 'some custom value'
|
137
138
|
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
138
|
-
|
139
|
+
assert(err.message.start_with?("MJML.mjml_binary is set to 'some custom value' " \
|
140
|
+
'but MJML-Rails could not validate that it is a valid MJML binary'))
|
139
141
|
end
|
140
142
|
|
141
143
|
it 'honors old Mjml::BIN way of setting custom binary' do
|
142
|
-
Mjml::BIN = 'set by old way'
|
144
|
+
silence_warnings { Mjml::BIN = 'set by old way' }
|
145
|
+
Mjml.logger.expects(:warn).with(regexp_matches(/Setting `Mjml::BIN` is deprecated/))
|
143
146
|
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
144
|
-
|
147
|
+
assert(err.message.start_with?("MJML.mjml_binary is set to 'set by old way' " \
|
148
|
+
'but MJML-Rails could not validate that it is a valid MJML binary'))
|
145
149
|
end
|
146
150
|
|
147
151
|
it 'ignores empty Mjml::BIN' do
|
@@ -149,7 +153,8 @@ describe Mjml do
|
|
149
153
|
Mjml.mjml_binary = 'set by mjml_binary'
|
150
154
|
|
151
155
|
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
152
|
-
|
156
|
+
assert(err.message.start_with?("MJML.mjml_binary is set to 'set by mjml_binary' " \
|
157
|
+
'but MJML-Rails could not validate that it is a valid MJML binary'))
|
153
158
|
end
|
154
159
|
end
|
155
160
|
end
|
data/test/parser_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe Mjml::Parser do
|
@@ -57,7 +59,7 @@ describe Mjml::Parser do
|
|
57
59
|
describe '#run' do
|
58
60
|
describe 'when shell command failed' do
|
59
61
|
it 'raises exception' do
|
60
|
-
err = expect { parser.run
|
62
|
+
err = expect { parser.run '/tmp/non_existent_file.mjml' }.must_raise(Mjml::Parser::ParseError)
|
61
63
|
expect(err.message).must_include 'Command line error'
|
62
64
|
end
|
63
65
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
3
5
|
Bundler.setup
|
4
6
|
|
5
|
-
require
|
6
|
-
require
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'active_support/test_case'
|
7
9
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
10
|
+
require 'action_mailer'
|
11
|
+
require 'rails/railtie'
|
12
|
+
require 'rails/generators'
|
13
|
+
require 'rails/generators/test_case'
|
12
14
|
require 'mocha/minitest'
|
15
|
+
require 'byebug'
|
13
16
|
|
14
17
|
# require "minitest/reporters"
|
15
18
|
# Minitest::Reporters.use!
|
16
19
|
|
17
|
-
|
18
|
-
require
|
20
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
21
|
+
require 'mjml'
|
19
22
|
Mjml::Railtie.run_initializers
|
20
23
|
|
21
24
|
ActiveSupport::TestCase.test_order = :sorted if ActiveSupport::TestCase.respond_to? :test_order=
|
@@ -27,18 +30,16 @@ ActionMailer::Base.delivery_method = :test
|
|
27
30
|
ActionMailer::Base.perform_deliveries = true
|
28
31
|
|
29
32
|
def with_settings(settings)
|
30
|
-
original_settings =
|
31
|
-
|
32
|
-
agg[key] = Mjml.public_send(key)
|
33
|
-
end
|
34
|
-
|
35
|
-
settings.each do |key, value|
|
36
|
-
Mjml.public_send("#{key}=", value)
|
37
|
-
end
|
38
|
-
|
33
|
+
original_settings = settings.each_with_object({}) { |(key, _), agg| agg[key] = Mjml.public_send(key) }
|
34
|
+
settings.each { |key, value| Mjml.public_send("#{key}=", value) }
|
39
35
|
yield
|
40
36
|
ensure
|
41
|
-
original_settings.each
|
42
|
-
Mjml.public_send("#{key}=", value)
|
43
|
-
end
|
37
|
+
original_settings.each { |key, value| Mjml.public_send("#{key}=", value) }
|
44
38
|
end
|
39
|
+
|
40
|
+
# Suppress all ruby warnings of the mail gem, see:
|
41
|
+
# * https://github.com/mikel/mail/issues/1424
|
42
|
+
# * https://github.com/mikel/mail/issues/1384
|
43
|
+
# * https://github.com/mikel/mail/pull/1162
|
44
|
+
require 'warning'
|
45
|
+
Warning.ignore(//, %r{.*gems/mail.*/lib/mail/})
|
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.
|
4
|
+
version: 4.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -11,32 +11,130 @@ bindir: bin
|
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
14
|
+
MIIEPDCCAqSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAkMSIwIAYDVQQDDBlzaWdo
|
15
|
+
bW9uL0RDPXNpZ2htb24vREM9Y29tMB4XDTIxMTIxODA1MDcyM1oXDTIyMTIxODA1
|
16
|
+
MDcyM1owJDEiMCAGA1UEAwwZc2lnaG1vbi9EQz1zaWdobW9uL0RDPWNvbTCCAaIw
|
17
|
+
DQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALvTbM9xGlGQ9pByLEAJjAqc6U76
|
18
|
+
64uCOSIkgIFbC4iQdU5vzB/w4Y+mjgkH4oMsuW2NQfFBV+xI3jxQA0dN4qMgHooB
|
19
|
+
AWT/CSk0AAqTY1qCfCSASHLUWb5ZxURvsHmlXX/HCLX9bPcaYB0nQ+VT/u0lCicZ
|
20
|
+
beXMczHsNAj8f3ZJWDR9mw5OYc6cdGHM7Se3sqrmEsMYL9s8d08tChDcllxKV7cE
|
21
|
+
r2zb0oPrRFoYpakOIz1ViCl4KqBpQsDqXbwEw1kDCkKMXGHCsmDKML55kXsVVu4Q
|
22
|
+
9vqGvtEuvseWsDpKb6Psy4nJoktswhotUf21dNVM9k8ufXNaWvZed+cYnBFPLdQV
|
23
|
+
daaEqh6hIC/yUP98D5u+xmTYLRQQEsjhkbdfoLmB8UOwrsEZu79TXN6Iq4MZqmBe
|
24
|
+
qkCTlXOMaO/EbWVRRvs64iibC/boVVlXu6RZCVNyzXEvYxg/zyl0zjS8KPR8Vf4f
|
25
|
+
RKOUVKJCcL/nW4VZ1mvmJtiXI3eARaJdrBEjjQIDAQABo3kwdzAJBgNVHRMEAjAA
|
26
|
+
MAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUC9Ln2Rotb61VZFq2rxBPP7sJIiUwHgYD
|
27
|
+
VR0RBBcwFYETc2lnaG1vbkBzaWdobW9uLmNvbTAeBgNVHRIEFzAVgRNzaWdobW9u
|
28
|
+
QHNpZ2htb24uY29tMA0GCSqGSIb3DQEBCwUAA4IBgQBN7i1ChHKDNa5ceCXUXdJ/
|
29
|
+
ZQnVQTx2KMvWwZ6qpkIWFbzwwL5w/xQdhQbLMjuaie5X1ZYOB9753ipw3tvl7iJz
|
30
|
+
vHEdTcOWAzMzHytySVcSa2DhanDopC+hrO5N+GoQ+5X9CN+xKG1Png4ho4FsuUtI
|
31
|
+
fESG8Kb48iNlpLGbfcM8Nqm/mYk/Xwqh3aSVb2E1NVUNr3QW84xB/xmzy2d9qNBm
|
32
|
+
0GecfnBmH+ARmR9Qk9H7YjtnhQv1W2wOBiz1k6GeO8wMLKRRHVI2TGcPR8AqhQGd
|
33
|
+
ejWL8tjMzIw5ggxro3WDklV1hn0iFSeWXNWd9tN40PjLYZqZ3krQ2wWgcgw/9eC9
|
34
|
+
yVr+12iQ7XbbPqlveO/FhP4gLa8e2q1TgWjYAXIaM61em83Dlm/3p75ch0YCB3X5
|
35
|
+
R9NsaxhBfawJEJcYoPZflGkLjJU8pjSuvIW5+rNgAiqY8D37hTtZMu/n2Fz8Qp24
|
36
|
+
7EZetZmcvBzARf8vQSJjga3y0Bftk8u7LmblOEWddzE=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
39
|
-
dependencies:
|
38
|
+
date: 2021-12-18 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: byebug
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: mocha
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.4.0
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.4.0
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rails
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rubocop
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.23.0
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.23.0
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rubocop-performance
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.12.0
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.12.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rubocop-rails
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 2.12.4
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 2.12.4
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: warning
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.2.1
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 1.2.1
|
40
138
|
description: Render MJML + ERb template views in Rails
|
41
139
|
email: sighmon@sighmon.com
|
42
140
|
executables: []
|
@@ -70,14 +168,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
168
|
requirements:
|
71
169
|
- - ">="
|
72
170
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
171
|
+
version: '2.5'
|
74
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
173
|
requirements:
|
76
174
|
- - ">="
|
77
175
|
- !ruby/object:Gem::Version
|
78
176
|
version: '0'
|
79
177
|
requirements: []
|
80
|
-
rubygems_version: 3.1.
|
178
|
+
rubygems_version: 3.1.6
|
81
179
|
signing_key:
|
82
180
|
specification_version: 4
|
83
181
|
summary: MJML + ERb templates
|
metadata.gz.sig
CHANGED
Binary file
|