mjml-rails 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +69 -1
- data/lib/mjml.rb +2 -1
- data/lib/mjml/parser.rb +2 -1
- data/lib/mjml/version.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: 8e77f052d7e2a3b95f8fa4a8968e90aac1a44d6c
|
4
|
+
data.tar.gz: c0779f30b21ec71d46ceee38db0ed65562e3df65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8bca5a52f8d01ea38f7044c59b6b2a1d8f4ceef3b4d305a5c60bc25198267d2e579142718203afcf4bc36ae9987a24e8bf4cc9af7c1eb251aeb8042dbbfe968
|
7
|
+
data.tar.gz: 4bf757fd433358cda8ee79f33588d7297009565276ced1c01cb13f684ddfd2156ce51c9b408b6c2bf95647f10535c1cac3b1dbcf3326014997f118dd3ba63ab6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ Install the MJML parser (optional -g to install it globally):
|
|
65
65
|
npm install -g mjml@^3.0
|
66
66
|
```
|
67
67
|
|
68
|
-
|
68
|
+
Note that you'll need at least Node.js version 6 for MJML to function properly.
|
69
69
|
|
70
70
|
If you're using ```:haml``` or any other Rails template language, create an initializer to set it up:
|
71
71
|
|
@@ -90,6 +90,74 @@ gem 'mjml-rails', '2.2.0'
|
|
90
90
|
|
91
91
|
[Hugo Giraudel](https://twitter.com/hugogiraudel) wrote a post on [using MJML in Rails](http://dev.edenspiekermann.com/2016/06/02/using-mjml-in-rails/).
|
92
92
|
|
93
|
+
## Using Email Layouts
|
94
|
+
|
95
|
+
Mailer:
|
96
|
+
```ruby
|
97
|
+
# mailers/foo_mailer.rb
|
98
|
+
class MyMailer < ActionMailer::Base
|
99
|
+
layout "default"
|
100
|
+
|
101
|
+
def mail_template(template_name, recipient, subject, **params)
|
102
|
+
mail(
|
103
|
+
to: recipient.email,
|
104
|
+
from: ENV["MAILER_FROM"],
|
105
|
+
subject: subject
|
106
|
+
) do |format|
|
107
|
+
format.mjml { render template_name, locals: { recipient: recipient }.merge(params) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# this function is called to send the email
|
112
|
+
def foo(item, user)
|
113
|
+
mail_template(
|
114
|
+
"foo_bar",
|
115
|
+
user,
|
116
|
+
"email subject",
|
117
|
+
request: item
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
Email layout:
|
124
|
+
```html
|
125
|
+
<!-- views/layouts/default.mjml -->
|
126
|
+
<mjml>
|
127
|
+
<mj-body>
|
128
|
+
<mj-container>
|
129
|
+
<%= yield %>
|
130
|
+
</mj-container>
|
131
|
+
</mj-body>
|
132
|
+
</mjml>
|
133
|
+
```
|
134
|
+
|
135
|
+
Email view:
|
136
|
+
```html
|
137
|
+
<!-- views/my_mailer/foo_bar.mjml.erb -->
|
138
|
+
<%= render partial: "to", formats: [:html], locals: { name: recipient.name } %>
|
139
|
+
|
140
|
+
<mj-section>
|
141
|
+
<mj-column>
|
142
|
+
<mj-text>
|
143
|
+
Hello <%= recipient.name %>!
|
144
|
+
</mj-text>
|
145
|
+
</mj-column>
|
146
|
+
</mj-section>
|
147
|
+
```
|
148
|
+
|
149
|
+
Email partial:
|
150
|
+
```html
|
151
|
+
<!-- views/my_mailer/_to.mjml -->
|
152
|
+
<mj-section>
|
153
|
+
<mj-column>
|
154
|
+
<mj-text>
|
155
|
+
<%= name %>,
|
156
|
+
</mj-text>
|
157
|
+
</mj-column>
|
158
|
+
</mj-section>
|
159
|
+
```
|
160
|
+
|
93
161
|
## Sending Devise user emails
|
94
162
|
|
95
163
|
If you use [Devise](https://github.com/plataformatec/devise) for user authentication and want to send user emails with MJML templates, here's how to override the [devise mailer](https://github.com/plataformatec/devise/blob/master/app/mailers/devise/mailer.rb):
|
data/lib/mjml.rb
CHANGED
@@ -25,7 +25,8 @@ module Mjml
|
|
25
25
|
mjml_bin = File.join(`npm bin`.chomp, 'mjml')
|
26
26
|
return mjml_bin if check_version(mjml_bin)
|
27
27
|
|
28
|
-
|
28
|
+
puts "Couldn't find the MJML binary.. have you run $ npm install mjml?"
|
29
|
+
nil
|
29
30
|
end
|
30
31
|
|
31
32
|
BIN = discover_mjml_bin
|
data/lib/mjml/parser.rb
CHANGED
@@ -5,6 +5,7 @@ module Mjml
|
|
5
5
|
#
|
6
6
|
# @param input [String] The string to transform in html
|
7
7
|
def initialize input
|
8
|
+
raise "Couldn't find the MJML binary.. have you run $ npm install mjml?" unless mjml_bin
|
8
9
|
file = File.open(in_tmp_file, 'w')
|
9
10
|
file.write(input)
|
10
11
|
file.close
|
@@ -78,4 +79,4 @@ module Mjml
|
|
78
79
|
Mjml::BIN
|
79
80
|
end
|
80
81
|
end
|
81
|
-
end
|
82
|
+
end
|
data/lib/mjml/version.rb
CHANGED
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: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
5hPZOkUdP3egZ1xAHeFIOhTIaOJezjUEDQVattPkgwl25+Q2EXJ+5ehDU86v+lxH
|
32
32
|
E9hMwkxwQntg0fKVFbnVMOg2itaj8fJ7
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-
|
34
|
+
date: 2017-05-02 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
|