mjml-rails 4.8.0 → 4.10.0
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 +39 -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 +18 -16
- data/test/mrml_parser_test.rb +33 -0
- data/test/test_helper.rb +2 -0
- data.tar.gz.sig +0 -0
- metadata +47 -29
- 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: e787307cfcd482f30208f9e38c0ec246b1670ef56bd36fd158d1c84f9b05430a
|
4
|
+
data.tar.gz: 7cc87eadbc13039cf2348cc3e5dc08313a751bf6360c403bfa4b545d628864c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38927fca73bc05d06f51a749176b1d8a93e9f08d30ebecd7b1a904f10093111d8239f368cd4ae0c428a15aaad4412f09442767bb60c621b6508917620f3c2d3a
|
7
|
+
data.tar.gz: 05cf3a1528c6375c7dd526d1952b589625af2b1a9c974d35a067f64a54bab3bd8eb3f9cbb8ae0bee17411a53e9c0efc83d08999e7c28f0d8dd3807ec3e149543
|
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
|
@@ -72,6 +74,9 @@ Add the MJML parser to your project with your favourite package manager:
|
|
72
74
|
# with npm
|
73
75
|
npm install mjml
|
74
76
|
|
77
|
+
# or install it globally (The best way for Rails 7.x.x with importmaps)
|
78
|
+
npm install -g mjml
|
79
|
+
|
75
80
|
# with yarn
|
76
81
|
yarn add mjml
|
77
82
|
```
|
@@ -80,6 +85,34 @@ MJML-Rails falls back to a global installation of MJML but it is strongly recomm
|
|
80
85
|
|
81
86
|
You'll need at least Node.js version 6 for MJML to function properly.
|
82
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
|
+
|
83
116
|
## Configuration
|
84
117
|
|
85
118
|
MJML-Rails has the following settings with defaults:
|
@@ -112,10 +145,12 @@ MJML-Rails has the following settings with defaults:
|
|
112
145
|
|
113
146
|
This can be used to specify the path to a custom MJML binary if it is not detected automatically (shouldn't be needed).
|
114
147
|
|
115
|
-
- `
|
148
|
+
- `mjml_binary_version_supported: "4."`
|
116
149
|
|
117
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.
|
118
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.
|
119
154
|
|
120
155
|
```ruby
|
121
156
|
# config/initializers/mjml.rb
|
@@ -133,6 +168,9 @@ Mjml.setup do |config|
|
|
133
168
|
# Render MJML templates with errors
|
134
169
|
config.validation_level = "soft"
|
135
170
|
|
171
|
+
# Use MRML instead of MJML, false by default
|
172
|
+
config.use_mrml = false
|
173
|
+
|
136
174
|
# Use custom MJML binary with custom version
|
137
175
|
config.mjml_binary = "/path/to/custom/mjml"
|
138
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)
|
@@ -71,18 +73,28 @@ module Mjml
|
|
71
73
|
|
72
74
|
def self.check_for_yarn_mjml_binary
|
73
75
|
yarn_bin = `which yarn`.chomp
|
74
|
-
return
|
76
|
+
return if yarn_bin.blank?
|
77
|
+
|
78
|
+
stdout, _, status = Open3.capture3("#{yarn_bin} bin mjml")
|
79
|
+
return unless status.success?
|
75
80
|
|
76
|
-
mjml_bin =
|
81
|
+
mjml_bin = stdout.chomp
|
77
82
|
return mjml_bin if check_version(mjml_bin)
|
83
|
+
rescue Errno::ENOENT # package manager is not installed
|
84
|
+
nil
|
78
85
|
end
|
79
86
|
|
80
87
|
def self.check_for_npm_mjml_binary
|
81
88
|
npm_bin = `which npm`.chomp
|
82
|
-
return
|
89
|
+
return if npm_bin.blank?
|
90
|
+
|
91
|
+
stdout, _, status = Open3.capture3("#{npm_bin} root")
|
92
|
+
return unless status.success?
|
83
93
|
|
84
|
-
mjml_bin = File.join(
|
94
|
+
mjml_bin = File.join(stdout.chomp, '.bin', 'mjml')
|
85
95
|
return mjml_bin if check_version(mjml_bin)
|
96
|
+
rescue Errno::ENOENT # package manager is not installed
|
97
|
+
nil
|
86
98
|
end
|
87
99
|
|
88
100
|
def self.check_for_global_mjml_binary
|
@@ -90,16 +102,6 @@ module Mjml
|
|
90
102
|
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
|
91
103
|
end
|
92
104
|
|
93
|
-
def self.bin_path_from(package_manager)
|
94
|
-
stdout, _, status = Open3.capture3("#{package_manager} bin")
|
95
|
-
|
96
|
-
return unless status.success?
|
97
|
-
|
98
|
-
stdout.chomp
|
99
|
-
rescue Errno::ENOENT # package manager is not installed
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
|
103
105
|
def self.discover_mjml_bin
|
104
106
|
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
|
105
107
|
'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
|
@@ -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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Loffler
|
@@ -11,31 +11,32 @@ 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
|
+
MIIEdDCCAtygAwIBAgIBATANBgkqhkiG9w0BAQsFADBAMRAwDgYDVQQ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1vbi5jb20wDQYJKoZIhvcNAQELBQADggGBAA62EngIqmTY
|
30
|
+
f79wEueZU4P8o10SelwvawXFUkPrOyvDoGx/ZmZ7vpo3STuTN7ywS4h+P3V8t9Zt
|
31
|
+
e8eQ7Slk99lFuRbDoMaX3ARnB3EMjbpNbh3H+8xo5CrzJpklmU5BV6B91Clz3Bou
|
32
|
+
3vdY9D4lZ01s0LgMQsfLwOsKyHeWCEPVwkGdXl4bb/FKpsm0veicKxW3+3F5J+nB
|
33
|
+
zGDjFWsrjpgaq1wYzfO79NEmqrJwZFQM8SoOG89Jwo3iPzJ1mC0UlQx1E+wDakRQ
|
34
|
+
fjE20735cJoU1+WIKO6DLH/mHXDQ+Nrw+9zOWTizoV6at1QSvR1r4cM3u8TQGpIv
|
35
|
+
yjLIXbfSrriclRt4wg6Xlra1F3Jlm3DJMp9w5cRT+knQdTprNEft1lA2cVjczatt
|
36
|
+
RhdbGYd5Hku1QRVeQ+tN2OYG1/vZeRTqZ4MGLdl6r4iO5XGtWWoR2alg8kKc6yLx
|
37
|
+
P5J+9tLKId50fAv4voQg//wRwePPNiWIXsLUa1LPYWTAznKTvi3dAQ==
|
37
38
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
39
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
39
40
|
dependencies:
|
40
41
|
- !ruby/object:Gem::Dependency
|
41
42
|
name: byebug
|
@@ -57,14 +58,28 @@ dependencies:
|
|
57
58
|
requirements:
|
58
59
|
- - '='
|
59
60
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.
|
61
|
+
version: 2.1.0
|
61
62
|
type: :development
|
62
63
|
prerelease: false
|
63
64
|
version_requirements: !ruby/object:Gem::Requirement
|
64
65
|
requirements:
|
65
66
|
- - '='
|
66
67
|
- !ruby/object:Gem::Version
|
67
|
-
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
|
68
83
|
- !ruby/object:Gem::Dependency
|
69
84
|
name: rails
|
70
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,11 +164,13 @@ files:
|
|
149
164
|
- lib/mjml-rails.rb
|
150
165
|
- lib/mjml.rb
|
151
166
|
- lib/mjml/handler.rb
|
167
|
+
- lib/mjml/mrml_parser.rb
|
152
168
|
- lib/mjml/parser.rb
|
153
169
|
- lib/mjml/railtie.rb
|
154
170
|
- lib/mjml/version.rb
|
155
171
|
- test/generator_test.rb
|
156
172
|
- test/mjml_test.rb
|
173
|
+
- test/mrml_parser_test.rb
|
157
174
|
- test/parser_test.rb
|
158
175
|
- test/test_helper.rb
|
159
176
|
homepage: https://github.com/sighmon/mjml-rails
|
@@ -175,12 +192,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
192
|
- !ruby/object:Gem::Version
|
176
193
|
version: '0'
|
177
194
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.4.10
|
179
196
|
signing_key:
|
180
197
|
specification_version: 4
|
181
198
|
summary: MJML + ERb templates
|
182
199
|
test_files:
|
183
200
|
- test/generator_test.rb
|
184
|
-
- test/parser_test.rb
|
185
201
|
- test/mjml_test.rb
|
202
|
+
- test/mrml_parser_test.rb
|
203
|
+
- test/parser_test.rb
|
186
204
|
- test/test_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|