mjml-rails 4.9.0 → 4.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +36 -1
- data/lib/mjml/handler.rb +2 -1
- data/lib/mjml/mrml_parser.rb +28 -0
- data/lib/mjml/version.rb +1 -1
- data/lib/mjml.rb +13 -3
- data/test/mjml_test.rb +16 -0
- data/test/mrml_parser_test.rb +33 -0
- data/test/test_helper.rb +2 -0
- data.tar.gz.sig +0 -0
- metadata +22 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 321f6e1eaed15dffa0b3c65283a095a92ac80cae3b3d3df4f395d446fbc4e490
|
4
|
+
data.tar.gz: 96cce85167d65a6c20cc62ad3d5690ed7e4c166af37311190a0729f33b6a315d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc6708c231290dea0a14a04c03d977f58dd34c5d64116c7aba01601191ebbda08642cf0039bc2ab060b7174a5e8f5fa728dae2da14bceeaa3351f8bb4073b721
|
7
|
+
data.tar.gz: 6f32e5c076fac3d45c69c2e8dfcc6880ef8d73dbf32e1c87dfb51442f466b90917d9591c08fa5bbfd7f748845d2672b35befa3ea8210c6edec104f56398dd5b5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -54,6 +54,8 @@ end
|
|
54
54
|
|
55
55
|
## Installation
|
56
56
|
|
57
|
+
### Using MJML NPM package
|
58
|
+
|
57
59
|
Add it to your Gemfile.
|
58
60
|
|
59
61
|
```ruby
|
@@ -83,6 +85,34 @@ MJML-Rails falls back to a global installation of MJML but it is strongly recomm
|
|
83
85
|
|
84
86
|
You'll need at least Node.js version 6 for MJML to function properly.
|
85
87
|
|
88
|
+
### Using MRML with included binaries
|
89
|
+
|
90
|
+
If for some reason you can't or don't want to run JS code in your production environment, you can use [MRML](https://github.com/hardpixel/mrml-ruby). It ships with already compiled binaries for Rust implementation of MJML so it has no external dependencies.
|
91
|
+
|
92
|
+
Add `mjml-rails` and `mrml` to your Gemfile.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
gem 'mjml-rails'
|
96
|
+
gem 'mrml'
|
97
|
+
```
|
98
|
+
|
99
|
+
Run the following command to install it:
|
100
|
+
|
101
|
+
```console
|
102
|
+
bundle install
|
103
|
+
```
|
104
|
+
|
105
|
+
Set `use_mrml` option to `true` in your initializer:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
# config/initializers/mjml.rb
|
109
|
+
Mjml.setup do |config|
|
110
|
+
config.use_mrml = true
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
**Note**: MRML does not fully support all MJML functionalities, see [Missing implementations](https://github.com/jdrouet/mrml#missing-implementations)
|
115
|
+
|
86
116
|
## Configuration
|
87
117
|
|
88
118
|
MJML-Rails has the following settings with defaults:
|
@@ -115,10 +145,12 @@ MJML-Rails has the following settings with defaults:
|
|
115
145
|
|
116
146
|
This can be used to specify the path to a custom MJML binary if it is not detected automatically (shouldn't be needed).
|
117
147
|
|
118
|
-
- `
|
148
|
+
- `mjml_binary_version_supported: "4."`
|
119
149
|
|
120
150
|
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.
|
121
151
|
|
152
|
+
- `use_mrml: false`
|
153
|
+
Enabling this will allow you to use Rust implementation of MJML via the `mrml` gem. It comes with prebuilt binaries instead of having to install MJML along with Node. When enabled the options `mjml_binary_version_supported`, `mjml_binary`, `minify`, `beautify` and `validation_level` are ignored.
|
122
154
|
|
123
155
|
```ruby
|
124
156
|
# config/initializers/mjml.rb
|
@@ -136,6 +168,9 @@ Mjml.setup do |config|
|
|
136
168
|
# Render MJML templates with errors
|
137
169
|
config.validation_level = "soft"
|
138
170
|
|
171
|
+
# Use MRML instead of MJML, false by default
|
172
|
+
config.use_mrml = false
|
173
|
+
|
139
174
|
# Use custom MJML binary with custom version
|
140
175
|
config.mjml_binary = "/path/to/custom/mjml"
|
141
176
|
config.mjml_binary_version_supported = "3.3.5"
|
data/lib/mjml/handler.rb
CHANGED
@@ -16,6 +16,7 @@ module Mjml
|
|
16
16
|
def call(template, source = nil)
|
17
17
|
compiled_source = compile_source(source, template)
|
18
18
|
|
19
|
+
parser_class = Mjml.use_mrml ? 'MrmlParser' : 'Parser'
|
19
20
|
# Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
|
20
21
|
# If we get here and template source doesn't start with one it means
|
21
22
|
# that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
|
@@ -24,7 +25,7 @@ module Mjml
|
|
24
25
|
#
|
25
26
|
# [0] - https://github.com/mjmlio/mjml/blob/master/doc/components_1.md#mjml
|
26
27
|
if /<mjml.*?>/i.match?(compiled_source)
|
27
|
-
"Mjml
|
28
|
+
"Mjml::#{parser_class}.new(begin;#{compiled_source};end).render.html_safe"
|
28
29
|
else
|
29
30
|
compiled_source
|
30
31
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mjml
|
4
|
+
class MrmlParser
|
5
|
+
attr_reader :input
|
6
|
+
|
7
|
+
# Create new parser
|
8
|
+
#
|
9
|
+
# @param input [String] The string to transform in html
|
10
|
+
def initialize(input)
|
11
|
+
@input = input
|
12
|
+
end
|
13
|
+
|
14
|
+
# Render mjml template
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
def render
|
18
|
+
MRML.to_html(input)
|
19
|
+
rescue NameError
|
20
|
+
Mjml.logger.fatal('MRML is not installed. Please add `gem "mrml"` to your Gemfile.')
|
21
|
+
raise
|
22
|
+
rescue StandardError
|
23
|
+
raise if Mjml.raise_render_exception
|
24
|
+
|
25
|
+
''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/mjml/version.rb
CHANGED
data/lib/mjml.rb
CHANGED
@@ -5,7 +5,7 @@ require 'open3'
|
|
5
5
|
|
6
6
|
require 'mjml/handler'
|
7
7
|
require 'mjml/parser'
|
8
|
-
|
8
|
+
require 'mjml/mrml_parser'
|
9
9
|
require 'mjml/railtie' if defined?(Rails)
|
10
10
|
|
11
11
|
module Mjml
|
@@ -17,7 +17,8 @@ module Mjml
|
|
17
17
|
:mjml_binary_version_supported,
|
18
18
|
:raise_render_exception,
|
19
19
|
:template_language,
|
20
|
-
:validation_level
|
20
|
+
:validation_level,
|
21
|
+
:use_mrml
|
21
22
|
|
22
23
|
mattr_writer :valid_mjml_binary
|
23
24
|
|
@@ -29,6 +30,7 @@ module Mjml
|
|
29
30
|
self.beautify = true
|
30
31
|
self.minify = false
|
31
32
|
self.validation_level = 'strict'
|
33
|
+
self.use_mrml = false
|
32
34
|
|
33
35
|
def self.check_version(bin)
|
34
36
|
stdout, _, status = run_mjml('--version', mjml_bin: bin)
|
@@ -46,7 +48,8 @@ module Mjml
|
|
46
48
|
check_for_custom_mjml_binary ||
|
47
49
|
check_for_yarn_mjml_binary ||
|
48
50
|
check_for_npm_mjml_binary ||
|
49
|
-
check_for_global_mjml_binary
|
51
|
+
check_for_global_mjml_binary ||
|
52
|
+
check_for_mrml_binary
|
50
53
|
|
51
54
|
return @@valid_mjml_binary if @@valid_mjml_binary
|
52
55
|
|
@@ -100,6 +103,13 @@ module Mjml
|
|
100
103
|
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
|
101
104
|
end
|
102
105
|
|
106
|
+
def self.check_for_mrml_binary
|
107
|
+
MRML.present?
|
108
|
+
rescue NameError
|
109
|
+
Mjml.mjml_binary_error_string = 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
103
113
|
def self.discover_mjml_bin
|
104
114
|
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
|
105
115
|
'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
|
data/test/mjml_test.rb
CHANGED
@@ -119,11 +119,13 @@ describe Mjml do
|
|
119
119
|
before do
|
120
120
|
Mjml.mjml_binary = nil
|
121
121
|
Mjml.valid_mjml_binary = nil
|
122
|
+
Mjml.use_mrml = nil
|
122
123
|
end
|
123
124
|
|
124
125
|
after do
|
125
126
|
Mjml.mjml_binary = nil
|
126
127
|
Mjml.valid_mjml_binary = nil
|
128
|
+
Mjml.use_mrml = nil
|
127
129
|
end
|
128
130
|
|
129
131
|
it 'can be set to a custom value with mjml_binary if version is correct' do
|
@@ -156,5 +158,19 @@ describe Mjml do
|
|
156
158
|
assert(err.message.start_with?("MJML.mjml_binary is set to 'set by mjml_binary' " \
|
157
159
|
'but MJML-Rails could not validate that it is a valid MJML binary'))
|
158
160
|
end
|
161
|
+
|
162
|
+
it 'can use MRML and check for a valid binary' do
|
163
|
+
Mjml.use_mrml = true
|
164
|
+
Mjml.stubs(:check_for_custom_mjml_binary).returns(false)
|
165
|
+
Mjml.stubs(:check_for_yarn_mjml_binary).returns(false)
|
166
|
+
Mjml.stubs(:check_for_npm_mjml_binary).returns(false)
|
167
|
+
Mjml.stubs(:check_for_global_mjml_binary).returns(false)
|
168
|
+
expect(Mjml.valid_mjml_binary).must_equal(true)
|
169
|
+
|
170
|
+
Mjml.valid_mjml_binary = nil
|
171
|
+
MRML.stubs(:present?).raises(NameError)
|
172
|
+
assert_nil(Mjml.valid_mjml_binary)
|
173
|
+
expect(Mjml.mjml_binary_error_string).must_equal 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
|
174
|
+
end
|
159
175
|
end
|
160
176
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe Mjml::MrmlParser do
|
6
|
+
let(:parser) { Mjml::MrmlParser.new(input) }
|
7
|
+
|
8
|
+
describe '#render' do
|
9
|
+
describe 'when input is valid' do
|
10
|
+
let(:input) { '<mjml><mj-body><mj-text>Hello World</mj-text></mj-body></mjml>' }
|
11
|
+
|
12
|
+
it 'returns html' do
|
13
|
+
expect(parser.render).must_include 'Hello World</div>'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when exception is raised' do
|
18
|
+
let(:input) { '<mjml><body><mj-text>Hello World</mj-text></body></mjml>' }
|
19
|
+
|
20
|
+
it 'raises exception with render exception enabled' do
|
21
|
+
with_settings(raise_render_exception: true) do
|
22
|
+
expect { parser.render }.must_raise(MRML::Error)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns empty string with exception raising disabled' do
|
27
|
+
with_settings(raise_render_exception: false) do
|
28
|
+
expect(parser.render).must_equal ''
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -5,6 +5,7 @@ require 'bundler'
|
|
5
5
|
Bundler.setup
|
6
6
|
|
7
7
|
require 'minitest/autorun'
|
8
|
+
require 'active_support'
|
8
9
|
require 'active_support/test_case'
|
9
10
|
|
10
11
|
require 'action_mailer'
|
@@ -13,6 +14,7 @@ require 'rails/generators'
|
|
13
14
|
require 'rails/generators/test_case'
|
14
15
|
require 'mocha/minitest'
|
15
16
|
require 'byebug'
|
17
|
+
require 'mrml'
|
16
18
|
|
17
19
|
# require "minitest/reporters"
|
18
20
|
# Minitest::Reporters.use!
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mjml-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
RhdbGYd5Hku1QRVeQ+tN2OYG1/vZeRTqZ4MGLdl6r4iO5XGtWWoR2alg8kKc6yLx
|
37
37
|
P5J+9tLKId50fAv4voQg//wRwePPNiWIXsLUa1LPYWTAznKTvi3dAQ==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: byebug
|
@@ -58,14 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 2.1.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mrml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.2
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rails
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,11 +164,13 @@ files:
|
|
150
164
|
- lib/mjml-rails.rb
|
151
165
|
- lib/mjml.rb
|
152
166
|
- lib/mjml/handler.rb
|
167
|
+
- lib/mjml/mrml_parser.rb
|
153
168
|
- lib/mjml/parser.rb
|
154
169
|
- lib/mjml/railtie.rb
|
155
170
|
- lib/mjml/version.rb
|
156
171
|
- test/generator_test.rb
|
157
172
|
- test/mjml_test.rb
|
173
|
+
- test/mrml_parser_test.rb
|
158
174
|
- test/parser_test.rb
|
159
175
|
- test/test_helper.rb
|
160
176
|
homepage: https://github.com/sighmon/mjml-rails
|
@@ -176,12 +192,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
192
|
- !ruby/object:Gem::Version
|
177
193
|
version: '0'
|
178
194
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.5.3
|
180
196
|
signing_key:
|
181
197
|
specification_version: 4
|
182
198
|
summary: MJML + ERb templates
|
183
199
|
test_files:
|
184
200
|
- test/generator_test.rb
|
185
201
|
- test/mjml_test.rb
|
202
|
+
- test/mrml_parser_test.rb
|
186
203
|
- test/parser_test.rb
|
187
204
|
- test/test_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|