mjml-premailer 0.0.1 → 0.0.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
- data/Makefile +4 -1
- data/README.md +59 -44
- data/VERSION +1 -1
- data/lib/mjml-premailer.rb +6 -13
- data/lib/mjml-premailer/debug.rb +9 -0
- data/lib/mjml-premailer/mjml_mail.rb +9 -0
- data/lib/mjml-premailer/{hook.rb → transform_html.rb} +11 -35
- data/lib/mjml-premailer/transform_mail.rb +24 -0
- data/spec/rails_app/app/mailers/application_mailer.rb +2 -0
- data/spec/rails_app/app/mailers/welcome_mailer.rb +2 -1
- data/spec/unit/config_spec.rb +1 -0
- metadata +8 -60
- data/example/.gitignore +0 -16
- data/example/Gemfile +0 -10
- data/example/README.md +0 -10
- data/example/Rakefile +0 -6
- data/example/app/assets/stylesheets/email.css +0 -32
- data/example/app/mailers/example_mailer.rb +0 -9
- data/example/app/views/example_mailer/_wrapper.html.erb +0 -3
- data/example/app/views/example_mailer/test_message.html.erb +0 -9
- data/example/app/views/layout/mail.html.erb +0 -7
- data/example/bin/rails +0 -4
- data/example/config.ru +0 -4
- data/example/config/application.rb +0 -12
- data/example/config/boot.rb +0 -3
- data/example/config/environment.rb +0 -5
- data/example/config/environments/development.rb +0 -9
- data/example/config/environments/production.rb +0 -9
- data/example/config/initializers/assets.rb +0 -2
- data/example/config/routes.rb +0 -3
- data/example/config/secrets.yml +0 -2
- data/example/test/mailers/previews/example_mailer_preview.rb +0 -5
- data/lib/mjml-premailer/railtie.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a358282013850d34f730c47e0fff480c6299e97a110f54f5bf2a0702bd5f86d
|
4
|
+
data.tar.gz: '038f27861c72bbdb7ad86e1630b9aeefca0c34b35ae9a31171003cbf73f4a96c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd30f41124459faf0f58918893fa67268cdf0ec18d692216d8bdcc66cfa7f0fea2122352f51ac6feb5fecab63f53eb8e49f894961616d081c2e9899aad92879
|
7
|
+
data.tar.gz: 70caf40a5cdb125f6398986900861533f5f5725660ae3de954cf1cc40d5d82ff5de4a49da7af57d08780ae65967cda2f977144eb889327745f036a1994d14f36
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -3,19 +3,64 @@
|
|
3
3
|
Write your emails using [mjml framework](https://mjml.io) on rails, using any template language supported by Rails
|
4
4
|
|
5
5
|
[](https://travis-ci.org/srghma/mjml-premailer)
|
6
|
-
[](https://badge.fury.io/rb/mjml-premailer)
|
7
7
|
[](https://codeclimate.com/github/srghma/mjml-premailer/maintainability)
|
8
8
|
[](https://coveralls.io/github/srghma/mjml-premailer?branch=master)
|
9
9
|
|
10
10
|
## How it works
|
11
|
-
This gem will processes html part of your mail using `mjml` cli before delivery using rails ActionMailer hook
|
12
11
|
|
13
|
-
|
12
|
+
This gem will processes html part of your mail using `mjml` cli before delivery, just use `mjml_mail` function for delivery instead of `mail`
|
13
|
+
|
14
|
+
```rb
|
15
|
+
class ApplicationMailer < ActionMailer::Base
|
16
|
+
include MjmlPremailer::MjmlMail # adds function `mjml_mail`
|
17
|
+
|
18
|
+
layout "mailer"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
```rb
|
23
|
+
class WelcomeMailer < ApplicationMailer
|
24
|
+
def welcome(user)
|
25
|
+
@user = user
|
26
|
+
mjml_mail(to: @user.email, subject: 'Welcome')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
```erb
|
32
|
+
<!-- app/views/layouts/mailer.html.erb -->
|
33
|
+
|
34
|
+
<mjml>
|
35
|
+
<mj-head>
|
36
|
+
<mj-head>
|
37
|
+
My site
|
38
|
+
<mj-head>
|
39
|
+
<mj-head>
|
40
|
+
<mj-body>
|
41
|
+
<%= yield %>
|
42
|
+
<mj-body>
|
43
|
+
</mjml>
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
```erb
|
48
|
+
<!-- app/views/welcome_mailer/welcome.html.erb -->
|
49
|
+
|
50
|
+
<mj-text>Hello, <%= @user.name %></mj-text>
|
51
|
+
```
|
52
|
+
|
53
|
+
Or you can transform mail object yourself using
|
14
54
|
|
15
55
|
```ruby
|
16
|
-
MjmlPremailer::
|
56
|
+
MjmlPremailer::TransformMail.transform_mail(mail)
|
17
57
|
```
|
18
58
|
|
59
|
+
Example rails project you can find [here](example)
|
60
|
+
|
61
|
+
Mjml documentation is [here](https://mjml.io/documentation)
|
62
|
+
|
63
|
+
|
19
64
|
## Installation
|
20
65
|
|
21
66
|
Install `mjml` npm package (v4) globally
|
@@ -33,7 +78,7 @@ $ npm install --save-dev mjml@^4.0
|
|
33
78
|
Add the gem to your `Gemfile`:
|
34
79
|
|
35
80
|
```ruby
|
36
|
-
gem
|
81
|
+
gem "mjml-premailer"
|
37
82
|
```
|
38
83
|
|
39
84
|
## Configuration options
|
@@ -42,54 +87,24 @@ In `/config/initializers/mjml_premailer.rb`
|
|
42
87
|
|
43
88
|
```ruby
|
44
89
|
MjmlPremailer.config.merge!(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
minify: false, # true/false
|
49
|
-
keep_comments: false, # true/false
|
50
|
-
validation_level: :skip # :strict/:soft/:skip
|
51
|
-
)
|
52
|
-
```
|
53
|
-
|
54
|
-
## Usage
|
55
|
-
|
56
|
-
```erb
|
57
|
-
<!-- app/views/layouts/mailer.html.erb -->
|
58
|
-
|
59
|
-
<mjml>
|
60
|
-
<mj-body>
|
61
|
-
<%= yield %>
|
62
|
-
<mj-body>
|
63
|
-
</mjml>
|
64
|
-
```
|
65
|
-
|
90
|
+
minify: Rails.env.production?, # default - false
|
91
|
+
beautify: !Rails.env.production?, # default - true
|
92
|
+
keep_comments: !Rails.env.production?, # default - false
|
66
93
|
|
67
|
-
|
68
|
-
<!-- app/views/welcome_mailer/welcome.html.erb -->
|
69
|
-
|
70
|
-
<mj-text>Hello, <%= @user.name %></mj-text>
|
94
|
+
## other possible options
|
71
95
|
|
96
|
+
# debug: false, # default - false
|
97
|
+
# bin: ..., # by default bin path is found authomatically, but you can specify it here
|
98
|
+
# validation_level: :skip # default - :skip, possible options - :strict/:soft/:skip
|
99
|
+
)
|
72
100
|
```
|
73
101
|
|
74
|
-
|
75
|
-
class WelcomeMailer < ApplicationMailer
|
76
|
-
def welcome(user)
|
77
|
-
@user = user
|
78
|
-
mail(to: @user.email, subject: 'Welcome')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
```
|
82
|
-
|
83
|
-
Example rails project you can find [here](example)
|
84
|
-
|
85
|
-
Mjml documentation is [here](https://mjml.io/documentation)
|
102
|
+
More about options [here](https://mjml.io/documentation/#command-line-interface)
|
86
103
|
|
87
104
|
|
88
105
|
## Difference from other gems
|
89
106
|
|
90
107
|
[sighmon/mjml-rails](https://github.com/sighmon/mjml-rails):
|
91
|
-
- outdated
|
92
|
-
- work on hacks
|
93
108
|
- no support for `/app/views/layouts`
|
94
109
|
|
95
110
|
[kolybasov/mjml-ruby](https://github.com/kolybasov/mjml-ruby/):
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/mjml-premailer.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require 'action_mailer'
|
2
|
-
|
3
1
|
require 'mjml-premailer/version'
|
4
|
-
require 'mjml-premailer/
|
2
|
+
require 'mjml-premailer/debug'
|
5
3
|
require 'mjml-premailer/find_executable'
|
6
4
|
|
5
|
+
require 'mjml-premailer/transform_html'
|
6
|
+
require 'mjml-premailer/transform_mail'
|
7
|
+
|
8
|
+
require 'mjml-premailer/mjml_mail'
|
9
|
+
|
7
10
|
class MjmlPremailer
|
8
11
|
# from https://github.com/kolybasov/mjml-ruby/blob/master/lib/mjml.rb#L33
|
9
12
|
@config = {
|
@@ -18,14 +21,4 @@ class MjmlPremailer
|
|
18
21
|
class << self
|
19
22
|
attr_accessor :config
|
20
23
|
end
|
21
|
-
|
22
|
-
def self.register_interceptors
|
23
|
-
ActionMailer::Base.register_interceptor(MjmlPremailer::Hook)
|
24
|
-
|
25
|
-
if ActionMailer::Base.respond_to?(:register_preview_interceptor)
|
26
|
-
ActionMailer::Base.register_preview_interceptor(MjmlPremailer::Hook)
|
27
|
-
end
|
28
|
-
end
|
29
24
|
end
|
30
|
-
|
31
|
-
require 'mjml-premailer/railtie' if defined?(Rails)
|
@@ -1,37 +1,13 @@
|
|
1
1
|
require 'open3'
|
2
2
|
|
3
3
|
class MjmlPremailer
|
4
|
-
module
|
4
|
+
module TransformHtml
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
html = html_part.body.to_s
|
7
|
+
def transform_html(html_body)
|
8
|
+
bin = MjmlPremailer.config[:bin]
|
10
9
|
|
11
|
-
|
12
|
-
debug html
|
13
|
-
|
14
|
-
parsed_html, error = parse(html)
|
15
|
-
|
16
|
-
error_ = error.strip.presence
|
17
|
-
|
18
|
-
raise error_ if error_
|
19
|
-
|
20
|
-
debug '> MjmlPremailer parsed template:'
|
21
|
-
debug parsed_html
|
22
|
-
|
23
|
-
html_part.body = parsed_html
|
24
|
-
end
|
25
|
-
|
26
|
-
alias delivering_email perform
|
27
|
-
alias previewing_email perform
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def parse(html_body)
|
32
|
-
bin = MjmlPremailer.config[:bin]
|
33
|
-
|
34
|
-
beautify = MjmlPremailer.config[:beautify]
|
10
|
+
beautify = MjmlPremailer.config[:beautify]
|
35
11
|
beautify_option = "--config.beautify #{beautify}"
|
36
12
|
|
37
13
|
minify = MjmlPremailer.config[:minify]
|
@@ -68,7 +44,9 @@ class MjmlPremailer
|
|
68
44
|
temp_file.rewind
|
69
45
|
temp_file.unlink
|
70
46
|
|
71
|
-
|
47
|
+
err_ = err.strip.presence
|
48
|
+
|
49
|
+
[temp_file.read, err_]
|
72
50
|
else
|
73
51
|
write_output_to_stdout_option = '-s'
|
74
52
|
|
@@ -82,16 +60,14 @@ class MjmlPremailer
|
|
82
60
|
validation_level_option
|
83
61
|
].join(' ')
|
84
62
|
|
85
|
-
debug "> MjmlPremailer command: #{cmd}"
|
63
|
+
MjmlPremailer::Debug.debug "> MjmlPremailer command: #{cmd}"
|
86
64
|
|
87
65
|
out, err, _sts = Open3.capture3(cmd, stdin_data: html_body)
|
88
66
|
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
67
|
+
err_ = err.strip.presence
|
92
68
|
|
93
|
-
|
94
|
-
|
69
|
+
[out, err_]
|
70
|
+
end
|
95
71
|
end
|
96
72
|
end
|
97
73
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class MjmlPremailer
|
2
|
+
module TransformMail
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def transform_mail(mail)
|
6
|
+
mail.tap do
|
7
|
+
html_part = mail.html_part || mail
|
8
|
+
html = html_part.body.to_s
|
9
|
+
|
10
|
+
MjmlPremailer::Debug.debug '> MjmlPremailer template:'
|
11
|
+
MjmlPremailer::Debug.debug html
|
12
|
+
|
13
|
+
parsed_html, error = MjmlPremailer::TransformHtml.transform_html(html)
|
14
|
+
|
15
|
+
raise error if error
|
16
|
+
|
17
|
+
MjmlPremailer::Debug.debug '> MjmlPremailer parsed template:'
|
18
|
+
MjmlPremailer::Debug.debug parsed_html
|
19
|
+
|
20
|
+
html_part.body = parsed_html
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/unit/config_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mjml-premailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Homa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -100,30 +100,12 @@ files:
|
|
100
100
|
- README.md
|
101
101
|
- Rakefile
|
102
102
|
- VERSION
|
103
|
-
- example/.gitignore
|
104
|
-
- example/Gemfile
|
105
|
-
- example/README.md
|
106
|
-
- example/Rakefile
|
107
|
-
- example/app/assets/stylesheets/email.css
|
108
|
-
- example/app/mailers/example_mailer.rb
|
109
|
-
- example/app/views/example_mailer/_wrapper.html.erb
|
110
|
-
- example/app/views/example_mailer/test_message.html.erb
|
111
|
-
- example/app/views/layout/mail.html.erb
|
112
|
-
- example/bin/rails
|
113
|
-
- example/config.ru
|
114
|
-
- example/config/application.rb
|
115
|
-
- example/config/boot.rb
|
116
|
-
- example/config/environment.rb
|
117
|
-
- example/config/environments/development.rb
|
118
|
-
- example/config/environments/production.rb
|
119
|
-
- example/config/initializers/assets.rb
|
120
|
-
- example/config/routes.rb
|
121
|
-
- example/config/secrets.yml
|
122
|
-
- example/test/mailers/previews/example_mailer_preview.rb
|
123
103
|
- lib/mjml-premailer.rb
|
104
|
+
- lib/mjml-premailer/debug.rb
|
124
105
|
- lib/mjml-premailer/find_executable.rb
|
125
|
-
- lib/mjml-premailer/
|
126
|
-
- lib/mjml-premailer/
|
106
|
+
- lib/mjml-premailer/mjml_mail.rb
|
107
|
+
- lib/mjml-premailer/transform_html.rb
|
108
|
+
- lib/mjml-premailer/transform_mail.rb
|
127
109
|
- lib/mjml-premailer/version.rb
|
128
110
|
- mjml-premailer.gemspec
|
129
111
|
- spec/integration/delivery_spec.rb
|
@@ -161,42 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
143
|
version: '0'
|
162
144
|
requirements: []
|
163
145
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.7.
|
146
|
+
rubygems_version: 2.7.7
|
165
147
|
signing_key:
|
166
148
|
specification_version: 4
|
167
149
|
summary: Write your emails using mjml framework
|
168
|
-
test_files:
|
169
|
-
- example/Gemfile
|
170
|
-
- example/README.md
|
171
|
-
- example/Rakefile
|
172
|
-
- example/app/assets/stylesheets/email.css
|
173
|
-
- example/app/mailers/example_mailer.rb
|
174
|
-
- example/app/views/example_mailer/_wrapper.html.erb
|
175
|
-
- example/app/views/example_mailer/test_message.html.erb
|
176
|
-
- example/app/views/layout/mail.html.erb
|
177
|
-
- example/bin/rails
|
178
|
-
- example/config.ru
|
179
|
-
- example/config/application.rb
|
180
|
-
- example/config/boot.rb
|
181
|
-
- example/config/environment.rb
|
182
|
-
- example/config/environments/development.rb
|
183
|
-
- example/config/environments/production.rb
|
184
|
-
- example/config/initializers/assets.rb
|
185
|
-
- example/config/routes.rb
|
186
|
-
- example/config/secrets.yml
|
187
|
-
- example/test/mailers/previews/example_mailer_preview.rb
|
188
|
-
- spec/integration/delivery_spec.rb
|
189
|
-
- spec/rails_app/app/mailers/application_mailer.rb
|
190
|
-
- spec/rails_app/app/mailers/welcome_mailer.rb
|
191
|
-
- spec/rails_app/app/views/layouts/mail.html.erb
|
192
|
-
- spec/rails_app/app/views/welcome_mailer/_wrapper.html.erb
|
193
|
-
- spec/rails_app/app/views/welcome_mailer/welcome_email.html.erb
|
194
|
-
- spec/rails_app/config.ru
|
195
|
-
- spec/rails_app/config/application.rb
|
196
|
-
- spec/rails_app/config/boot.rb
|
197
|
-
- spec/rails_app/config/environment.rb
|
198
|
-
- spec/rails_app/config/environments/test.rb
|
199
|
-
- spec/rails_app/config/initializers/assets.rb
|
200
|
-
- spec/rails_app/config/routes.rb
|
201
|
-
- spec/spec_helper.rb
|
202
|
-
- spec/unit/config_spec.rb
|
150
|
+
test_files: []
|
data/example/.gitignore
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
-
#
|
3
|
-
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
-
# or operating system, you probably want to add a global ignore instead:
|
5
|
-
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
-
|
7
|
-
# Ignore bundler config.
|
8
|
-
/.bundle
|
9
|
-
|
10
|
-
# Ignore the default SQLite database.
|
11
|
-
/db/*.sqlite3
|
12
|
-
/db/*.sqlite3-journal
|
13
|
-
|
14
|
-
# Ignore all logfiles and tempfiles.
|
15
|
-
/log/*.log
|
16
|
-
/tmp
|
data/example/Gemfile
DELETED
data/example/README.md
DELETED
data/example/Rakefile
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
background: #efefef;
|
3
|
-
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
4
|
-
}
|
5
|
-
|
6
|
-
p {
|
7
|
-
line-height: 1.4;
|
8
|
-
}
|
9
|
-
|
10
|
-
.wrap {
|
11
|
-
max-width: 40em;
|
12
|
-
margin: 0 auto;
|
13
|
-
padding: 1em;
|
14
|
-
background: white;
|
15
|
-
}
|
16
|
-
|
17
|
-
.greeting {
|
18
|
-
text-align: center;
|
19
|
-
font-weight: bold;
|
20
|
-
font-size: 110%;
|
21
|
-
}
|
22
|
-
|
23
|
-
.footer {
|
24
|
-
font-size: 90%;
|
25
|
-
color: #666;
|
26
|
-
}
|
27
|
-
|
28
|
-
a {
|
29
|
-
color: green;
|
30
|
-
text-decoration: none;
|
31
|
-
border-bottom: 2px solid green;
|
32
|
-
}
|
data/example/bin/rails
DELETED
data/example/config.ru
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'action_controller/railtie'
|
4
|
-
require 'action_mailer/railtie'
|
5
|
-
require 'sprockets/railtie'
|
6
|
-
|
7
|
-
Bundler.require(*Rails.groups)
|
8
|
-
|
9
|
-
module Example
|
10
|
-
class Application < Rails::Application
|
11
|
-
end
|
12
|
-
end
|
data/example/config/boot.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
Rails.application.configure do
|
2
|
-
config.cache_classes = false
|
3
|
-
config.eager_load = false
|
4
|
-
config.consider_all_requests_local = true
|
5
|
-
config.action_controller.perform_caching = false
|
6
|
-
config.assets.debug = true
|
7
|
-
config.assets.digest = true
|
8
|
-
config.assets.raise_runtime_errors = true
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
Rails.application.configure do
|
2
|
-
config.cache_classes = true
|
3
|
-
config.eager_load = true
|
4
|
-
config.consider_all_requests_local = false
|
5
|
-
config.action_controller.perform_caching = true
|
6
|
-
config.assets.compile = false
|
7
|
-
config.assets.digest = true
|
8
|
-
config.log_level = :info
|
9
|
-
end
|
data/example/config/routes.rb
DELETED
data/example/config/secrets.yml
DELETED