mjml-rails 4.1.0 → 4.2.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 +2 -1
- data.tar.gz.sig +0 -0
- data/README.md +36 -45
- data/lib/generators/mjml/mailer/mailer_generator.rb +13 -2
- data/lib/generators/mjml/mailer/templates/layout.html.mjml +5 -0
- data/lib/generators/mjml/mailer/templates/{view.mjml → view.html.erb} +0 -0
- data/lib/mjml.rb +9 -1
- data/lib/mjml/version.rb +1 -1
- data/test/generator_test.rb +13 -3
- data/test/mjml_test.rb +36 -100
- metadata +4 -6
- metadata.gz.sig +3 -1
- data/lib/generators/mjml/mailer/templates/layout.mjml +0 -1
- data/test/mjml_subdir_test.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc88d6b14f96fbfe78ac00b83250ab72a874d6a
|
4
|
+
data.tar.gz: 2fcde96e13cabd54474394cbca661c2936f03750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b50259d07cc0ef7b1d4c15b4d587a5c3379ea859b9468de54222e562a0c86c83b468be2b4160c36695b1d2ce42cd2454e9145fbbf632bed6207d522810913c
|
7
|
+
data.tar.gz: 51dcfa5a5d08b911bb3ad2ab276c52edbc39510f184d84562f672d27c19454677b32b55a65680bd4acd7c35421d25cf81287a19378e102bf33c71cb01b8beec8
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
���� ��K��9H�@�$��-�tE������e��������"�bl�
|
2
|
+
�'N�mQӇ�]��2�-������ԵZ�V�`�}��,�iZ@\��,� &��J������X�� V{w��0�`�&�����[*>K����w���H�G �\��FY>�w�c�ɬ��<~�9e��\�{��y�$��Wu�B� ..���Z��8�?�=حÏ����H9�`DSO�x8(ꚁ`0�Mܚ��)
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
An example template might look like:
|
8
8
|
|
9
9
|
```erb
|
10
|
-
<!-- ./app/views/user_mailer/email.mjml -->
|
10
|
+
<!-- ./app/views/user_mailer/email.html.mjml -->
|
11
11
|
<mjml>
|
12
12
|
<mj-head>
|
13
13
|
<mj-preview>Hello World</mj-preview>
|
@@ -16,7 +16,7 @@ An example template might look like:
|
|
16
16
|
<mj-section>
|
17
17
|
<mj-column>
|
18
18
|
<mj-text>Hello World</mj-text>
|
19
|
-
<%= render :
|
19
|
+
<%= render partial: "info" %>
|
20
20
|
</mj-column>
|
21
21
|
</mj-section>
|
22
22
|
</mj-body>
|
@@ -26,19 +26,19 @@ An example template might look like:
|
|
26
26
|
And the partial `_info.mjml`:
|
27
27
|
|
28
28
|
```erb
|
29
|
-
<!-- ./app/views/user_mailer/_info.
|
29
|
+
<!-- ./app/views/user_mailer/_info.html.erb -->
|
30
30
|
<mj-text>This is <%= @user.username %></mj-text>
|
31
31
|
```
|
32
32
|
|
33
|
-
* Notice you can use
|
33
|
+
* Notice you can use ERB and partials inside the template.
|
34
34
|
|
35
35
|
Your `user_mailer.rb` might look like this::
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
# ./app/mailers/user_mailer.rb
|
39
39
|
class UserMailer < ActionMailer::Base
|
40
|
-
def user_signup_confirmation
|
41
|
-
mail(to:
|
40
|
+
def user_signup_confirmation
|
41
|
+
mail(to: "user@example.com", from: "app@example.com") do |format|
|
42
42
|
format.text
|
43
43
|
format.mjml
|
44
44
|
end
|
@@ -86,9 +86,9 @@ Mjml.setup do |config|
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
-
### MJML v3.x & v4.
|
89
|
+
### MJML v3.x & v4.x support
|
90
90
|
|
91
|
-
Version 4.
|
91
|
+
Version 4.x of this gem brings support for MJML 4.x
|
92
92
|
|
93
93
|
Version 2.3.x and 2.4.x of this gem brings support for MJML 3.x
|
94
94
|
|
@@ -116,67 +116,57 @@ npm install -g mjml@3.3.5
|
|
116
116
|
|
117
117
|
## Using Email Layouts
|
118
118
|
|
119
|
+
*Note*: [Aleksandrs Ļedovskis](https://github.com/aleksandrs-ledovskis) kindly updated the gem for better Rails Email Layouts support - it should be a non-breaking change, but check the updated file naming below if you experience problems.
|
120
|
+
|
119
121
|
Mailer:
|
120
122
|
```ruby
|
121
|
-
# mailers/
|
123
|
+
# mailers/my_mailer.rb
|
122
124
|
class MyMailer < ActionMailer::Base
|
123
125
|
layout "default"
|
124
126
|
|
125
|
-
def
|
126
|
-
|
127
|
-
to: recipient.email,
|
128
|
-
from: ENV["MAILER_FROM"],
|
129
|
-
subject: subject
|
130
|
-
) do |format|
|
131
|
-
format.mjml { render template_name, locals: { recipient: recipient }.merge(params) }
|
132
|
-
end
|
133
|
-
end
|
127
|
+
def foo_bar(user)
|
128
|
+
@recipient = user
|
134
129
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
"foo_bar",
|
139
|
-
user,
|
140
|
-
"email subject",
|
141
|
-
request: item
|
142
|
-
)
|
130
|
+
mail(to: user.email, from: "app@example.com") do |format|
|
131
|
+
format.html
|
132
|
+
end
|
143
133
|
end
|
144
134
|
end
|
145
135
|
```
|
146
136
|
|
147
137
|
Email layout:
|
148
138
|
```html
|
149
|
-
<!-- views/layouts/default.mjml -->
|
139
|
+
<!-- views/layouts/default.html.mjml -->
|
150
140
|
<mjml>
|
151
|
-
|
152
|
-
|
153
|
-
|
141
|
+
<mj-body>
|
142
|
+
<%= yield %>
|
143
|
+
</mj-body>
|
154
144
|
</mjml>
|
155
145
|
```
|
156
146
|
|
157
147
|
Email view:
|
158
148
|
```html
|
159
|
-
<!-- views/my_mailer/foo_bar.
|
160
|
-
<%= render partial: "to"
|
149
|
+
<!-- views/my_mailer/foo_bar.html.erb -->
|
150
|
+
<%= render partial: "to" %>
|
161
151
|
|
162
152
|
<mj-section>
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
153
|
+
<mj-column>
|
154
|
+
<mj-text>
|
155
|
+
Something foo regarding bar!
|
156
|
+
</mj-text>
|
157
|
+
</mj-column>
|
168
158
|
</mj-section>
|
169
159
|
```
|
170
160
|
|
171
161
|
Email partial:
|
172
162
|
```html
|
173
|
-
<!-- views/my_mailer/_to.
|
163
|
+
<!-- views/my_mailer/_to.html.erb -->
|
174
164
|
<mj-section>
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
165
|
+
<mj-column>
|
166
|
+
<mj-text>
|
167
|
+
Hello <%= @recipient.name %>,
|
168
|
+
</mj-text>
|
169
|
+
</mj-column>
|
180
170
|
</mj-section>
|
181
171
|
```
|
182
172
|
|
@@ -268,14 +258,15 @@ If you discover any bugs, feel free to create an issue on GitHub. Please add as
|
|
268
258
|
|
269
259
|
* Simon Loffler [github.com/sighmon](https://github.com/sighmon)
|
270
260
|
* Steven Pickles [github.com/thatpixguy](https://github.com/thatpixguy)
|
261
|
+
* [The Rails community](https://github.com/sighmon/mjml-rails/pulls?q=is%3Apr+is%3Aclosed). :-)
|
271
262
|
|
272
263
|
## Other similar gems
|
273
264
|
|
274
|
-
* [srghma/mjml-premailer](https://github.com/srghma/mjml-premailer)
|
265
|
+
* [srghma/mjml-premailer](https://github.com/srghma/mjml-premailer)
|
275
266
|
* [kolybasov/mjml-ruby/](https://github.com/kolybasov/mjml-ruby/)
|
276
267
|
|
277
268
|
## License
|
278
269
|
|
279
|
-
MIT License. Copyright
|
270
|
+
MIT License. Copyright 2018 Simon Loffler. [sighmon.com](http://sighmon.com)
|
280
271
|
|
281
272
|
Lovingly built on [github.com/plataformatec/markerb](https://github.com/plataformatec/markerb)
|
@@ -5,10 +5,10 @@ module Mjml
|
|
5
5
|
class MailerGenerator < Erb::Generators::MailerGenerator
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
|
-
|
8
|
+
private
|
9
9
|
|
10
10
|
def format
|
11
|
-
|
11
|
+
:html
|
12
12
|
end
|
13
13
|
|
14
14
|
def formats
|
@@ -18,6 +18,17 @@ module Mjml
|
|
18
18
|
def handler
|
19
19
|
:mjml
|
20
20
|
end
|
21
|
+
|
22
|
+
def view_handler
|
23
|
+
Mjml.template_language
|
24
|
+
end
|
25
|
+
|
26
|
+
def filename_with_extensions(name, file_format = format)
|
27
|
+
# Due to MJML single-pass processing nature
|
28
|
+
# layout files MUST have .mjml extension, but views/templates cannot
|
29
|
+
is_layout_file = name.in?([:layout, "mailer"])
|
30
|
+
[name, file_format, is_layout_file ? handler : view_handler].compact.join(".")
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
File without changes
|
data/lib/mjml.rb
CHANGED
@@ -41,7 +41,15 @@ module Mjml
|
|
41
41
|
|
42
42
|
def call(template)
|
43
43
|
compiled_source = template_handler.call(template)
|
44
|
-
|
44
|
+
|
45
|
+
# Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
|
46
|
+
# If we get here and template source doesn't start with one it means
|
47
|
+
# that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
|
48
|
+
# Therefore we skip MJML processing and return raw compiled source. It will be processed
|
49
|
+
# by MJML library when top-level layout/template is rendered
|
50
|
+
#
|
51
|
+
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/guide.md#mjml
|
52
|
+
if template.source =~ /<mjml>/
|
45
53
|
"Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe"
|
46
54
|
else
|
47
55
|
compiled_source
|
data/lib/mjml/version.rb
CHANGED
data/test/generator_test.rb
CHANGED
@@ -9,8 +9,18 @@ class GeneratorTest < Rails::Generators::TestCase
|
|
9
9
|
test "assert all views are properly created with given name" do
|
10
10
|
run_generator %w(notifier foo bar baz)
|
11
11
|
|
12
|
-
assert_file "app/views/
|
13
|
-
|
14
|
-
|
12
|
+
assert_file "app/views/layouts/mailer.html.mjml" do |mailer|
|
13
|
+
assert_match "<mjml>", mailer
|
14
|
+
assert_match "<mj-body>", mailer
|
15
|
+
assert_match "<%= yield %>", mailer
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_file "app/views/notifier_mailer/foo.html.erb" do |template|
|
19
|
+
assert_match "<%= @greeting %>", template
|
20
|
+
assert_match "app/views/notifier_mailer/foo.html.erb", template
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_file "app/views/notifier_mailer/bar.html.erb"
|
24
|
+
assert_file "app/views/notifier_mailer/baz.html.erb"
|
15
25
|
end
|
16
26
|
end
|
data/test/mjml_test.rb
CHANGED
@@ -1,127 +1,63 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class NotifierMailer < ActionMailer::Base
|
4
4
|
self.view_paths = File.expand_path("../views", __FILE__)
|
5
5
|
|
6
|
-
layout
|
6
|
+
layout "default"
|
7
7
|
|
8
|
-
def
|
8
|
+
def inform_contact(recipient)
|
9
9
|
@recipient = recipient
|
10
|
-
mail(:to => @recipient, :from => "john.doe@example.com") do |format|
|
11
|
-
format.send(format_type)
|
12
|
-
end
|
13
|
-
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
format.
|
11
|
+
mail(to: @recipient, from: "app@example.com") do |format|
|
12
|
+
format.text
|
13
|
+
format.html
|
18
14
|
end
|
19
15
|
end
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
format.send(format_type)
|
24
|
-
end
|
25
|
-
end
|
18
|
+
class NoLayoutMailer < ActionMailer::Base
|
19
|
+
self.view_paths = File.expand_path("../views", __FILE__)
|
26
20
|
|
27
|
-
|
28
|
-
mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
|
29
|
-
format.send(format_type)
|
30
|
-
end
|
31
|
-
end
|
21
|
+
layout nil
|
32
22
|
|
33
|
-
def
|
23
|
+
def inform_contact(recipient)
|
34
24
|
@recipient = recipient
|
35
|
-
|
36
|
-
|
37
|
-
format.
|
25
|
+
|
26
|
+
mail(to: @recipient, from: "app@example.com") do |format|
|
27
|
+
format.mjml
|
38
28
|
end
|
39
29
|
end
|
40
30
|
end
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# @show_text = render_options.delete(:show_text)
|
46
|
-
# super(render_options)
|
47
|
-
# end
|
32
|
+
class NotifierMailerTest < ActiveSupport::TestCase
|
33
|
+
test "MJML layout based multipart email is generated correctly" do
|
34
|
+
email = NotifierMailer.inform_contact("user@example.com")
|
48
35
|
|
49
|
-
|
50
|
-
# show_text ? "TEST #{text}" : "TEST"
|
51
|
-
# end
|
52
|
-
# end
|
36
|
+
assert_equal "multipart/alternative", email.mime_type
|
53
37
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
38
|
+
refute email.html_part.body.match(%r{</?mj.+?>})
|
39
|
+
assert email.html_part.body.match(/<body>/)
|
40
|
+
assert email.html_part.body.match(/Hello, user@example.com!/)
|
41
|
+
assert email.html_part.body.match(%r{<h2>We inform you about something</h2>})
|
42
|
+
assert email.html_part.body.match(%r{<a href="https://www.example.com">this link</a>})
|
43
|
+
assert email.html_part.body.match(/tracking-code-123/)
|
60
44
|
|
61
|
-
|
62
|
-
|
63
|
-
Mjml.processing_options = @original_processing_options
|
45
|
+
assert email.text_part.body.match(/We inform you about something/)
|
46
|
+
assert email.text_part.body.match(%r{Please visit https://www.example.com})
|
64
47
|
end
|
48
|
+
end
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
assert_no_match(/<mj-body>/, email.body.encoded.strip)
|
70
|
-
assert_match(/<body/, email.body.encoded.strip)
|
71
|
-
assert_match('<p>Hello from <a href="http://www.sighmon.com">sighmon.com</a></p>', email.body.encoded.strip)
|
72
|
-
end
|
50
|
+
class NotifierMailerTest < ActiveSupport::TestCase
|
51
|
+
test "old mjml-rails configuration style MJML template is rendered correctly" do
|
52
|
+
email = NoLayoutMailer.inform_contact("user@example.com")
|
73
53
|
|
74
|
-
test 'with partial' do
|
75
|
-
email = Notifier.user(:mjml)
|
76
54
|
assert_equal "text/html", email.mime_type
|
77
|
-
assert_match(/Hello Partial/, email.body.encoded.strip)
|
78
|
-
assert_no_match(/mj-text/, email.body.encoded.strip)
|
79
|
-
end
|
80
55
|
|
81
|
-
|
82
|
-
email
|
83
|
-
|
84
|
-
|
85
|
-
|
56
|
+
refute email.body.match(%r{</?mj.+?>})
|
57
|
+
assert email.body.match(/<body>/)
|
58
|
+
assert email.body.match(/Welcome, user@example.com!/)
|
59
|
+
assert email.body.match(%r{<h2>We inform you about something</h2>})
|
60
|
+
assert email.body.match(%r{<a href="https://www.example.com">this link</a>})
|
61
|
+
refute email.body.match(/tracking-code-123/)
|
86
62
|
end
|
87
|
-
|
88
|
-
# test "plain text should be sent as a plain text" do
|
89
|
-
# email = Notifier.contact("you@example.com", :text)
|
90
|
-
# assert_equal "text/plain", email.mime_type
|
91
|
-
# assert_equal "<mj-body></mj-body>", email.body.encoded.strip
|
92
|
-
# end
|
93
|
-
|
94
|
-
# test 'dealing with multipart e-mails' do
|
95
|
-
# email = Notifier.multiple_format_contact("you@example.com")
|
96
|
-
# assert_equal 2, email.parts.size
|
97
|
-
# assert_equal "multipart/alternative", email.mime_type
|
98
|
-
# assert_equal "text/plain", email.parts[0].mime_type
|
99
|
-
# assert_equal "<mj-body></mj-body>",
|
100
|
-
# email.parts[0].body.encoded.strip
|
101
|
-
# assert_equal "text/html", email.parts[1].mime_type
|
102
|
-
# assert_not_equal "<mj-body></mj-body>",
|
103
|
-
# email.parts[1].body.encoded.strip
|
104
|
-
# end
|
105
|
-
|
106
|
-
# test "with a custom renderer" do
|
107
|
-
# Mjml.renderer = TestRenderer
|
108
|
-
# email = Notifier.contact("you@example.com", :html)
|
109
|
-
# assert_equal "text/html", email.mime_type
|
110
|
-
# assert_equal "<p>TEST<strong>TEST</strong>TEST</p>", email.body.encoded.strip
|
111
|
-
# end
|
112
|
-
|
113
|
-
# test "with a custom renderer and options" do
|
114
|
-
# Mjml.renderer = TestRenderer.new(:show_text => true)
|
115
|
-
# email = Notifier.contact("you@example.com", :html)
|
116
|
-
# assert_equal "text/html", email.mime_type
|
117
|
-
# assert_equal "<p>TEST Dual templates <strong>TEST rocks</strong>TEST !</p>", email.body.encoded.strip
|
118
|
-
# end
|
119
|
-
|
120
|
-
# test 'with custom mjml processing options' do
|
121
|
-
# Mjml.processing_options = {:autolink => true}
|
122
|
-
# email = Notifier.link(:html)
|
123
|
-
# assert_equal "text/html", email.mime_type
|
124
|
-
# assert_equal '<p>Hello from <a href="http://www.sighmon.com">http://www.sighmon.com</a></p>', email.body.encoded.strip
|
125
|
-
# end
|
126
|
-
|
127
63
|
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.
|
4
|
+
version: 4.2.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-07-08 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description: Render MJML + ERb template views in Rails
|
37
37
|
email: sighmon@sighmon.com
|
@@ -42,8 +42,8 @@ files:
|
|
42
42
|
- MIT-LICENSE
|
43
43
|
- README.md
|
44
44
|
- lib/generators/mjml/mailer/mailer_generator.rb
|
45
|
-
- lib/generators/mjml/mailer/templates/layout.mjml
|
46
|
-
- lib/generators/mjml/mailer/templates/view.
|
45
|
+
- lib/generators/mjml/mailer/templates/layout.html.mjml
|
46
|
+
- lib/generators/mjml/mailer/templates/view.html.erb
|
47
47
|
- lib/mjml-rails.rb
|
48
48
|
- lib/mjml.rb
|
49
49
|
- lib/mjml/mjmltemplate.rb
|
@@ -51,7 +51,6 @@ files:
|
|
51
51
|
- lib/mjml/railtie.rb
|
52
52
|
- lib/mjml/version.rb
|
53
53
|
- test/generator_test.rb
|
54
|
-
- test/mjml_subdir_test.rb
|
55
54
|
- test/mjml_test.rb
|
56
55
|
- test/parser_test.rb
|
57
56
|
- test/template_test.rb
|
@@ -82,7 +81,6 @@ specification_version: 4
|
|
82
81
|
summary: MJML + ERb templates
|
83
82
|
test_files:
|
84
83
|
- test/generator_test.rb
|
85
|
-
- test/mjml_subdir_test.rb
|
86
84
|
- test/parser_test.rb
|
87
85
|
- test/mjml_test.rb
|
88
86
|
- test/template_test.rb
|
metadata.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
L���8Z����s.���9�W��tc1ʵ����a��5���D
|
2
|
+
��m����)��1�{�y���$}�^+�2�&��ԉ`�uT�H��)q:>�Hm>jB��ŽŅ�^�y�wӽhp�p���2���F"�i��d����y"-&���}8vB�r�k�BK������9$[�\*���kf�x��8��B�-+q@��8��5����oz�R�8}J�;=�-#H�q{�<&lZᚄʙ�`,~�+
|
3
|
+
6~��NR���5
|
@@ -1 +0,0 @@
|
|
1
|
-
<%%= yield %>
|
data/test/mjml_subdir_test.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class SubdirNotifier < ActionMailer::Base
|
4
|
-
self.view_paths = File.expand_path("../views", __FILE__)
|
5
|
-
|
6
|
-
layout false
|
7
|
-
|
8
|
-
def simple_block(format_type)
|
9
|
-
mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
|
10
|
-
format.send(format_type)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def simple_block_and_path(format_type)
|
15
|
-
mail(:template_path => 'template_subdir',:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
|
16
|
-
format.send(format_type)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def simple_with_path(format_type)
|
21
|
-
mail(:template_path => 'template_subdir',:to => 'foo@bar.com', :from => "john.doe@example.com")
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
# class TestRenderer < ActionView::PartialRenderer
|
27
|
-
# attr_accessor :show_text
|
28
|
-
# def initialize(render_options = {})
|
29
|
-
# @show_text = render_options.delete(:show_text)
|
30
|
-
# super(render_options)
|
31
|
-
# end
|
32
|
-
|
33
|
-
# def normal_text(text)
|
34
|
-
# show_text ? "TEST #{text}" : "TEST"
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
|
38
|
-
class MjmlTest < ActiveSupport::TestCase
|
39
|
-
|
40
|
-
setup do
|
41
|
-
@original_renderer = Mjml.renderer
|
42
|
-
@original_processing_options = Mjml.processing_options
|
43
|
-
end
|
44
|
-
|
45
|
-
teardown do
|
46
|
-
Mjml.renderer = @original_renderer
|
47
|
-
Mjml.processing_options = @original_processing_options
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
test 'in a subdir with a block fails' do
|
52
|
-
assert_raises(ActionView::MissingTemplate) do
|
53
|
-
email = SubdirNotifier.simple_block(:mjml)
|
54
|
-
assert_equal "text/html", email.mime_type
|
55
|
-
assert_match(/alternate sub-directory/, email.body.encoded.strip)
|
56
|
-
assert_no_match(/mj-text/, email.body.encoded.strip)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'in a subdir with a block and template_path option fails' do
|
61
|
-
assert_raises(ActionView::MissingTemplate) do
|
62
|
-
email = SubdirNotifier.simple_block_and_path(:mjml)
|
63
|
-
assert_equal "text/html", email.mime_type
|
64
|
-
assert_match(/alternate sub-directory/, email.body.encoded.strip)
|
65
|
-
assert_no_match(/mj-text/, email.body.encoded.strip)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'in a subdir with path' do
|
70
|
-
email = SubdirNotifier.simple_with_path(:mjml)
|
71
|
-
assert_equal "text/html", email.mime_type
|
72
|
-
assert_match(/alternate sub-directory/, email.body.encoded.strip)
|
73
|
-
assert_no_match(/mj-text/, email.body.encoded.strip)
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|