mjml-haml 0.1.1 → 0.2.0

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
  SHA1:
3
- metadata.gz: 1bcfcdb446ab96a8360f4216a3c1e2b0a1fd4dc4
4
- data.tar.gz: 8424cb964a54196407230b66d64ad7e450305627
3
+ metadata.gz: 67291cbd028813753e240a9ced2a3eacb45930cd
4
+ data.tar.gz: b1dcfb0646657a4a42a108732627485b6670bd23
5
5
  SHA512:
6
- metadata.gz: 32613e9ee60ce6048dbd905f2cb838ac5696ba09cd2b8e6b2cadc2638a4f87c707cf9d6816a811330744508b5f7776af97256c64aae5cb5aab4de3071f0867a2
7
- data.tar.gz: fa1f0ad48ba3ad91afffaed96c93c9679c5131a50f2c21be0d5a64c6823ee31983bab43d5048654191dc66456178c0361d0ac912b0399d9b80f621087e904e56
6
+ metadata.gz: 60feae028d0336f22ebc7cf05d064fce1ac4da23291988fb64423af8e20357947a5bca166333b3b311ad23d48a644d0cc5c3ed8dd64ebf398b00e6a52abc7d7d
7
+ data.tar.gz: b684bc293222f73212e9446c42f3c6159f7f6f07e21da02d47074daf467d8e34c9340999e039f735a735c94351b3ad670707b3cc4b1ed28e45fe19bc68a95d21
data/README.md CHANGED
@@ -2,40 +2,72 @@
2
2
 
3
3
  [![Build Status](https://api.travis-ci.org/fnix/mjml-haml.svg?branch=master)](http://travis-ci.org/fnix/mjml-haml) [![Gem Version](https://badge.fury.io/rb/mjml-haml.svg)](https://badge.fury.io/rb/mjml-haml)
4
4
 
5
- **MJML-Haml** allows you to render HTML e-mails from an [MJML](https://mjml.io) template.
5
+ **MJML-Haml** allows you to render HTML e-mails from a [MJML](https://mjml.io) template.
6
6
 
7
- An example template might look like:
7
+ An example layout might look like:
8
8
 
9
9
  ```haml
10
- / ./app/views/user_mailer/email.mjml
10
+ / app/views/layouts/user_mailer.html.mjml
11
11
  %mjml
12
12
  %mj-body
13
13
  %mj-container
14
- %mj-section
15
- %mj-column
16
- %mj-text
17
- = render :partial => 'info', :formats => [:html]
14
+ %mj-section{ background: { color: '#222' }, padding: '10px' }
15
+ %mj-column{ width: '30%' }
16
+ %mj-image{ alt: 'fnix', href: root_url, src: image_url('my-logo.png') }
17
+ %mj-column{ width: '30%' }
18
+ %mj-column{ width: '40%' }
19
+ %mj-social{ 'base-url': '/images/mailer/', display: 'facebook:url google:url linkedin:url twitter:url',
20
+ 'facebook-content': '', 'facebook-href': 'https://www.facebook.com/Fnix-804357709655741/',
21
+ 'facebook-icon-color': 'transparent', 'google-content': '',
22
+ 'google-href': 'https://plus.google.com/+FnixBr', 'google-icon-color': 'transparent', 'icon-size': '32px',
23
+ 'linkedin-content': '', 'linkedin-href': 'https://www.linkedin.com/company/fnix',
24
+ 'linkedin-icon-color': 'transparent', 'twitter-content': '', 'twitter-href': 'https://twitter.com/fnixbr',
25
+ 'twitter-icon-color': 'transparent' }
26
+ %mj-section{ 'text-align': 'left' }
27
+ = yield
28
+ %mj-section{ 'background-color': '#E5E5E5', padding: '10px 0' }
29
+ %mj-text{ 'font-size': '11px', 'line-height': '15px' }
30
+ My awesome footer
18
31
  ```
19
32
 
20
- And the partial `_info.mjml`:
33
+ And the template for an action:
21
34
 
22
35
  ```haml
23
- / ./app/views/user_mailer/_info.mjml
24
- %mj-text= "This is #{@user.username}"
36
+ / app/views/user_mailer/password.html.haml
37
+ %mj-text
38
+ %h2 Password
39
+ %mj-text
40
+ %p{style: 'text-align: justify;'}
41
+ == You sign up with #{provider_to_name @user.identities.first.try(:provider)}, so we generate a password for you:
42
+ %mj-button= @password
43
+ %mj-text
44
+ %p
45
+ == You need this password to change your #{link_to 'account', edit_user_registration_url} details. Do you want to
46
+ change this cryptic password, no problem::
47
+ %mj-button{ href: edit_user_registration_url } Change Password
48
+
49
+ ```
50
+
51
+ Note that the layout is named `.html.mjml` and the template `.html.haml`. Why? mjml only output content that are wrapped
52
+ by:
53
+
54
+ ```html
55
+ <mjml>
56
+ <mj-body>
57
+ ...
58
+ </mj-body>
59
+ </mjml>
25
60
  ```
26
61
 
27
- * Notice you can use Haml and partials inside the template.
62
+ So, for the template we just want to use HAML and for the layout + template we use mjml + haml.
28
63
 
29
- Your `user_mailer.rb` might look like this::
64
+ You write your mailer as usual:
30
65
 
31
66
  ```ruby
32
- # ./app/mailers/user_mailer.rb
67
+ # app/mailers/user_mailer.rb
33
68
  class UserMailer < ActionMailer::Base
34
- def user_signup_confirmation()
35
- mail(to: 'test@example.com', subject: 'test') do |format|
36
- format.text
37
- format.mjml
38
- end
69
+ def password()
70
+ mail(to: 'test@example.com', subject: 'test')
39
71
  end
40
72
  end
41
73
  ```
@@ -59,36 +91,6 @@ Install the MJML parser (optional -g to install it globally):
59
91
  ```console
60
92
  npm install -g mjml@^2.0
61
93
  ```
62
-
63
- ## Sending Devise user emails
64
-
65
- 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):
66
- ```ruby
67
- # app/mailers/devise_mailer.rb
68
- class DeviseMailer < Devise::Mailer
69
- def reset_password_instructions(record, token, opts={})
70
- @token = token
71
- @resource = record
72
- # Custom logic to send the email with MJML
73
- mail(
74
- template_path: 'devise/mailer',
75
- from: "some@email.com",
76
- to: record.email,
77
- subject: "Custom subject"
78
- ) do |format|
79
- format.mjml
80
- format.text
81
- end
82
- end
83
- end
84
- ```
85
-
86
- Now tell devise to user your mailer in `config/initializers/devise.rb` by setting `config.mailer = 'DeviseMailer'` or whatever name you called yours.
87
-
88
- And then your MJML template goes here: `app/views/devise/mailer/reset_password_instructions.mjml`
89
-
90
- Devise also have [more instructions](https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer) if you need them.
91
-
92
94
  ## Deploying with Heroku
93
95
 
94
96
  To deploy with [Heroku](https://heroku.com) you'll need to setup [multiple buildpacks](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app) so that Heroku first builds Node for MJML and then the Ruby environment for your app.
@@ -19,11 +19,11 @@ module Mjml
19
19
  # Check for a global install of MJML binary
20
20
  mjml_bin = 'mjml'
21
21
  return mjml_bin if check_version(mjml_bin)
22
-
22
+
23
23
  # Check for a local install of MJML binary
24
24
  mjml_bin = File.join(`npm bin`.chomp, 'mjml')
25
25
  return mjml_bin if check_version(mjml_bin)
26
-
26
+
27
27
  raise RuntimeError, "Couldn't find the MJML binary.. have you run $ npm install mjml?"
28
28
  end
29
29
 
@@ -36,7 +36,7 @@ module Mjml
36
36
 
37
37
  def call(template)
38
38
  compiled_source = haml_handler.call(template)
39
- if template.formats.include?(:mjml)
39
+ if template.formats.include?(:html)
40
40
  "Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe"
41
41
  else
42
42
  compiled_source
@@ -5,7 +5,6 @@ module Mjml
5
5
 
6
6
  initializer "mjml-haml.register_template_handler" do
7
7
  ActionView::Template.register_template_handler :mjml, Mjml::Handler.new
8
- Mime::Type.register "text/html", :mjml
9
8
  end
10
9
  end
11
- end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Mjml
2
- VERSION = "0.1.1"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -5,36 +5,22 @@ class SubdirNotifier < ActionMailer::Base
5
5
 
6
6
  layout false
7
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
8
+ def simple_block
9
+ mail(:to => 'foo@bar.com', :from => "john.doe@example.com")
12
10
  end
13
11
 
14
- def simple_block_and_path(format_type)
12
+ def simple_block_and_path
15
13
  mail(:template_path => 'template_subdir',:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
16
- format.send(format_type)
14
+ format.html
17
15
  end
18
16
  end
19
17
 
20
- def simple_with_path(format_type)
18
+ def simple_with_path
21
19
  mail(:template_path => 'template_subdir',:to => 'foo@bar.com', :from => "john.doe@example.com")
22
20
  end
23
21
 
24
22
  end
25
23
 
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
24
  class MjmlTest < ActiveSupport::TestCase
39
25
 
40
26
  setup do
@@ -50,7 +36,7 @@ class MjmlTest < ActiveSupport::TestCase
50
36
 
51
37
  test 'in a subdir with a block fails' do
52
38
  assert_raises(ActionView::MissingTemplate) do
53
- email = SubdirNotifier.simple_block(:mjml)
39
+ email = SubdirNotifier.simple_block
54
40
  assert_equal "text/html", email.mime_type
55
41
  assert_match(/alternate sub-directory/, email.body.encoded.strip)
56
42
  assert_no_match(/mj-text/, email.body.encoded.strip)
@@ -59,7 +45,7 @@ class MjmlTest < ActiveSupport::TestCase
59
45
 
60
46
  test 'in a subdir with a block and template_path option fails' do
61
47
  assert_raises(ActionView::MissingTemplate) do
62
- email = SubdirNotifier.simple_block_and_path(:mjml)
48
+ email = SubdirNotifier.simple_block_and_path
63
49
  assert_equal "text/html", email.mime_type
64
50
  assert_match(/alternate sub-directory/, email.body.encoded.strip)
65
51
  assert_no_match(/mj-text/, email.body.encoded.strip)
@@ -67,7 +53,7 @@ class MjmlTest < ActiveSupport::TestCase
67
53
  end
68
54
 
69
55
  test 'in a subdir with path' do
70
- email = SubdirNotifier.simple_with_path(:mjml)
56
+ email = SubdirNotifier.simple_with_path
71
57
  assert_equal "text/html", email.mime_type
72
58
  assert_match(/alternate sub-directory/, email.body.encoded.strip)
73
59
  assert_no_match(/mj-text/, email.body.encoded.strip)
@@ -5,29 +5,21 @@ class Notifier < ActionMailer::Base
5
5
 
6
6
  layout false
7
7
 
8
- def contact(recipient, format_type)
8
+ def contact(recipient)
9
9
  @recipient = recipient
10
- mail(:to => @recipient, :from => "john.doe@example.com") do |format|
11
- format.send(format_type)
12
- end
10
+ mail(:to => @recipient, :from => "john.doe@example.com")
13
11
  end
14
12
 
15
- def link(format_type)
16
- mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
17
- format.send(format_type)
18
- end
13
+ def link
14
+ mail(:to => 'foo@bar.com', :from => "john.doe@example.com")
19
15
  end
20
16
 
21
- def user(format_type)
22
- mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
23
- format.send(format_type)
24
- end
17
+ def user
18
+ mail(:to => 'foo@bar.com', :from => "john.doe@example.com")
25
19
  end
26
20
 
27
- def no_partial(format_type)
28
- mail(:to => 'foo@bar.com', :from => "john.doe@example.com") do |format|
29
- format.send(format_type)
30
- end
21
+ def no_partial
22
+ mail(:to => 'foo@bar.com', :from => "john.doe@example.com")
31
23
  end
32
24
 
33
25
  def multiple_format_contact(recipient)
@@ -64,7 +56,7 @@ class MjmlTest < ActiveSupport::TestCase
64
56
  end
65
57
 
66
58
  test "html should be sent as html" do
67
- email = Notifier.contact("you@example.com", :mjml)
59
+ email = Notifier.contact("you@example.com")
68
60
  assert_equal "text/html", email.mime_type
69
61
  assert_no_match(/<mj-body>/, email.body.encoded.strip)
70
62
  assert_match(/<body/, email.body.encoded.strip)
@@ -72,56 +64,16 @@ class MjmlTest < ActiveSupport::TestCase
72
64
  end
73
65
 
74
66
  test 'with partial' do
75
- email = Notifier.user(:mjml)
67
+ email = Notifier.user
76
68
  assert_equal "text/html", email.mime_type
77
69
  assert_match(/Hello Partial/, email.body.encoded.strip)
78
70
  assert_no_match(/mj-text/, email.body.encoded.strip)
79
71
  end
80
72
 
81
73
  test 'without a partial' do
82
- email = Notifier.no_partial(:mjml)
74
+ email = Notifier.no_partial
83
75
  assert_equal "text/html", email.mime_type
84
76
  assert_match(/Hello World/, email.body.encoded.strip)
85
77
  assert_no_match(/mj-text/, email.body.encoded.strip)
86
78
  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
79
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kadu Diógenes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-12 00:00:00.000000000 Z
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.9.0
27
27
  description: Render MJML + Haml template views in Rails
28
28
  email: kadu@fnix.com.br
29
29
  executables: []