mjml-rails 4.9.0 → 4.10.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
  SHA256:
3
- metadata.gz: 63fb17f29c1ab7539b3b53470787d35246e9536ee960a1493c02806c8119de75
4
- data.tar.gz: 50fd2491ce1bdef74e0eaf080687ef7e5ce5c23a423f8748eba62e27dcc3dfae
3
+ metadata.gz: e787307cfcd482f30208f9e38c0ec246b1670ef56bd36fd158d1c84f9b05430a
4
+ data.tar.gz: 7cc87eadbc13039cf2348cc3e5dc08313a751bf6360c403bfa4b545d628864c7
5
5
  SHA512:
6
- metadata.gz: 9cb24065a5430452f98fffbcc54c81da74dfb97c91ba85f64d4f16ceb8fbd302bb0483bc2705ce03027a22ce026f8f852d0a3274b0905c53f1ce94d485c6fab7
7
- data.tar.gz: 91ffeea703562d051c68dbabaad228efd2f6b07daa4cb750625727332363f95a184b42b500501c23e90a6714ca48eb6e3d63fbd7c90f58cf93ec8eaf4c2fb479
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
@@ -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
- - `mjml_binary_version_support: "4."`
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::Parser.new(begin;#{compiled_source};end).render.html_safe"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mjml
4
4
  # Version number no longer matches MJML.io version
5
- VERSION = '4.9.0'
5
+ VERSION = '4.10.0'
6
6
  end
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)
@@ -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.9.0
4
+ version: 4.10.0
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: 2023-05-12 00:00:00.000000000 Z
39
+ date: 2024-01-18 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.4.0
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.4.0
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
@@ -183,5 +199,6 @@ 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