mjml-rails 4.4.0 → 4.6.1
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 +54 -32
- data/lib/mjml-rails.rb +1 -1
- data/lib/mjml.rb +70 -53
- data/lib/mjml/handler.rb +36 -0
- data/lib/mjml/parser.rb +6 -16
- data/lib/mjml/railtie.rb +5 -0
- data/lib/mjml/version.rb +1 -1
- data/test/mjml_test.rb +66 -0
- data/test/parser_test.rb +21 -30
- data/test/test_helper.rb +17 -0
- metadata +30 -32
- metadata.gz.sig +1 -3
- data/lib/mjml/mjmltemplate.rb +0 -12
- data/test/template_test.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a845d39f307dd7d452b0766805154e622aecaed3bbb3b4d392ead880939dc04
|
|
4
|
+
data.tar.gz: 13a7793222a8253ce62dd97f2a225379615515225e7f987deb23f5a93d6dbbfd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f05c5580304ececa283ea79e17b61c7a281ce9b327d8aa3c73bacbdeaa8873049f3491243f03964e8fe0bf33f4c4e9ff2c0c70c2424100ae23f7d1a26d3322da
|
|
7
|
+
data.tar.gz: 111b70710d670a442564aa877652f3711c0ad9c934e1be8edd24a6fc0011f7019c3c9aaa58abec7cfcc338b7ca5ecac2aa6c3e3bd9af30cbb68402dcfa5a3165
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# MJML-Rails
|
|
2
2
|
|
|
3
|
-
[](https://github.com/sighmon/mjml-rails/actions?query=workflow%3Atest+branch%3Amaster) [](https://badge.fury.io/rb/mjml-rails)
|
|
4
4
|
|
|
5
|
-
**MJML-Rails** allows you to render HTML
|
|
5
|
+
**MJML-Rails** allows you to render HTML emails from an [MJML](https://mjml.io) template.
|
|
6
6
|
|
|
7
7
|
**Note**: As of MJML 4.3.0 you can no longer use `<mj-text>` directly inside an `<mj-body>`, wrap it in `<mj-section><mj-column>`.
|
|
8
8
|
|
|
@@ -66,57 +66,79 @@ Run the following command to install it:
|
|
|
66
66
|
bundle install
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Add the MJML parser to your project with your favourite package manager:
|
|
70
70
|
|
|
71
71
|
```console
|
|
72
|
-
|
|
72
|
+
# with npm
|
|
73
|
+
npm install mjml
|
|
74
|
+
|
|
75
|
+
# with yarn
|
|
76
|
+
yarn add mjml
|
|
73
77
|
```
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
MJML-Rails falls back to a global installation of MJML but it is strongly recommended to add MJML directly to your project.
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
You'll need at least Node.js version 6 for MJML to function properly.
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
MJML-Rails has the following settings with defaults:
|
|
86
|
+
|
|
87
|
+
- `template_language: :erb`
|
|
88
|
+
|
|
89
|
+
ERB can be used inside MJML templates by default. Possible values are all template languages that you have installed, e.g. `:haml` or `:slim`.
|
|
90
|
+
|
|
91
|
+
**Note:** If you’re using Haml/Slim layouts, please don’t put `<mjml>` in comments in your partial. Read more at [#34](https://github.com/sighmon/mjml-rails/issues/34).
|
|
92
|
+
|
|
93
|
+
- `raise_render_exception: true`
|
|
94
|
+
|
|
95
|
+
Exceptions will be raised and passed to your application by default.
|
|
96
|
+
|
|
97
|
+
Beware that setting it to `false` leads to an empty html email when an exception is raised, so only set this to `false` if you do not rely on html (e.g. you have a text fallback for your emails).
|
|
98
|
+
|
|
99
|
+
- `minify: false`
|
|
100
|
+
|
|
101
|
+
- `beautify: true`
|
|
85
102
|
|
|
86
|
-
|
|
103
|
+
- `validation_level: "strict"`
|
|
104
|
+
|
|
105
|
+
MJML-Rails will raise an exception on any template error by default.
|
|
106
|
+
|
|
107
|
+
If set to `soft`, MJML will render invalid templates and ignore invalid parts. This means in case of an invalid template those invalid parts will be missing from the output.
|
|
108
|
+
|
|
109
|
+
See [MJML validation documentation](https://github.com/mjmlio/mjml/tree/master/packages/mjml-validator#validating-mjml) for all possible values.
|
|
110
|
+
|
|
111
|
+
- `mjml_binary: nil`
|
|
112
|
+
|
|
113
|
+
This can be used to specify the path to a custom MJML binary if it is not detected automatically (shouldn't be needed).
|
|
114
|
+
|
|
115
|
+
- `mjml_binary_version_support: "4."`
|
|
116
|
+
|
|
117
|
+
MJML-Rails checks the version of the MJML binary and fails if it does not start with this version, e.g. if an old version is installed by accident.
|
|
87
118
|
|
|
88
|
-
If there are configurations you'd like change:
|
|
89
|
-
- render errors: defaults to `true` (errors raised)
|
|
90
|
-
- minify: defaults to `false` (not minified)
|
|
91
|
-
- beautify: defaults to `true` (beautified)
|
|
92
|
-
- validation_level: defaults to `soft` (MJML syntax validation)
|
|
93
119
|
|
|
94
120
|
```ruby
|
|
95
121
|
# config/initializers/mjml.rb
|
|
96
122
|
Mjml.setup do |config|
|
|
97
|
-
#
|
|
98
|
-
config.
|
|
123
|
+
# Use :haml as a template language
|
|
124
|
+
config.template_language = :haml
|
|
99
125
|
|
|
100
|
-
#
|
|
126
|
+
# Ignore errors silently
|
|
127
|
+
config.raise_render_exception = false
|
|
128
|
+
|
|
129
|
+
# Optimize the size of your emails
|
|
101
130
|
config.beautify = false
|
|
102
131
|
config.minify = true
|
|
103
|
-
config.validation_level = "strict"
|
|
104
|
-
end
|
|
105
|
-
```
|
|
106
132
|
|
|
107
|
-
|
|
133
|
+
# Render MJML templates with errors
|
|
134
|
+
config.validation_level = "soft"
|
|
108
135
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Mjml.setup do |config|
|
|
136
|
+
# Use custom MJML binary with custom version
|
|
137
|
+
config.mjml_binary = "/path/to/custom/mjml"
|
|
112
138
|
config.mjml_binary_version_supported = "3.3.5"
|
|
113
139
|
end
|
|
114
|
-
# If you set a different MJML binary version, you need to re-discover the binary
|
|
115
|
-
Mjml::BIN = Mjml.discover_mjml_bin
|
|
116
140
|
```
|
|
117
141
|
|
|
118
|
-
**Note:** If you set a different MJML binary you’ll see warnings in your logs of `already initialized constant Mjml::BIN`. Read more: [#39](https://github.com/sighmon/mjml-rails/issues/39#issuecomment-429151908)
|
|
119
|
-
|
|
120
142
|
### MJML v3.x & v4.x support
|
|
121
143
|
|
|
122
144
|
Version 4.x of this gem brings support for MJML 4.x
|
data/lib/mjml-rails.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require "mjml"
|
|
1
|
+
require "mjml"
|
data/lib/mjml.rb
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
require "rails/version"
|
|
2
|
-
require "action_view"
|
|
3
|
-
require "action_view/template"
|
|
4
|
-
require "mjml/mjmltemplate"
|
|
5
|
-
require "mjml/railtie"
|
|
6
1
|
require "rubygems"
|
|
7
2
|
require "open3"
|
|
8
3
|
|
|
4
|
+
require "mjml/handler"
|
|
5
|
+
require "mjml/parser"
|
|
6
|
+
|
|
7
|
+
require "mjml/railtie" if defined?(Rails)
|
|
8
|
+
|
|
9
9
|
module Mjml
|
|
10
|
-
mattr_accessor
|
|
10
|
+
mattr_accessor \
|
|
11
|
+
:beautify,
|
|
12
|
+
:minify,
|
|
13
|
+
:mjml_binary,
|
|
14
|
+
:mjml_binary_error_string,
|
|
15
|
+
:mjml_binary_version_supported,
|
|
16
|
+
:raise_render_exception,
|
|
17
|
+
:template_language,
|
|
18
|
+
:validation_level
|
|
19
|
+
|
|
20
|
+
mattr_writer :valid_mjml_binary
|
|
11
21
|
|
|
12
22
|
@@template_language = :erb
|
|
13
23
|
@@raise_render_exception = true
|
|
@@ -15,71 +25,78 @@ module Mjml
|
|
|
15
25
|
@@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
|
|
16
26
|
@@beautify = true
|
|
17
27
|
@@minify = false
|
|
18
|
-
@@validation_level = "
|
|
28
|
+
@@validation_level = "strict"
|
|
19
29
|
|
|
20
30
|
def self.check_version(bin)
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
|
32
|
+
status.success? && stdout.include?("mjml-core: #{Mjml.mjml_binary_version_supported}")
|
|
33
|
+
rescue StandardError
|
|
23
34
|
false
|
|
24
35
|
end
|
|
25
36
|
|
|
26
|
-
def self.
|
|
27
|
-
#
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
def self.run_mjml(args, mjml_bin: valid_mjml_binary)
|
|
38
|
+
Open3.capture3("#{mjml_bin} #{args}")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.valid_mjml_binary
|
|
42
|
+
@@valid_mjml_binary ||=
|
|
43
|
+
check_for_custom_mjml_binary ||
|
|
44
|
+
check_for_yarn_mjml_binary ||
|
|
45
|
+
check_for_npm_mjml_binary ||
|
|
46
|
+
check_for_global_mjml_binary
|
|
47
|
+
|
|
48
|
+
return @@valid_mjml_binary if @@valid_mjml_binary
|
|
30
49
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
puts Mjml.mjml_binary_error_string
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.check_for_custom_mjml_binary
|
|
54
|
+
if const_defined?('BIN') && Mjml::BIN.present?
|
|
55
|
+
logger.warn('Setting `Mjml::BIN` is deprecated and will be removed in a future version! Please use `Mjml.mjml_binary=` instead.')
|
|
56
|
+
self.mjml_binary = Mjml::BIN
|
|
57
|
+
remove_const 'BIN'
|
|
36
58
|
end
|
|
37
59
|
|
|
60
|
+
return unless mjml_binary.present?
|
|
61
|
+
|
|
62
|
+
return mjml_binary if check_version(mjml_binary)
|
|
63
|
+
|
|
64
|
+
raise "MJML.mjml_binary is set to '#{mjml_binary}' but MJML-Rails could not validate that it is a valid MJML binary. Please check your configuration."
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.check_for_yarn_mjml_binary
|
|
68
|
+
yarn_bin = `which yarn`.chomp
|
|
69
|
+
return unless yarn_bin.present?
|
|
70
|
+
|
|
71
|
+
mjml_bin = "#{yarn_bin} run mjml"
|
|
72
|
+
return mjml_bin if check_version(mjml_bin)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.check_for_npm_mjml_binary
|
|
76
|
+
npm_bin = `which npm`.chomp
|
|
77
|
+
return unless npm_bin.present? && (installer_path = bin_path_from(npm_bin)).present?
|
|
78
|
+
|
|
38
79
|
mjml_bin = File.join(installer_path, 'mjml')
|
|
39
80
|
return mjml_bin if check_version(mjml_bin)
|
|
81
|
+
end
|
|
40
82
|
|
|
41
|
-
|
|
42
|
-
|
|
83
|
+
def self.check_for_global_mjml_binary
|
|
84
|
+
mjml_bin = `which mjml`.chomp
|
|
85
|
+
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
|
|
43
86
|
end
|
|
44
87
|
|
|
45
88
|
def self.bin_path_from(package_manager)
|
|
46
|
-
|
|
47
|
-
|
|
89
|
+
stdout, _, status = Open3.capture3("#{package_manager} bin")
|
|
90
|
+
|
|
91
|
+
return unless status.success?
|
|
92
|
+
|
|
93
|
+
stdout.chomp
|
|
48
94
|
rescue Errno::ENOENT # package manager is not installed
|
|
49
95
|
nil
|
|
50
96
|
end
|
|
51
97
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class Handler
|
|
55
|
-
def template_handler
|
|
56
|
-
@_template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Optional second source parameter to make it work with Rails >= 6:
|
|
60
|
-
# Beginning with Rails 6 template handlers get the source of the template as the second
|
|
61
|
-
# parameter.
|
|
62
|
-
def call(template, source = nil)
|
|
63
|
-
compiled_source =
|
|
64
|
-
if Rails::VERSION::MAJOR >= 6
|
|
65
|
-
template_handler.call(template, source)
|
|
66
|
-
else
|
|
67
|
-
template_handler.call(template)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
|
|
71
|
-
# If we get here and template source doesn't start with one it means
|
|
72
|
-
# that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
|
|
73
|
-
# Therefore we skip MJML processing and return raw compiled source. It will be processed
|
|
74
|
-
# by MJML library when top-level layout/template is rendered
|
|
75
|
-
#
|
|
76
|
-
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/guide.md#mjml
|
|
77
|
-
if compiled_source =~ /<mjml(.+)?>/i
|
|
78
|
-
"Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe"
|
|
79
|
-
else
|
|
80
|
-
compiled_source
|
|
81
|
-
end
|
|
82
|
-
end
|
|
98
|
+
def self.discover_mjml_bin
|
|
99
|
+
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
|
|
83
100
|
end
|
|
84
101
|
|
|
85
102
|
def self.setup
|
data/lib/mjml/handler.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'action_view'
|
|
2
|
+
require 'action_view/template'
|
|
3
|
+
require 'rails/version'
|
|
4
|
+
|
|
5
|
+
module Mjml
|
|
6
|
+
class Handler
|
|
7
|
+
def template_handler
|
|
8
|
+
@template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Optional second source parameter to make it work with Rails >= 6:
|
|
12
|
+
# Beginning with Rails 6 template handlers get the source of the template as the second
|
|
13
|
+
# parameter.
|
|
14
|
+
def call(template, source = nil)
|
|
15
|
+
compiled_source =
|
|
16
|
+
if Rails::VERSION::MAJOR >= 6
|
|
17
|
+
template_handler.call(template, source)
|
|
18
|
+
else
|
|
19
|
+
template_handler.call(template)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
|
|
23
|
+
# If we get here and template source doesn't start with one it means
|
|
24
|
+
# that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
|
|
25
|
+
# Therefore we skip MJML processing and return raw compiled source. It will be processed
|
|
26
|
+
# by MJML library when top-level layout/template is rendered
|
|
27
|
+
#
|
|
28
|
+
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/guide.md#mjml
|
|
29
|
+
if compiled_source =~ /<mjml.*?>/i
|
|
30
|
+
"Mjml::Parser.new(begin;#{compiled_source};end).render.html_safe"
|
|
31
|
+
else
|
|
32
|
+
compiled_source
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/mjml/parser.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'open3'
|
|
2
|
-
|
|
3
1
|
module Mjml
|
|
4
2
|
class Parser
|
|
5
3
|
class ParseError < StandardError; end
|
|
@@ -10,7 +8,7 @@ module Mjml
|
|
|
10
8
|
#
|
|
11
9
|
# @param input [String] The string to transform in html
|
|
12
10
|
def initialize input
|
|
13
|
-
raise Mjml.mjml_binary_error_string unless
|
|
11
|
+
raise Mjml.mjml_binary_error_string unless Mjml.valid_mjml_binary
|
|
14
12
|
@input = input
|
|
15
13
|
end
|
|
16
14
|
|
|
@@ -33,22 +31,14 @@ module Mjml
|
|
|
33
31
|
# Exec mjml command
|
|
34
32
|
#
|
|
35
33
|
# @return [String] The result as string
|
|
36
|
-
def run(in_tmp_file, beautify=true, minify=false, validation_level="
|
|
34
|
+
def run(in_tmp_file, beautify=true, minify=false, validation_level="strict")
|
|
37
35
|
Tempfile.create(["out", ".html"]) do |out_tmp_file|
|
|
38
|
-
command = "
|
|
39
|
-
_,
|
|
40
|
-
raise ParseError.new(stderr.
|
|
36
|
+
command = "-r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
|
|
37
|
+
_, stderr, status = Mjml.run_mjml(command)
|
|
38
|
+
raise ParseError.new(stderr.chomp) unless status.success?
|
|
39
|
+
Mjml.logger.warn(stderr.chomp) unless stderr.blank?
|
|
41
40
|
out_tmp_file.read
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
|
-
|
|
45
|
-
private
|
|
46
|
-
|
|
47
|
-
# Get mjml bin path
|
|
48
|
-
#
|
|
49
|
-
# @return [String]
|
|
50
|
-
def mjml_bin
|
|
51
|
-
Mjml::BIN
|
|
52
|
-
end
|
|
53
43
|
end
|
|
54
44
|
end
|
data/lib/mjml/railtie.rb
CHANGED
data/lib/mjml/version.rb
CHANGED
data/test/mjml_test.rb
CHANGED
|
@@ -13,6 +13,15 @@ class NotifierMailer < ActionMailer::Base
|
|
|
13
13
|
format.html
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
+
|
|
17
|
+
def invalid_template(recipient)
|
|
18
|
+
@recipient = recipient
|
|
19
|
+
|
|
20
|
+
mail(to: @recipient, from: "app@example.com") do |format|
|
|
21
|
+
format.html
|
|
22
|
+
format.text
|
|
23
|
+
end
|
|
24
|
+
end
|
|
16
25
|
end
|
|
17
26
|
|
|
18
27
|
class NoLayoutMailer < ActionMailer::Base
|
|
@@ -58,6 +67,22 @@ class NotifierMailerTest < ActiveSupport::TestCase
|
|
|
58
67
|
assert email.text_part.body.match(/We inform you about something/)
|
|
59
68
|
assert email.text_part.body.match(%r{Please visit https://www.example.com})
|
|
60
69
|
end
|
|
70
|
+
|
|
71
|
+
test "Invalid template raises error with validation level strict" do
|
|
72
|
+
with_settings(validation_level: 'strict') do
|
|
73
|
+
email = NotifierMailer.invalid_template("user@example.com")
|
|
74
|
+
assert_raise(ActionView::Template::Error) { email.html_part.body.to_s }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
test "Invalid template gets compiled with validation level soft" do
|
|
79
|
+
with_settings(validation_level: 'soft') do
|
|
80
|
+
email = NotifierMailer.invalid_template("user@example.com")
|
|
81
|
+
assert email.text_part.body.match(/This is valid/)
|
|
82
|
+
assert email.html_part.body.match(/This is valid/)
|
|
83
|
+
refute email.html_part.body.match(/This is invalid/)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
61
86
|
end
|
|
62
87
|
|
|
63
88
|
class NotifierMailerTest < ActiveSupport::TestCase
|
|
@@ -87,3 +112,44 @@ class NotifierMailerTest < ActiveSupport::TestCase
|
|
|
87
112
|
refute email.body.match(/tracking-code-123/)
|
|
88
113
|
end
|
|
89
114
|
end
|
|
115
|
+
|
|
116
|
+
describe Mjml do
|
|
117
|
+
describe '#valid_mjml_binary' do
|
|
118
|
+
before do
|
|
119
|
+
Mjml.mjml_binary = nil
|
|
120
|
+
Mjml.valid_mjml_binary = nil
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
after do
|
|
124
|
+
Mjml.mjml_binary = nil
|
|
125
|
+
Mjml.valid_mjml_binary = nil
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'can be set to a custom value with mjml_binary if version is correct' do
|
|
129
|
+
Mjml.mjml_binary = 'some custom value'
|
|
130
|
+
Mjml.stub :check_version, true do
|
|
131
|
+
expect(Mjml.valid_mjml_binary).must_equal 'some custom value'
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'raises an error if mjml_binary is invalid' do
|
|
136
|
+
Mjml.mjml_binary = 'some custom value'
|
|
137
|
+
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
|
138
|
+
expect(err.message).must_match(/MJML\.mjml_binary is set to 'some custom value' but MJML-Rails could not validate that it is a valid MJML binary/)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'honors old Mjml::BIN way of setting custom binary' do
|
|
142
|
+
Mjml::BIN = 'set by old way'
|
|
143
|
+
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
|
144
|
+
expect(err.message).must_match(/MJML\.mjml_binary is set to 'set by old way' but MJML-Rails could not validate that it is a valid MJML binary/)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'ignores empty Mjml::BIN' do
|
|
148
|
+
Mjml::BIN = ''
|
|
149
|
+
Mjml.mjml_binary = 'set by mjml_binary'
|
|
150
|
+
|
|
151
|
+
err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
|
|
152
|
+
expect(err.message).must_match(/MJML\.mjml_binary is set to 'set by mjml_binary' but MJML-Rails could not validate that it is a valid MJML binary/)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
data/test/parser_test.rb
CHANGED
|
@@ -13,61 +13,52 @@ describe Mjml::Parser do
|
|
|
13
13
|
parser.stubs(:run).raises(error)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'raises exception' do
|
|
24
|
-
-> { parser.render }.must_raise(custom_error_class, error.message)
|
|
16
|
+
it 'raises exception with render exception enabled' do
|
|
17
|
+
with_settings(raise_render_exception: true) do
|
|
18
|
+
err = expect { parser.render }.must_raise(custom_error_class)
|
|
19
|
+
expect(err.message).must_equal error.message
|
|
25
20
|
end
|
|
26
21
|
end
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
config.raise_render_exception = false
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'returns empty string' do
|
|
36
|
-
parser.render.must_equal ''
|
|
23
|
+
it 'returns empty string with exception raising disabled' do
|
|
24
|
+
with_settings(raise_render_exception: false) do
|
|
25
|
+
expect(parser.render).must_equal ''
|
|
37
26
|
end
|
|
38
27
|
end
|
|
39
28
|
end
|
|
40
29
|
|
|
41
30
|
describe 'can read beautify, minify, and validation_level configs' do
|
|
42
|
-
it '
|
|
31
|
+
it 'uses defaults if no config is set' do
|
|
43
32
|
expect(Mjml.beautify).must_equal(true)
|
|
44
33
|
expect(Mjml.minify).must_equal(false)
|
|
45
|
-
expect(Mjml.validation_level).must_equal('
|
|
34
|
+
expect(Mjml.validation_level).must_equal('strict')
|
|
46
35
|
end
|
|
47
36
|
|
|
48
|
-
it '
|
|
37
|
+
it 'uses setup config' do
|
|
49
38
|
Mjml.setup do |config|
|
|
50
39
|
config.beautify = false
|
|
51
40
|
config.minify = true
|
|
52
|
-
config.validation_level = '
|
|
41
|
+
config.validation_level = 'soft'
|
|
53
42
|
end
|
|
54
43
|
|
|
55
44
|
expect(Mjml.beautify).must_equal(false)
|
|
56
45
|
expect(Mjml.minify).must_equal(true)
|
|
57
|
-
expect(Mjml.validation_level).must_equal('
|
|
46
|
+
expect(Mjml.validation_level).must_equal('soft')
|
|
47
|
+
|
|
48
|
+
Mjml.setup do |config|
|
|
49
|
+
config.beautify = true
|
|
50
|
+
config.minify = false
|
|
51
|
+
config.validation_level = 'strict'
|
|
52
|
+
end
|
|
58
53
|
end
|
|
59
54
|
end
|
|
60
55
|
end
|
|
61
56
|
|
|
62
57
|
describe '#run' do
|
|
63
|
-
describe 'when shell command
|
|
64
|
-
let(:error) { 'shell error' }
|
|
65
|
-
let(:stderr) { mock('stderr', eof?: false, read: error) }
|
|
66
|
-
|
|
67
|
-
before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
|
|
68
|
-
|
|
58
|
+
describe 'when shell command failed' do
|
|
69
59
|
it 'raises exception' do
|
|
70
|
-
|
|
60
|
+
err = expect { parser.run "/tmp/non_existent_file.mjml" }.must_raise(Mjml::Parser::ParseError)
|
|
61
|
+
expect(err.message).must_include 'Command line error'
|
|
71
62
|
end
|
|
72
63
|
end
|
|
73
64
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -25,3 +25,20 @@ I18n.enforce_available_locales = false
|
|
|
25
25
|
|
|
26
26
|
ActionMailer::Base.delivery_method = :test
|
|
27
27
|
ActionMailer::Base.perform_deliveries = true
|
|
28
|
+
|
|
29
|
+
def with_settings(settings)
|
|
30
|
+
original_settings =
|
|
31
|
+
settings.each_with_object({}) do |(key, _), agg|
|
|
32
|
+
agg[key] = Mjml.public_send(key)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
settings.each do |key, value|
|
|
36
|
+
Mjml.public_send("#{key}=", value)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
yield
|
|
40
|
+
ensure
|
|
41
|
+
original_settings.each do |key, value|
|
|
42
|
+
Mjml.public_send("#{key}=", value)
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mjml-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Simon Loffler
|
|
8
8
|
- Steven Pickles
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain:
|
|
12
12
|
- |
|
|
13
13
|
-----BEGIN CERTIFICATE-----
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
MIIEKDCCApCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAfMR0wGwYDVQQDDBR5b3Vy
|
|
15
|
+
L0RDPWVtYWlsL0RDPWNvbTAeFw0yMDExMjIwNTA5MjJaFw0yMTExMjIwNTA5MjJa
|
|
16
|
+
MB8xHTAbBgNVBAMMFHlvdXIvREM9ZW1haWwvREM9Y29tMIIBojANBgkqhkiG9w0B
|
|
17
|
+
AQEFAAOCAY8AMIIBigKCAYEAmYphpc2KJNqmKAAKTE53F59mnVv2aW8r5NFDZqG0
|
|
18
|
+
DF6V8N5rdWanaMLlo1HyU9r7D1f/h7O/LnjZemvgH6MROd19Qe64GIdIPRXC/ZxM
|
|
19
|
+
cTBNC7GMoZf9LomBmg8sXnoL0Z2enUP6BV716I00EecxrEb8drtvZlRwjUgRcZrv
|
|
20
|
+
iEaanYYp1Sw3+koyOsof/xYb3Pn2TAh9UE58lbVDpf88zc74ij3Vs3+LW/k+jZzh
|
|
21
|
+
pzo7qq47XeVNGWtVDGm3dk8QLrIyQdk28B2ZRJ+HeuLEgx7ASDYFVZc05QlAjehS
|
|
22
|
+
4k37CIgF0ODDnscoSNNb6toFzaiD/kU9+ManRj871qOAMDlcX6cM4Wl08xfXZsxh
|
|
23
|
+
VgmIv7vFoSkBDw6t3xrHGD1HiYYQl2tFQsS9D/X9I+1ArChtUTSxEyN6VGP1YVd6
|
|
24
|
+
jsf4A/eMNRO6+udEQjYHontemi1xFeeyb6PDbP14oLMOls73fKvGZ3eW5uO3qCOb
|
|
25
|
+
tKhPFou/w1GgU3vR3O26Q3EZAgMBAAGjbzBtMAkGA1UdEwQCMAAwCwYDVR0PBAQD
|
|
26
|
+
AgSwMB0GA1UdDgQWBBTx6I3ZLm1G7VCtTJWWSKR2qv6x7TAZBgNVHREEEjAQgQ55
|
|
27
|
+
b3VyQGVtYWlsLmNvbTAZBgNVHRIEEjAQgQ55b3VyQGVtYWlsLmNvbTANBgkqhkiG
|
|
28
|
+
9w0BAQsFAAOCAYEAKCpNu5+MmYNrb+oOws9m8mghO4KDO53EQsfHtRcpsBxzwzV3
|
|
29
|
+
MLO4el5fMiAiv2PrULEWVyEoe3k65bEiSEQP7m7w02B02OGugXNzwbetG56gogFy
|
|
30
|
+
aJ4VJ95aiPEwDmGORLg7RmZcL/07ikDfb96ebPn3v2REYN2lWrqu4fT1MdTmA+hZ
|
|
31
|
+
vhfqJeSuWM5wNsWxA66SgbQe8BMHcsqV1CTG+Ir8FIAHzfa+c7CNke/28htRKYJV
|
|
32
|
+
6+lk55Ueov5TjjgLTUvjdqbAEtyCZpgxe2e0o3xqKh5d5YjWVQ4mSNvBsqK7UXOx
|
|
33
|
+
MGsePVBV9lnSFEJkGB3iOvavQSVUvqybF+yk6DrJR9iZtKCvAqd96PjkcFoM19dG
|
|
34
|
+
5ofv88TRZwXM9lWn4UKuekSSF1ElH3UBVDbH4zEHaOzrOvgfnZw3VteDigwfmmwF
|
|
35
|
+
lsAqKbu4nrHhtGhkwdYbflf2URJTUxXGptrnPYV7okmEg4rsykK3RAsZ6kMNdKmx
|
|
36
|
+
DcQ7RSt1TU5eck6c
|
|
37
37
|
-----END CERTIFICATE-----
|
|
38
|
-
date: 2020-
|
|
38
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
|
39
39
|
dependencies: []
|
|
40
40
|
description: Render MJML + ERb template views in Rails
|
|
41
41
|
email: sighmon@sighmon.com
|
|
@@ -50,20 +50,19 @@ files:
|
|
|
50
50
|
- lib/generators/mjml/mailer/templates/view.html.erb
|
|
51
51
|
- lib/mjml-rails.rb
|
|
52
52
|
- lib/mjml.rb
|
|
53
|
-
- lib/mjml/
|
|
53
|
+
- lib/mjml/handler.rb
|
|
54
54
|
- lib/mjml/parser.rb
|
|
55
55
|
- lib/mjml/railtie.rb
|
|
56
56
|
- lib/mjml/version.rb
|
|
57
57
|
- test/generator_test.rb
|
|
58
58
|
- test/mjml_test.rb
|
|
59
59
|
- test/parser_test.rb
|
|
60
|
-
- test/template_test.rb
|
|
61
60
|
- test/test_helper.rb
|
|
62
61
|
homepage: https://github.com/sighmon/mjml-rails
|
|
63
62
|
licenses:
|
|
64
63
|
- MIT
|
|
65
64
|
metadata: {}
|
|
66
|
-
post_install_message: "Don't forget to install MJML e.g. \n$ npm install
|
|
65
|
+
post_install_message: "Don't forget to install MJML e.g. \n$ npm install mjml"
|
|
67
66
|
rdoc_options: []
|
|
68
67
|
require_paths:
|
|
69
68
|
- lib
|
|
@@ -78,13 +77,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
78
77
|
- !ruby/object:Gem::Version
|
|
79
78
|
version: '0'
|
|
80
79
|
requirements: []
|
|
81
|
-
rubygems_version: 3.
|
|
82
|
-
signing_key:
|
|
80
|
+
rubygems_version: 3.1.4
|
|
81
|
+
signing_key:
|
|
83
82
|
specification_version: 4
|
|
84
83
|
summary: MJML + ERb templates
|
|
85
84
|
test_files:
|
|
86
85
|
- test/generator_test.rb
|
|
87
86
|
- test/parser_test.rb
|
|
88
87
|
- test/mjml_test.rb
|
|
89
|
-
- test/template_test.rb
|
|
90
88
|
- test/test_helper.rb
|
metadata.gz.sig
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
�0i�`�Z�ln���culhmE`
|
|
3
|
-
/V��iڇv��D'1|�8(�h�';�"W���N�
|
|
1
|
+
.�%�S��3y���Ԣ7ikx�hm���T�W���x^�8��`/��D4�\�F��Ơ\7"�˚/\y�x�E����}l�nF>@�d�Mi��:N$�u-P<��{����j���*ѥ�,\��2�JӇ}�ޮ��9��������C$�k�t�,�JϙMZ�ɒ��t�vpr�v����Mj����\lG���~K:�e�̢l��B�Q�x�>R�� �Z�����6#+,o���1��Her�qB�����H�ɟ@���N/v_tҀ�崉�I���l�=�ޫ�0é:�K�O�0@�0!�y��^�@��!ɰ�i������X߂d�+���踟,F��k�k1S��9��dT<ee��!�N
|
data/lib/mjml/mjmltemplate.rb
DELETED
data/test/template_test.rb
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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-section><mj-column></mj-column></mj-section></mj-body></mjml>").strip
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
end
|