mjml-haml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +24 -0
- data/README.md +155 -0
- data/lib/generators/mjml/mailer/mailer_generator.rb +23 -0
- data/lib/generators/mjml/mailer/templates/layout.mjml +1 -0
- data/lib/generators/mjml/mailer/templates/view.mjml +3 -0
- data/lib/mjml-haml.rb +1 -0
- data/lib/mjml.rb +46 -0
- data/lib/mjml/mjmltemplate.rb +12 -0
- data/lib/mjml/parser.rb +81 -0
- data/lib/mjml/railtie.rb +11 -0
- data/lib/mjml/version.rb +3 -0
- data/test/generator_test.rb +16 -0
- data/test/mjml_subdir_test.rb +76 -0
- data/test/mjml_test.rb +127 -0
- data/test/template_test.rb +9 -0
- data/test/test_helper.rb +26 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6e55d749e51a70017144ea604268d8fab1d689c
|
4
|
+
data.tar.gz: bd27dbbbd4cea54aa1316e79f8cff2f7796f6281
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 042d35675cf1759cd37ba0d348cd1bb23735a4f5a6f0e0dd738bcd8fb4809d6ed34b2f4f2886fd3dd910fe02477d03555577a7600d319113c8194f7cc7b1af0f
|
7
|
+
data.tar.gz: 842e03283cb44f4b91694b16e373e6538e8dc63d34e0c76259f73264ee8eb2b0f4211c01f5bc7c0b7653132c723b32bbb161fab4f9057086272d771f93d838ac
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright 2016 Simon Loffler (https://sighmon.com)
|
2
|
+
|
3
|
+
Based on Markerb Gem:
|
4
|
+
|
5
|
+
Copyright 2011-2015 Plataformatec (http://blog.plataformatec.com.br)
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# MJML-Haml
|
2
|
+
|
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
|
+
|
5
|
+
**MJML-Haml** allows you to render HTML e-mails from an [MJML](https://mjml.io) template.
|
6
|
+
|
7
|
+
An example template might look like:
|
8
|
+
|
9
|
+
```haml
|
10
|
+
/ ./app/views/user_mailer/email.mjml
|
11
|
+
%mjml
|
12
|
+
%mj-body
|
13
|
+
%mj-container
|
14
|
+
%mj-section
|
15
|
+
%mj-column
|
16
|
+
%mj-text
|
17
|
+
= render :partial => 'info', :formats => [:html]
|
18
|
+
```
|
19
|
+
|
20
|
+
And the partial `_info.mjml`:
|
21
|
+
|
22
|
+
```haml
|
23
|
+
/ ./app/views/user_mailer/_info.mjml
|
24
|
+
%mj-text= "This is #{@user.username}"
|
25
|
+
```
|
26
|
+
|
27
|
+
* Notice you can use Haml and partials inside the template.
|
28
|
+
|
29
|
+
Your `user_mailer.rb` might look like this::
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# ./app/mailers/user_mailer.rb
|
33
|
+
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
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
Add it to your Gemfile.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem 'mjml-haml'
|
49
|
+
```
|
50
|
+
|
51
|
+
Run the following command to install it:
|
52
|
+
|
53
|
+
```console
|
54
|
+
bundle install
|
55
|
+
```
|
56
|
+
|
57
|
+
Install the MJML parser (optional -g to install it globally):
|
58
|
+
|
59
|
+
```console
|
60
|
+
npm install -g mjml@^2.0
|
61
|
+
```
|
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
|
+
## Deploying with Heroku
|
93
|
+
|
94
|
+
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.
|
95
|
+
|
96
|
+
Once you've installed the [Heroku Toolbelt](https://toolbelt.heroku.com/) you can setup the buildpacks from the commandline:
|
97
|
+
|
98
|
+
`$ heroku buildpacks:set heroku/ruby`
|
99
|
+
|
100
|
+
And then add the Node buildpack to index 1 so it's run first:
|
101
|
+
|
102
|
+
`$ heroku buildpacks:add --index 1 heroku/nodejs`
|
103
|
+
|
104
|
+
Check that's all setup by running:
|
105
|
+
|
106
|
+
`$ heroku buildpacks`
|
107
|
+
|
108
|
+
Next you'll need to setup a `package.json` file in the root, something like this:
|
109
|
+
|
110
|
+
```json
|
111
|
+
{
|
112
|
+
"name": "your-site",
|
113
|
+
"version": "1.0.0",
|
114
|
+
"description": "Now with MJML email templates!",
|
115
|
+
"main": "index.js",
|
116
|
+
"directories": {
|
117
|
+
"doc": "doc",
|
118
|
+
"test": "test"
|
119
|
+
},
|
120
|
+
"dependencies": {
|
121
|
+
"mjml": "^2.0"
|
122
|
+
},
|
123
|
+
"repository": {
|
124
|
+
"type": "git",
|
125
|
+
"url": "git+https://github.com/your-repo/your-site.git"
|
126
|
+
},
|
127
|
+
"keywords": [
|
128
|
+
"mailer"
|
129
|
+
],
|
130
|
+
"author": "Your Name",
|
131
|
+
"license": "ISC",
|
132
|
+
"bugs": {
|
133
|
+
"url": "https://github.com/fnix/mjml-haml/issues"
|
134
|
+
},
|
135
|
+
"homepage": "https://github.com/fnix/mjml-haml"
|
136
|
+
}
|
137
|
+
```
|
138
|
+
|
139
|
+
Then `$ git push heroku master` and it should Just WorkTM.
|
140
|
+
|
141
|
+
## Bug reports
|
142
|
+
|
143
|
+
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.
|
144
|
+
|
145
|
+
[github.com/fnix/mjml-haml/issues](https://github.com/fnix/mjml-haml/issues)
|
146
|
+
|
147
|
+
## Maintainers
|
148
|
+
|
149
|
+
* Kadu Diógenes [github.com/cerdiogenes](https://github.com/cerdiogenes)
|
150
|
+
|
151
|
+
## License
|
152
|
+
|
153
|
+
MIT License. Copyright 2016 Kadu Diógenes.
|
154
|
+
|
155
|
+
Lovingly built on [github.com/sighmon/mjml-rails](https://github.com/sighmon/mjml-rails)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'generators/haml/mailer/mailer_generator'
|
2
|
+
|
3
|
+
module Mjml
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < Haml::Generators::MailerGenerator
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def format
|
11
|
+
nil # Our templates have no format
|
12
|
+
end
|
13
|
+
|
14
|
+
def formats
|
15
|
+
[format]
|
16
|
+
end
|
17
|
+
|
18
|
+
def handler
|
19
|
+
:mjml
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
= yield
|
data/lib/mjml-haml.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "mjml"
|
data/lib/mjml.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "action_view"
|
2
|
+
require "haml"
|
3
|
+
require "haml/template/plugin"
|
4
|
+
require "mjml/mjmltemplate"
|
5
|
+
require "mjml/railtie"
|
6
|
+
require "rubygems"
|
7
|
+
|
8
|
+
module Mjml
|
9
|
+
|
10
|
+
def self.check_version(bin)
|
11
|
+
begin
|
12
|
+
Gem::Dependency.new('','~> 2.0').match?('',`#{bin} --version`)
|
13
|
+
rescue
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.discover_mjml_bin
|
19
|
+
# Check for a global install of MJML binary
|
20
|
+
mjml_bin = 'mjml'
|
21
|
+
return mjml_bin if check_version(mjml_bin)
|
22
|
+
|
23
|
+
# Check for a local install of MJML binary
|
24
|
+
mjml_bin = File.join(`npm bin`.chomp, 'mjml')
|
25
|
+
return mjml_bin if check_version(mjml_bin)
|
26
|
+
|
27
|
+
raise RuntimeError, "Couldn't find the MJML binary.. have you run $ npm install mjml?"
|
28
|
+
end
|
29
|
+
|
30
|
+
BIN = discover_mjml_bin
|
31
|
+
|
32
|
+
class Handler
|
33
|
+
def haml_handler
|
34
|
+
@haml_handler ||= ActionView::Template.registered_template_handler(:haml)
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(template)
|
38
|
+
compiled_source = haml_handler.call(template)
|
39
|
+
if template.formats.include?(:mjml)
|
40
|
+
"Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe"
|
41
|
+
else
|
42
|
+
compiled_source
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/mjml/parser.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Mjml
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
# Create new parser
|
5
|
+
#
|
6
|
+
# @param input [String] The string to transform in html
|
7
|
+
def initialize input
|
8
|
+
file = File.open(in_tmp_file, 'w')
|
9
|
+
file.write(input)
|
10
|
+
file.close
|
11
|
+
end
|
12
|
+
|
13
|
+
# Render mjml template
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
def render
|
17
|
+
result = run
|
18
|
+
remove_tmp_files
|
19
|
+
result
|
20
|
+
rescue
|
21
|
+
|
22
|
+
""
|
23
|
+
end
|
24
|
+
|
25
|
+
# Exec mjml command
|
26
|
+
#
|
27
|
+
# @return [String] The result as string
|
28
|
+
def run
|
29
|
+
command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file}"
|
30
|
+
# puts command
|
31
|
+
`#{command}`
|
32
|
+
file = File.open(out_tmp_file, 'r')
|
33
|
+
str = file.read
|
34
|
+
file.close
|
35
|
+
str
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Remove tmp files
|
41
|
+
#
|
42
|
+
# @return nil
|
43
|
+
def remove_tmp_files
|
44
|
+
FileUtils.rm(in_tmp_file)
|
45
|
+
FileUtils.rm(out_tmp_file)
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return tmp dir
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
def tmp_dir
|
53
|
+
"/tmp"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Get parser tpm file to store result
|
57
|
+
#
|
58
|
+
# @return [String]
|
59
|
+
def out_tmp_file
|
60
|
+
|
61
|
+
@_out_tmp_file ||= "#{tmp_dir}/out_#{(0...8).map { (65 + rand(26)).chr }.join}.html"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get parser tpm file to get result
|
65
|
+
#
|
66
|
+
# @return [String]
|
67
|
+
def in_tmp_file
|
68
|
+
|
69
|
+
@_in_tmp_file ||= "#{tmp_dir}/in_#{(0...8).map { (65 + rand(26)).chr }.join}.mjml"
|
70
|
+
# puts @_in_tmp_file
|
71
|
+
return @_in_tmp_file
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get mjml bin path
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def mjml_bin
|
78
|
+
Mjml::BIN
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/mjml/railtie.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Mjml
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
config.mjml = Mjml
|
4
|
+
config.app_generators.mailer :template_engine => :mjml
|
5
|
+
|
6
|
+
initializer "mjml-haml.register_template_handler" do
|
7
|
+
ActionView::Template.register_template_handler :mjml, Mjml::Handler.new
|
8
|
+
Mime::Type.register "text/html", :mjml
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/mjml/version.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "generators/mjml/mailer/mailer_generator"
|
3
|
+
|
4
|
+
class GeneratorTest < Rails::Generators::TestCase
|
5
|
+
tests Mjml::Generators::MailerGenerator
|
6
|
+
destination File.expand_path("../tmp", __FILE__)
|
7
|
+
setup :prepare_destination
|
8
|
+
|
9
|
+
test "assert all views are properly created with given name" do
|
10
|
+
run_generator %w(notifier foo bar baz)
|
11
|
+
|
12
|
+
assert_file "app/views/notifier/foo.mjml"
|
13
|
+
assert_file "app/views/notifier/bar.mjml"
|
14
|
+
assert_file "app/views/notifier/baz.mjml"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,76 @@
|
|
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
|
data/test/mjml_test.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Notifier < ActionMailer::Base
|
4
|
+
self.view_paths = File.expand_path("../views", __FILE__)
|
5
|
+
|
6
|
+
layout false
|
7
|
+
|
8
|
+
def contact(recipient, format_type)
|
9
|
+
@recipient = recipient
|
10
|
+
mail(:to => @recipient, :from => "john.doe@example.com") do |format|
|
11
|
+
format.send(format_type)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
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
|
19
|
+
end
|
20
|
+
|
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
|
25
|
+
end
|
26
|
+
|
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
|
31
|
+
end
|
32
|
+
|
33
|
+
def multiple_format_contact(recipient)
|
34
|
+
@recipient = recipient
|
35
|
+
mail(:to => @recipient, :from => "john.doe@example.com", :template => "contact") do |format|
|
36
|
+
format.text { render 'contact' }
|
37
|
+
format.html { render 'contact' }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# class TestRenderer < ActionView::PartialRenderer
|
43
|
+
# attr_accessor :show_text
|
44
|
+
# def initialize(render_options = {})
|
45
|
+
# @show_text = render_options.delete(:show_text)
|
46
|
+
# super(render_options)
|
47
|
+
# end
|
48
|
+
|
49
|
+
# def normal_text(text)
|
50
|
+
# show_text ? "TEST #{text}" : "TEST"
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
class MjmlTest < ActiveSupport::TestCase
|
55
|
+
|
56
|
+
setup do
|
57
|
+
@original_renderer = Mjml.renderer
|
58
|
+
@original_processing_options = Mjml.processing_options
|
59
|
+
end
|
60
|
+
|
61
|
+
teardown do
|
62
|
+
Mjml.renderer = @original_renderer
|
63
|
+
Mjml.processing_options = @original_processing_options
|
64
|
+
end
|
65
|
+
|
66
|
+
test "html should be sent as html" do
|
67
|
+
email = Notifier.contact("you@example.com", :mjml)
|
68
|
+
assert_equal "text/html", email.mime_type
|
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="https://github.com/fnix/mjml-haml">haml-rails</a></p>', email.body.encoded.strip)
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'with partial' do
|
75
|
+
email = Notifier.user(:mjml)
|
76
|
+
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
|
+
|
81
|
+
test 'without a partial' do
|
82
|
+
email = Notifier.no_partial(:mjml)
|
83
|
+
assert_equal "text/html", email.mime_type
|
84
|
+
assert_match(/Hello World/, email.body.encoded.strip)
|
85
|
+
assert_no_match(/mj-text/, email.body.encoded.strip)
|
86
|
+
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
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class MjmlTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'with Mjmltemplate processor' do
|
6
|
+
assert_not_equal "<mj-body></mj-body>", Mjml::Mjmltemplate.to_html("<mjml><mj-body><mj-container><mj-section><mj-column></mj-column></mj-section></mj-container></mj-body></mjml>").strip
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require "minitest/autorun"
|
6
|
+
require "active_support/test_case"
|
7
|
+
|
8
|
+
require "action_mailer"
|
9
|
+
require "rails/railtie"
|
10
|
+
require "rails/generators"
|
11
|
+
require "rails/generators/test_case"
|
12
|
+
|
13
|
+
# require "minitest/reporters"
|
14
|
+
# Minitest::Reporters.use!
|
15
|
+
|
16
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
17
|
+
require "mjml"
|
18
|
+
Mjml::Railtie.run_initializers
|
19
|
+
|
20
|
+
ActiveSupport::TestCase.test_order = :sorted if ActiveSupport::TestCase.respond_to? :test_order=
|
21
|
+
|
22
|
+
# Avoid annoying warning from I18n.
|
23
|
+
I18n.enforce_available_locales = false
|
24
|
+
|
25
|
+
ActionMailer::Base.delivery_method = :test
|
26
|
+
ActionMailer::Base.perform_deliveries = true
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mjml-haml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kadu Diógenes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Render MJML + Haml template views in Rails
|
28
|
+
email: kadu@fnix.com.br
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/generators/mjml/mailer/mailer_generator.rb
|
36
|
+
- lib/generators/mjml/mailer/templates/layout.mjml
|
37
|
+
- lib/generators/mjml/mailer/templates/view.mjml
|
38
|
+
- lib/mjml-haml.rb
|
39
|
+
- lib/mjml.rb
|
40
|
+
- lib/mjml/mjmltemplate.rb
|
41
|
+
- lib/mjml/parser.rb
|
42
|
+
- lib/mjml/railtie.rb
|
43
|
+
- lib/mjml/version.rb
|
44
|
+
- test/generator_test.rb
|
45
|
+
- test/mjml_subdir_test.rb
|
46
|
+
- test/mjml_test.rb
|
47
|
+
- test/template_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
homepage: https://github.com/fnix/mjml-haml
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message: "Don't forget to install MJML e.g. \n$ npm install -g mjml"
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.4.8
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: MJML + Haml templates
|
73
|
+
test_files:
|
74
|
+
- test/mjml_subdir_test.rb
|
75
|
+
- test/template_test.rb
|
76
|
+
- test/mjml_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- test/generator_test.rb
|