mjml-premailer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95877653a5a4ad8155f4e878171341e0c1d9ef6b43351fde6862504333900524
4
- data.tar.gz: 26a8bafedb5064a49affa3fba245ffa8d02bc169c434d5b7ea3f9719f6a50188
3
+ metadata.gz: 2a358282013850d34f730c47e0fff480c6299e97a110f54f5bf2a0702bd5f86d
4
+ data.tar.gz: '038f27861c72bbdb7ad86e1630b9aeefca0c34b35ae9a31171003cbf73f4a96c'
5
5
  SHA512:
6
- metadata.gz: 70fabf7df1c3158c83a8a80f7fead2db93cd7679e0b6b333d9a157e094963709412f31773620eb7192cf36179666eee99e459da3140576f0476f1801eb3e161a
7
- data.tar.gz: f1bb3cf40bbe51b1880c82093b179a0bf3d5be61ebaeaadbbc2bd91e2badee137cb3e88045b8896c796892fd8fe90b1d9e1a4dce495b91bae2a96050a87b38af
6
+ metadata.gz: 9cd30f41124459faf0f58918893fa67268cdf0ec18d692216d8bdcc66cfa7f0fea2122352f51ac6feb5fecab63f53eb8e49f894961616d081c2e9899aad92879
7
+ data.tar.gz: 70caf40a5cdb125f6398986900861533f5f5725660ae3de954cf1cc40d5d82ff5de4a49da7af57d08780ae65967cda2f977144eb889327745f036a1994d14f36
data/Makefile CHANGED
@@ -10,4 +10,7 @@ run_env:
10
10
 
11
11
  publish:
12
12
  gem build mjml-premailer
13
- gem push
13
+ gem push mjml-premailer-$$(cat VERSION).gem
14
+
15
+ test:
16
+ bundle exec rspec
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
  [![Travis](https://travis-ci.org/srghma/mjml-premailer.svg?branch=master)](https://travis-ci.org/srghma/mjml-premailer)
6
- [![GitHub version](https://badge.fury.io/gh/srghma%2Fmjml-premailer.svg)](https://badge.fury.io/gh/srghma%2Fmjml-premailer)
6
+ [![Gem Version](https://badge.fury.io/rb/mjml-premailer.svg)](https://badge.fury.io/rb/mjml-premailer)
7
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/87ecd26fdfceb00dacb6/maintainability)](https://codeclimate.com/github/srghma/mjml-premailer/maintainability)
8
8
  [![Coverage Status](https://coveralls.io/repos/github/srghma/mjml-premailer/badge.svg?branch=master)](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
- Or you can process it yourself using
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::Hook.perform(mail)
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 'mjml-premailer'
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
- bin: ..., # by default found authomatically
46
- debug: false, # true/false
47
- beautify: true, # true/false
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
- ```erb
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
1
+ 0.0.2
@@ -1,9 +1,12 @@
1
- require 'action_mailer'
2
-
3
1
  require 'mjml-premailer/version'
4
- require 'mjml-premailer/hook'
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)
@@ -0,0 +1,9 @@
1
+ class MjmlPremailer
2
+ module Debug
3
+ extend self
4
+
5
+ def debug(str)
6
+ puts str if MjmlPremailer.config[:debug]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class MjmlPremailer
2
+ module MjmlMail
3
+ def mjml_mail(*args, **kargs, &block)
4
+ this_mail = mail(*args, **kargs, &block)
5
+
6
+ MjmlPremailer::TransformMail.transform_mail(this_mail)
7
+ end
8
+ end
9
+ end
@@ -1,37 +1,13 @@
1
1
  require 'open3'
2
2
 
3
3
  class MjmlPremailer
4
- module Hook
4
+ module TransformHtml
5
5
  extend self
6
6
 
7
- def perform(mail)
8
- html_part = mail.html_part || mail
9
- html = html_part.body.to_s
7
+ def transform_html(html_body)
8
+ bin = MjmlPremailer.config[:bin]
10
9
 
11
- debug '> MjmlPremailer template:'
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
- [temp_file.read, err]
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
- [out, err]
90
- end
91
- end
67
+ err_ = err.strip.presence
92
68
 
93
- def debug(str)
94
- puts str if MjmlPremailer.config[:debug]
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
@@ -1,4 +1,6 @@
1
1
  class ApplicationMailer < ActionMailer::Base
2
+ include MjmlPremailer::MjmlMail
3
+
2
4
  default from: 'from@example.com'
3
5
  layout 'mail'
4
6
  end
@@ -1,6 +1,7 @@
1
1
  class WelcomeMailer < ApplicationMailer
2
2
  def welcome_email(greeting)
3
3
  @greeting = greeting
4
- mail to: 'example@example.com'
4
+
5
+ mjml_mail(to: 'example@example.com')
5
6
  end
6
7
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe MjmlPremailer do
4
4
  describe '#config' do
5
5
  subject { MjmlPremailer.config }
6
+
6
7
  context 'when set' do
7
8
  around do |example|
8
9
  begin
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.1
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: 2018-05-19 00:00:00.000000000 Z
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/hook.rb
126
- - lib/mjml-premailer/railtie.rb
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.6
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
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'mjml-premailer', path: '..'
4
- gem 'nokogiri'
5
- gem 'rails', '~> 5.0'
6
-
7
- platforms :rbx do
8
- gem 'racc'
9
- gem 'rubysl'
10
- end
data/example/README.md DELETED
@@ -1,10 +0,0 @@
1
- # Example Rails App
2
-
3
- To run this app, run:
4
-
5
- ```shell
6
- bundle
7
- bundle exec rails s
8
- ```
9
-
10
- Then point your browser at [http://localhost:3000/](http://localhost:3000/).
data/example/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Rails.application.load_tasks
@@ -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
- }
@@ -1,9 +0,0 @@
1
- class ExampleMailer < ActionMailer::Base
2
- default from: "from@example.com"
3
-
4
- layout 'mail'
5
-
6
- def test_message
7
- mail to: 'to@example.org', subject: 'Test Message'
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- <mj-text>Hello from wrapper</mj-text>
2
-
3
- <%= yield %>
@@ -1,9 +0,0 @@
1
- <mj-section>
2
- <mj-column>
3
- <mj-text>Hello from test_message outside block</mj-text>
4
-
5
- <%= render 'wrapper' do %>
6
- <mj-text>Hello from test_message inside block</mj-text>
7
- <% end %>
8
- </mj-column>
9
- </mj-section>
@@ -1,7 +0,0 @@
1
- <mjml>
2
- <mj-body>
3
- <mj-text>Hello from layout</mj-text>
4
-
5
- <%= yield %>
6
- </mj-body>
7
- </mjml>
data/example/bin/rails DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
data/example/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Rails.application
@@ -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
@@ -1,3 +0,0 @@
1
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
-
3
- require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -1,5 +0,0 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Rails.application.initialize!
@@ -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
@@ -1,2 +0,0 @@
1
- Rails.application.config.assets.version = '1.0'
2
- Rails.application.config.assets.precompile += %w( email.css )
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- root to: redirect('rails/mailers/example_mailer/test_message')
3
- end
@@ -1,2 +0,0 @@
1
- development:
2
- secret_key_base: bc1d05753b1a42a7d983dcb4f998c433532ec8f91ab3842a36ed3d9072d143a2d9c05a6dc43a3d780a2ff3d8e7b75a1011ae2e0d13a022e98dc1f0299da5a5a0
@@ -1,5 +0,0 @@
1
- class ExampleMailerPreview < ActionMailer::Preview
2
- def test_message
3
- ExampleMailer.test_message
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- class MjmlPremailer
2
- class Railtie < ::Rails::Railtie
3
- config.after_initialize do
4
- ::MjmlPremailer.register_interceptors
5
- end
6
- end
7
- end